We can learn how to make an interpreter in this book.
====> ☆☆☆ "Writing An Interpreter in Go" ☆☆☆
That interpreter is called Monkey in the book.
The Monkey is written in Go in the book, but in this repository it is written in Zig.
Zig: v0.13.0
- Lexer
- Parser
- Evaluator
- REPL
- Test case
- Macro
- Compiler
- VM
- Linux
- Mac
- Windows
- Multibyte character
$ zig build run
>> let a = 5
null
>> a
5
>> a + 10
15
>> let add = fn(x, y) { x + y }
null
>> add(10, 20)
30
>> let closure = fn(x) { a + x }
null
>> closure(10)
15
>> let new_closure = fn(a) { fn() { a; }; };
null
>> let closure = new_closure(99);
null
>> closure();
99
let fibonacci = fn(x) {
if (x == 0) {
return 0;
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
fibonacci(15); #=> 610
$ zig build test --summary all
- ktanaka101 - creator, maintainer
MIT