Source: https://mokxi.com/teachers/plans/build-an-interpreter
Updated: 2026-11-19

Lesson plan

# Build a programming language lesson plan

Write Orbit, a small language for a mission control panel, in Python on a Raspberry Pi: tokenizer, recursive descent parser, AST, evaluator, scope, functions and real error messages, ending in a REPL that lights real lamps.

4 chapters, 8 lessons, about 6 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- Text into tokens, tokens into answers: the front end of every language.
- A tree in the middle, and an evaluator that walks it to drive the board.
- Variables, environments, functions and closures.
- Errors that point at the mistake, then Orbit 1.0 with a REPL on the Serial Monitor.

### Materials for the whole unit

- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 20 min

## Reading code

Text into tokens, tokens into answers: the front end of every language.

Lesson | Time | What students do

Tokens Start Orbit, a language for a mission control panel: a tokenizer that turns text into numbers, names, strings and symbols, one character at a time, the first stage of every compiler and interpreter there is. | 40 min

- Run it: text into tokens
- Whole numbers, and decimals
- Names
- Strings and punctuation
- A whole program

Recursive descent Turn tokens into answers with a recursive descent parser: one function per rule of a grammar, precedence that falls out of which function calls which, brackets, unary minus and the remainder operator. | 40 min

- Run it: a parser that adds
- Precedence: times before plus
- Brackets: the recursion in recursive descent
- Unary minus
- The remainder operator

### Materials

- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module

### Check for understanding

Each student finishes "Recursive descent" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "The remainder operator".

Chapter 2. About 1 h 20 min

## Running code

A tree in the middle, and an evaluator that walks it to drive the board.

Lesson | Time | What students do

An AST Split understanding from doing: the parser builds an abstract syntax tree out of tuples, and small recursive functions draw it, evaluate it and turn it into reverse Polish notation. | 40 min

- Run it: a tree made of tuples
- Draw the tree
- Evaluate the tree
- Reverse Polish notation
- Brackets vanish

Evaluating Orbit grows statements: a program is a list of statement nodes, and a run loop carries each one out, printing, switching real lamps on the Pi and waiting, until a launch sequence written in your own language counts down on the panel. | 40 min

- Run it: a program is a list of statements
- Lamps: the language touches the world
- wait
- A launch sequence in Orbit
- Trace one statement

### Materials

- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module

### Check for understanding

Each student finishes "Evaluating" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Trace one statement".

Chapter 3. About 1 h 30 min

## Names

Variables, environments, functions and closures.

Lesson | Time | What students do

Scope Variables, assignment and repeat blocks, then the idea that decides where a name can be seen: environments chained to their parents, so a block gets names of its own and the outside world stays safe. | 40 min

- Run it: an unknown word
- let and names
- Assignment and repeat blocks
- Environments with parents
- Shadowing

Functions def, calls and return in your own language: functions as values in the environment, return as an exception that unwinds the interpreter, the difference between lexical and dynamic scope proved on one program, and recursion with if. | 50 min

- Run it: def is not a word yet
- def and calls
- return
- Lexical scope: which parent?
- if, and recursion
- Recursion all the way down

### Materials

- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module

### Check for understanding

Each student finishes "Functions" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Recursion all the way down".

Chapter 4. About 1 h 40 min

## Ship it

Errors that point at the mistake, then Orbit 1.0 with a REPL on the Serial Monitor.

Lesson | Time | What students do

Errors The difference between a toy and a tool: tokens that know their line and column, one error type for the whole language, a caret under the exact spot, and runtime errors like division by zero and adding text to a number caught before Python sees them. | 40 min

- Run it: an unhelpful error
- Line and column
- Point at it
- Runtime errors
- Type errors

Boss: a calculator language on a board Finish Orbit 1.0: a read-eval-print loop on the Serial Monitor that remembers between lines, reads multi-line blocks, survives errors and Ctrl-C, has built-in math, and flies a launch sequence on the Pi's lamps typed live. | 60 min

- Run it: a REPL
- Remember between lines
- Blocks over several lines
- Survive Ctrl-C
- Built-in functions
- Boss: fly a mission
- Share your language

### Materials

- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module

### Check for understanding

Each student finishes "Boss: a calculator language on a board" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Share your language".

Your class

## Teach this unit as a class

Start a class from this course and its 8 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
