Working through Crafting Interpreters by Robert Nystrom.
The book builds two complete interpreters for Lox, a small dynamically-typed scripting language:
| Part | Interpreter | Language | Approach |
|---|---|---|---|
| I | jlox | Java | Tree-walk interpreter |
| II | clox | C | Bytecode VM (coming later) |
A Python translation of jlox (lox-python/) is maintained alongside the Java source, chapter by chapter.
crafting-interpreters/
├── src/com/craftinginterpreters/
│ ├── lox/ ← jlox source (Java)
│ └── tool/ ← code-generation utilities
├── lox-python/ ← Python translation of jlox
│ └── tests/ ← pytest test suite
├── hello.lox ← sample Lox script
├── Makefile ← build / run targets
└── CLAUDE.md ← project notes & conventions
Requirements: JDK 17+
# Compile
make compile
# Interactive REPL
make run
# Run a script
make run-file FILE=hello.lox
# Regenerate Expr.java from the grammar definition
make generateRequirements: Python 3.11+
cd lox-python
# Interactive REPL
python lox.py
# Run a script
python lox.py ../hello.lox
# Run tests
python -m pytest tests/ -v| Chapter | Topic | Java | Python |
|---|---|---|---|
| 4 | Scanning | ✅ | ✅ |
| 5 | Representing Code (AST) | ✅ | ✅ |
| 6 | Parsing Expressions | ✅ | ✅ |
| 7 | Evaluating Expressions | ✅ | ✅ |
| 8 | Statements and State | ✅ | ✅ |
| 9 | Control Flow | ||
| 10 | Functions | ||
| 11 | Resolving and Binding | ||
| 12 | Classes | ||
| 13 | Inheritance |
Lox is a small, dynamically-typed language with:
- Arithmetic, comparison, and logical operators
- Variables (
var), control flow (if,while,for) - Functions (
fun) and closures - Classes and inheritance
var x = 1 + 2.5;
print x;