Lox is a dynamically typed programming language from Robert Nystrom's Crafting Interpreters featuring:
- Variables and block scoping
- Control flow constructs (if/else, loops)
- First-class functions and closures
- Classes with inheritance
A detailed language specification can be found in the Lox Language chapter.
Install Java 21+ and GNU Make.
Then build the project:
makeRun jlox with a path to your Lox script file:
./jlox script.loxRun jlox without arguments to enter interactive mode:
./jloxIn this mode, you can enter Lox expressions and immediately see the result of their execution:
>>> print "Hello, world!";
Hello, world!
>>> var x = 42;
>>> print x;
42
This implementation prioritizes:
-
Immutability: Data structures are not modified after creation, making the system's data flow predictable.
-
Composition over Inheritance: Behavior is assembled from independent components rather than being defined by rigid class hierarchies.
-
No
nullReferences: The code is designed to avoidnullusage, preventing a common class of runtime errors. -
No Reflection: Logic relies on the static type system and polymorphism instead of runtime type checks.
-
No Global State: Each major module is self-sufficient and does not depend on global state.
- ✅ Lexer: FSM-based implementation
- ⏳ Parser: Planned
- ⏳ Interpreter: Planned
Contributions are welcome! Before submitting changes, run make test and make validate to ensure everything works
correctly. New features should include tests and follow the design principles outlined above.
Based on Crafting Interpreters by Robert Nystrom.