从零造一门解释型语言

Build Your Own Interpreted Language

Scanner → Pratt parser → tree-walk evaluator — see how the language you use every day actually runs

6 labs10 AI-mentored sessions~5 hoursBilingual · EN / 中
Start learning →

About this course

A build-it-yourself course: no jargon-first compiler theory. In every session an AI
mentor walks you through writing code, running assertions, and reading ASTs — crafting
a tiny language called Luma from its very first character to real running programs.
You'll hand-write a scanner that turns source text into tokens, tame operator
precedence and associativity with a Pratt parser, and build a tree-walk evaluator
that actually computes answers. Then you'll give the language variables, scopes,
branches, loops, functions, return and closures; wire in strings, lists and a
native-function bridge; and finally compile the AST to your own bytecode and run it
on a stack VM you build yourself — two execution strategies, one language.
Only the topic skeleton is anchored on Crafting Interpreters; every script and every
line of code is original, and Luma's syntax is 100% our own. All exercises are pure
Python stdlib, fully offline, sub-second, and exactly assertable.
Finish the course and you get to say it out loud: I built a language.

What you'll learn

  • Hand-write a scanner that turns source text into tokens — multi-digit numbers, two-char operators, string literals
  • Tame operator precedence and associativity with Pratt parsing (binding power) and print the resulting AST
  • Build a tree-walk evaluator with an environment chain: bindings, nested scopes, branches and loops
  • Implement function calls, return and closures, and explain why lexical scoping is designed this way
  • Wire strings, lists and a native-function bridge into the language, with type dispatch and runtime errors
  • Compile the AST to your own bytecode and run it on a hand-built stack VM, matching the tree-walk results exactly

Syllabus

1Craft a Tiny Language: from Char Stream to Evaluation2 sessions
  • 1Scanning and Pratt Expression Parsing30 minStart →
  • 2A Tree-Walk Evaluator with Scopes30 minStart →
2Statements & Control Flow: Make Programs Move3 sessions
  • 1Statements & Programs: print, let and Statement Lists30 minStart →
  • 2Truth & Branching: Comparisons, Booleans and if/else30 minStart →
  • 3Loops: while, Assignment and a Mutable World30 minStart →
3Functions & Closures: the Soul of a Language3 sessions
  • 1Defining & Calling Functions: Anatomy of a Call30 minStart →
  • 2return & Recursion: Functions That Call Themselves30 minStart →
  • 3Closures: Functions That Remember Where They Were Born30 minStart →
4Strings, Lists & Built-ins: the Language Meets the World2 sessions
  • 1Strings & Built-ins: Shaking Hands with the Host World30 minStart →
  • 2Lists & Indexing: the First Compound Data Structure30 minStart →
5A Bytecode VM: Another Way to Run the Same Language0 sessions

Sessions are on the way.

6Finale: Diagnostics, a REPL & Your Own DSL0 sessions

Sessions are on the way.

Same series · 计算机科学与工程探索

CS & Engineering Explorations

Build from scratch the systems you usually treat as black boxes — and understand them to the core.