Writing a compiler from scratch
summary
Live builds a working compiler for a tiny dynamic language that supports integers, addition, multiplication and variables and finishes by running compiled code on a simple VM. It implements lexing into tokens, a recursive‑descent parser that handles operator precedence correctly, and a compiler that emits five instructions (load int, load var, store var, add, multiply). Variables compile to byte-sized indexes and a stack-based VM executes immediate instructions; the demo compiles and runs examples (e.g. x=3; 1+23 yields 17). Recursive descent parsing* and eager matching are shown in code.
AI-written summary · about
chapters (13)
- 0:00Introduction and motivation
- 1:12Why build a compiler
- 5:32Compiler phases overview
- 8:03Building the scanner
- 19:20Parsing tokens into tree
- 25:42Recursive descent parsing
- 31:25Parsing expressions
- 43:03Parsing assignments
- 45:32Compilation targets
- 50:07Compiling to bytecode
- 53:58Executing bytecode
- 56:32Handling variables
- 1:00:23Final demo and tips
