Build a Programming Language from Scratch
Build a complete programming language from first principles. You'll implement a scanner, recursive descent parser, tree-walk interpreter, bytecode compiler, stack-based virtual machine, garbage collector, closures, classes with inheritance, and a type inference engine. This is the definitive course on programming language implementation — based on the same techniques used by Python, Ruby, Lua, and JavaScript engines.
advancedFree10 hours38 lessons
Start learningor sign up to track progress
Curriculum
Loading reference solution…
Going further
Read
- Crafting Interpreters (Robert Nystrom) — the canonical text for this material. Free online at craftinginterpreters.com. Build the bytecode VM next; it's roughly 20× faster than the tree-walker.
- Structure and Interpretation of Computer Programs (Abelson + Sussman) — for a more theoretical foundation, especially around closures and continuations.
- The Garbage Collection Handbook (Jones + Hosking + Moss) — when you add heap-allocated values, you'll need GC. This is the book.
Build next
- Functions + closures: extend the AST with
FunctionandCallnodes. Capture the enclosing environment when a function value is created. - Bytecode compiler + stack VM: translate the AST into a flat instruction stream (PUSH, ADD, JUMP, CALL, RETURN). Run on a stack-machine. ~10× speedup over walking the tree.
- Garbage collector: mark-and-sweep first, then incremental, then generational.
- Type system: Hindley-Milner inference is the rabbit hole.
Continue with our courses
- Build a C Compiler — same pipeline, but lowering all the way to x86-64 assembly. Real compilation, not interpretation.
- Build a Lisp Interpreter — a smaller, more uniform language to test the same ideas.