Recursive descent parser that builds expression AST. Everything evaluates to an expression which evaluates to a double.
- Supports
+, -, *, /as well as - Variable assignment can be done by
a=2ora=b=2. - Logical operations like
&&,|| - Comparison with
== - Function definition with `fn fnname(arg1, arg2, ...) { expr1; expr2; returnexpr }
- Ternary operator
cond ? iftrue : iffalse Ansautomatic variable to get previous answer- Builtin functions:
sin(x).
-4+1*7+2/3
3.666667
355/113
3.141593
> a=b=2
> a+b
4
> 1 && 2 && 3
1
> 1 && 0
0
> 1 || 0
1
Last expression is implicitly returned
> fn fib(n) {n==0 || n==1 ? n : fib(n-2)+fib(n-1) }
> fib(10)
55
Todo:
- Units
- Graphing?