Skip to content
/ cloxx Public

cloxx is a C++ implementation of the Lox programming language from the book Crafting Interpreters.

License

Notifications You must be signed in to change notification settings

chanryu/cloxx

Repository files navigation

cloxx Build Status

cloxx is a C++ implementation of Lox, the language featured in the book Crafting Interpreters.

cloxx is a purely educational project for myself and thus it won't be very useful for building real-world applications. However, if you're another reader of the book and implementing Lox in C++, you may find cloxx an interesting reference. While it's fully C++ish, I tried to make it as close as possible to the book's jlox implementation in terms of identifiers in the code such as class, variable and function names. It should be easy to follow along with the book.

Aside form the techniques explained the book such as Recursive Descent Parsing and Tree-Walk Interpretation, cloxx implements Mark-and-Sweep Garbage Collection.

Running cloxx

While I don't want to spend more time on supporting other environments than my MacBook, the following instructions would work for most Posix-compatible environments with minimal (if not none) tweaks where CMake, bash and a decent C++17 compiler are available.

Setup project

Once you've cloned the repo, you should run the configuration script to setup the project. It will generate Posix-compatible makefiles via CMake.

$ script/configure.sh    # pass "--debug" if that's what you want

As well as the source files checked into the repo, you will also need to generate some files to build the project. You won't need to do it again unless you're hacking — i.e., modifying Abstract Syntax Tree — cloxx.

$ script/gen-ast.sh

Build

As mentioned earlier, we use CMake to build the probject. The following command will do that for you:

$ script/build.sh    # it's just a convenient wrapper around `cmake --build`    

If everthing goes well, you should have an executable cloxx under the build directory.

Test

While I didn't put much effort on creating tests, cloxx is fully compatible with jlox. This means I can just reuse jlox's comprehensive test suites. The following Python script runs the full jlox test suites imported from the Crafting Interpreters repo.

$ tool/run-test.py

Directory layout

  • build/ - Intermediate files and other build output go here. Not committed to Git.
  • gen/ – C++ source files generated by gen-ast.py. Not committed.
  • src/ – Most of the C++ source files.
  • test/ - Test suite files imported from the Crafting Interpreters repo.
  • tool/ - Mostly, Python scripts for generating files and unit testing.
  • scripts/ - Shell scripts to configure the projects, wrapper of the above Python scripts, and etc.

About

cloxx is a C++ implementation of the Lox programming language from the book Crafting Interpreters.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published