A treewalking interpreter for the Lox language, written in OCaml. Follows Crafting Interpreters.
- OCaml
>= 4.14 - dune
>= 3.16 lwt
The easiest way to get a working toolchain is the bundled setup script. It handles a fresh Linux or macOS environment end-to-end — installs system prereqs, opam, a local switch, and project deps. On Linux it also detects when bubblewrap is installed but can't sandbox (the usual Docker / WSL / restricted-kernel snag) and falls back to opam init --disable-sandboxing instead of failing partway:
./setup.shOr if you already have opam:
opam switch create . 5.2.0
opam install . --deps-only --with-testdune builddune testThe interpreter accepts a subcommand and a path to a Lox source file:
dune exec loxcaml -- <command> <file.lox>
# or, after a build:
./run.sh <command> <file.lox>Commands:
| Command | Output |
|---|---|
tokenize |
Prints the token stream |
parse |
Prints the parsed AST |
evaluate |
Evaluates a single expression and prints the value |
run |
Executes the program |
Example:
./run.sh run test.lox