An interpreter of the Lox scripting language, implemented in C.
Lox is a tiny scripting language described in Bob Nystrom's book Crafting Interpreters. I've already written an tree-walk interpreter using TypeScript, called TSLox. This C version is a bytecode virtual machine, developed along with reading Part III of the book.
First build this project. Here we use CMake:
$ mkdir build && cd build # Create a CMake workspace
$ cmake .. && make
$ ./clox # Start CLox
Invoking clox
without parameter starts the REPL. To run Lox source files, please specify the file path. Feel free to run examples in the examples
directory:
$ ./clox ../examples/hello-world.lox
Hello, world!
By the end of 2021, I complete reading Crafting Interpreters and implement two interpreters of the Lox scripting language, in TypeScript and C respectively. I get some knowledge about creating programming languages, and it feels great! Next I may play with some toy languages, learn more optimization tricks and investigate different language features. Hope I can make some "real" production one day. ;)
- Book: Crafting Interpreters
- Blog post: Crafting "Crafting Interpreters"
- Wiki: Lox implementations