Implementing Interpreters
"Fairy tales are more than true: not because they tell us that dragons exist, but because they tell us that dragons can be beaten." - G.K. Chesterton
This course covers the design and implementation of programming languages. While compilers and interpreters are often viewed as complex systems, they are built upon standard data structures and algorithms. By building one from scratch, we will examine the engineering principles required to process and execute code.
The Project: Snek
We will implement a custom dynamic language called Snek (Snek is Not Exactly Komplicated). This language is modeled after the Lox language described in the book. While we follow the core design of Lox, our implementation may include minor variations. The project covers the entire language pipeline:
- Scanning: Converting raw source code into tokens.
- Parsing: Constructing Abstract Syntax Trees (ASTs) from tokens.
- Static Analysis: Variable resolution and error checking.
- Interpretation: Executing the AST to run the program.
We will use Python (version 3.10 or newer) as the implementation language.
You can begin with 1. Introduction.
Literature
The course structure follows the first half of Robert Nystrom's book.
- Crafting Interpreters by Robert Nystrom.
Supplementary Resources
- Compilers: Principles, Techniques, and Tools (The "Dragon Book").
- The classic text on compiler theory. Useful if you want to dig deeper into the math behind parsers.
- Python 3.10+ Documentation