Writing an Interpreter for Lox
A worklog series building a tree-walking interpreter for the Lox language in Python, following Crafting Interpreters.
A worklog series where I build a full tree-walking interpreter for the Lox language in Python, following Bob Nystrom's Crafting Interpreters. Each part picks up where the previous left off — scanner, parser, evaluator, control flow, functions, resolution, classes, inheritance, and some bonus extensions to Lox that I design and implement.
The complete source is available on GitHub.
- Part 1
Writing my own interpreter for Lox, Part 1 - Scanner
Building a scanner for the Lox language that converts source code into tokens, following Crafting Interpreters.
- Part 2
Writing my own interpreter for Lox, Part 2 - Parsing Expressions
Building an expression parser for Lox using recursive descent, with ASTs and the Visitor pattern.
- Part 3
Writing my own interpreter for Lox, Part 3 - Evaluating Expressions
Implementing expression evaluation by converting AST nodes into runtime values in the Lox interpreter.
- Part 4
Writing my own interpreter for Lox, Part 4 - Statements
Extending the Lox interpreter with statements, variables, environments, and lexical scoping.
- Part 5
Writing my own interpreter for Lox, Part 5 - Control Flow
Adding control flow structures that make Lox Turing complete.
- Part 6
Writing my own interpreter for Lox, Part 6 - Functions
Adding functions as first-class values, closures, and native functions to the Lox interpreter.
- Part 7
Writing my own interpreter for Lox, Part 7 - Resolving and Binding
Fixing closure scoping bugs with a static resolver pass that computes variable binding distances.
- Part 8
Writing my own interpreter for Lox, Part 8 - Classes
Implementing object-oriented programming in Lox with classes, instances, methods, and the this keyword.
- Part 9
Writing my own interpreter for Lox, Part 9 - Inheritance
Adding single inheritance with method overriding and super keyword support to complete the Lox class system.
- Part 10
Extending Lox Language with Custom Features!
Extending Lox beyond the original spec with len(), explicit initialization checks, and break statements.