SSY
Sai Sasank Y
← All writing
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

    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.

  2. 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.

  3. 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.

  4. Part 4

    Writing my own interpreter for Lox, Part 4 - Statements

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

  5. Part 5

    Writing my own interpreter for Lox, Part 5 - Control Flow

    Adding control flow structures that make Lox Turing complete.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. Part 10

    Extending Lox Language with Custom Features!

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