Skip to content

baevm/monkey-lang-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

monke-lang-rs

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

CLI usage

  • --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 .monke file to execute. When omitted, the tool waits for --repl to launch an interactive session.

Benchmark

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...

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published