An interpreter for the Monkey Language written in Rust.
The language comes from the book Writing An Interpreter In Go by Thorsten Ball.
This version contains more features than the original book and supports loops and bitwise operations. Also, the language is proven to be turing complete.
let age = 1;
let isTrue = true;
let name = "Monkey";
let array = [1, 2, 3, 4];
let hash = {"one": 1, "two": 2};
let result = 1 + 2 * 3 / 4 - 5;
let isTrue = 1 < 2;
let isFalse = !isTrue;
"Hello" + " " + "World";
1 == 1 == true
1 != 2 == true
12 || -1 == true
1 && 0 == false
true && true == true
true && false == false
true || false == true
1 & 3 == 1
1 | 2 == 3
1 ^ 3 == 2
3 << 2 == 12
4 >> 1 == 2
let x = if (10 < 5) {
10;
} else if (10 > 5) {
5;
} else {
0;
}
let i = 0;
let j = while (i < 2) {
i = i + 1;
}
let sum = 0;
for (let i = 0; i < 11; i = i + 1) {
let sum = sum + i;
}
sum == 55
let adder = fn(x) {
fn (y) {
return x + y;
};
};
let addTwo = adder(2);
addTwo(5) == 7;
print(arg1, arg2, ...)
len("string") == 6
len(["a", "b"]) == 2
first([1, 2, 3]) == 1
rest([1, 2, 3]) == [1, 2, 3]
last([1, 2, 3]) == 3
push([1, 2], 3) == [1, 2, 3]
$ make repl
$ cargo run -- examples/<filename>.mk