Simple calculator in Go, using top-down recursive parser. At the moment, supported:
- Basic arithmetic (including power)
- Variables
- Function calls
- Function defining
Soon:
- Namespaces
- Types
- LLVM backend (using simple interpreter at the moment)
git clone https://github.com/fakefloordiv/calculator
cd calculator
go run cmd/main.go
This will run an interactive shell. For running, go>=1.20 is required
Enter an expression, the result will be printed on the next line.
f(x, y) -> x + y
Note: function body is always a single expression. The result of it is returned as a return value
f(x, y)
x -> 5
Note: variables defining is an expression, returning value of a newly defined variable. By that, we also can use the following form:
x -> y -> 5
...resulting in x == y == 5
+
- add
-
- subtract
/
- divide
*
- multiply
^
- power
+
and -
respectively.
Note: the precedence of unary operations are lower than power, function calls and in-parenthesis expressions. So in fact - just like in math