directory organize and lexer now ignores comments
This commit is contained in:
13
ExampleCodes/1-Variables.fig
Normal file
13
ExampleCodes/1-Variables.fig
Normal file
@@ -0,0 +1,13 @@
|
||||
var any_var; // type is Any
|
||||
var number = 10; // type is Int
|
||||
number = "123"; // valid
|
||||
|
||||
var number2 := 10; // specific type is Int
|
||||
var number3: Int = 10; // both is ok
|
||||
/*
|
||||
number2 = 3.14;
|
||||
invalid!
|
||||
*/
|
||||
|
||||
const Pi := 3.14; // recommended, auto detect type
|
||||
// equal -> const Pi: Double = 3.14;
|
||||
11
ExampleCodes/SpeedTest/fib.fig
Normal file
11
ExampleCodes/SpeedTest/fib.fig
Normal file
@@ -0,0 +1,11 @@
|
||||
func fib(x:Int) -> Int
|
||||
{
|
||||
if (x <= 1)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
return fib(x-1) + fib(x-2);
|
||||
}
|
||||
|
||||
var result := fib(25);
|
||||
__fstdout_println("result: ", result);
|
||||
11
ExampleCodes/SpeedTest/fib.py
Normal file
11
ExampleCodes/SpeedTest/fib.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from time import time as tt
|
||||
|
||||
def fib(x:int) -> int:
|
||||
if x <= 1: return x;
|
||||
return fib(x-1) + fib(x-2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
t0 = tt()
|
||||
result = fib(25)
|
||||
t1 = tt()
|
||||
print('cost: ',t1-t0, 'result:', result)
|
||||
24
ExampleCodes/SpeedTest/fibLoopTest.fig
Normal file
24
ExampleCodes/SpeedTest/fibLoopTest.fig
Normal file
@@ -0,0 +1,24 @@
|
||||
var callCnt:Int = 0;
|
||||
func fib(x:Int) -> Int
|
||||
{
|
||||
callCnt = callCnt + 1;
|
||||
if (x <= 1)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
return fib(x-1) + fib(x-2);
|
||||
}
|
||||
|
||||
var fibx:Int;
|
||||
__fstdout_print("input an index of fib ");
|
||||
fibx = __fvalue_int_parse(__fstdin_read());
|
||||
|
||||
var cnt:Int = 0;
|
||||
__fstdout_println("test forever");
|
||||
while (true)
|
||||
{
|
||||
cnt = cnt + 1;
|
||||
__fstdout_println("test ", cnt,",result: ", fib(fibx));
|
||||
__fstdout_println("func `fib` called ", callCnt);
|
||||
callCnt = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user