Skip to content
debadree25Public

About

Tree-walking lox interpreter written in ocaml for https://craftinginterpreters.com/

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

76 Commits

Folders and files

Repository files navigation

LoxCaml

A treewalking interpreter for the Lox language, written in OCaml. Follows Crafting Interpreters.

Requirements

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

Or if you already have opam:

opam switch create . 5.2.0
opam install . --deps-only --with-test

Build

dune build

Test

dune test

Run

The 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

About

Tree-walking lox interpreter written in ocaml for https://craftinginterpreters.com/

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages