Skip to content
/ jlox Public

Tree-walk interpreter for the Lox language written in Java, following craftinginterpreters.com

License

Notifications You must be signed in to change notification settings

andreychh/jlox

Repository files navigation

Java implementation of Lox language

Quality Gate Status Bugs Code Smells Coverage Duplicated Lines (%)

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.

Quick Start

Install Java 21+ and GNU Make.

Then build the project:

make

Run jlox with a path to your Lox script file:

./jlox script.lox

Run jlox without arguments to enter interactive mode:

./jlox

In 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

Design Principles

This implementation prioritizes:

  1. Immutability: Data structures are not modified after creation, making the system's data flow predictable.

  2. Composition over Inheritance: Behavior is assembled from independent components rather than being defined by rigid class hierarchies.

  3. No null References: The code is designed to avoid null usage, preventing a common class of runtime errors.

  4. No Reflection: Logic relies on the static type system and polymorphism instead of runtime type checks.

  5. No Global State: Each major module is self-sufficient and does not depend on global state.

Current Status

  • Lexer: FSM-based implementation
  • Parser: Planned
  • Interpreter: Planned

Contributing

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.

Acknowledgments

Based on Crafting Interpreters by Robert Nystrom.

About

Tree-walk interpreter for the Lox language written in Java, following craftinginterpreters.com

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •