← All Posts
Series10 parts · Complete

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.

Parts
  1. Part 1

    Building a scanner for the Lox language that converts source code into tokens, following Crafting Interpreters.

  2. Part 2

    Building an expression parser for Lox using recursive descent, with ASTs and the Visitor pattern.

  3. Part 3

    Implementing expression evaluation by converting AST nodes into runtime values in the Lox interpreter.

  4. Part 4

    Extending the Lox interpreter with statements, variables, environments, and lexical scoping.

  5. Part 5

    Adding control flow structures that make Lox Turing complete.

  6. Part 6

    Adding functions as first-class values, closures, and native functions to the Lox interpreter.

  7. Part 7

    Fixing closure scoping bugs with a static resolver pass that computes variable binding distances.

  8. Part 8

    Implementing object-oriented programming in Lox with classes, instances, methods, and the this keyword.

  9. Part 9

    Adding single inheritance with method overriding and super keyword support to complete the Lox class system.

  10. Part 10

    Extending Lox beyond the original spec with len(), explicit initialization checks, and break statements.