Interpreter written in Go.
make build
To run you can use the binary built in previous step
monkey
OR
make run
This will start monkey repl
- C-like syntax
- Dynamic typing
- Variable bindings
- Integers and booleans
- Arithmetic expressions
- Arrays and maps
- Built-in functions
- First-class and higher-order functions
- Closures - TODO
Sample snippets
let age = 1;
let name = "Monkey";
let result = 10 * (20 / 2);
let add = fn(a, b) { return a + b; };
add(1, 2);
let fibonacci = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
1
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
fn(x,Y){ x+y ;} (3,4)
let firstname = "Nishanth"
let lastname= "Shetty"
let fullname = firstname + " " + lastname
let ar = [1,2, "hello", 2/2, fn(x) { x* 2; }(3)]
ar[2]
len(ar)
let a = {1:"1", 2:"2", 3:"3"};
a[1]
a[4]
let map = {1:"one", 2:"two", 3:"three"}
map[1]
all the above snippets are valid monkey lang, try executing them in a repl
repl provides helper commands to inspect and more. They start with : (colon)
-
:envInspect environmentPrints out the variables, functions declared in the current environment
-
:exitor:quitExit the repl
make test
This implementation is based on the Thorsten Ball Book. Writing Interpreter In Go