Several implementations of Lox, the language described in Crafting Interpreters by Robert Nystrom. Lox is a dynamically typed, garbage collected, programming language that runs on a virtual machine.
- clox implemented in c++
Perhaps the most awkward hodgepodge of c++, a language I learned largely by following a book that used c.
Compiled to web assembly (requires emscripten installed). There's a little ui that loads the vm in a web worker and lets you run scripts. The js/html files will be in the out directory.
Builds a native executable for running lox programs.
- Run with no arguments to enter REPL
- Run with path to script as argument to execute it.
Builds an unoptimised executable with address sanitizer and runs gc as often as possible to help catch bugs. This is the build used by the test runner. It's ~20x slower than the normal version.
Runs the tests from the book and files in tests/cases and checks their output.
For the book tests that expect errors, it doesn't check that the message matches exactly, just that there's any error at all. It also skips a few about global variables because my implementation doesn't give them special treatment.
continueandbreakfrom loops.s[index]ors[start:end](Index and slice strings. Negative indexes start from the end)condition ? true_value : false_valuea ** b(a to the power of b)debugger;(print info about the state of the vm)import function_name;orimport ClassName(to import builtins)time() -> number: Get the number of seconds since the UNIX epoch.
- jlox implemented in python
Less interesting than clox but a good starting point. Some additional features are added, see the sub-directory's README.