Monke language interpreter and compiler based on books "Writing an Interpreter in Go" and "Writing A Compiler In Go"
🐵 Monke language in your browser (running in WASM + worker): https://monkey-lang-rs.vercel.app/
Features:
- Variables, variables reassignment
- Types: integers, booleans, strings, null
- Arithmetic operations and compound operators: +, -, *, /, +=, -=, *=, /=
- Comparison operations: ==, !=, <, <=, >, >=
- If statements
- C-like for loops (for (init; condition; post) { ... })
- Functions
- Closures
- Built-in functions
- Arrays
- Objects
- Web playground with compiler/interpreter compiled to WASM running in web worker
To run REPL:
cargo build --release
./target/release/cli --repl // runs interpreter mode
./target/release/cli --repl --compile // runs compiler mode
Example:
Welcome to Monke programming language!
Running in compiler mode.
>> let addFunction = function(x, y) { return x + y; };
>> addFunction(6,2);
8
--repl/-r: start an interactive REPL session (interpreter by default, compiler if combined with--compile).--compile/-c: enable compiler mode (affects both REPL and file execution).<path>: optional.monkefile to execute. When omitted, the tool waits for--replto launch an interactive session.
Not optimized:
- Compiler mode, fibonacci of 20:
- time: ~30.394 ms
- Interpreter mode, fibonacci of 20:
- time: ~113 ms
Optimized:
- Compiler mode, fibonacci of 20:
- time: TODO...
- Interpreter mode, fibonacci of 20:
- time: TODO...