compilers8 parts20 min total
8 parts
Part 13 min
Crafting a parser, part 1: from source to tokens
Before any grammar rule runs, a lexer turns characters into spanned tokens — and that token shape decides everything downstream.
Part 23 min
Crafting a parser, part 2: grammars and recursive descent
One function per grammar rule, the call stack as the parse tree, and why left recursion is a trap.
Part 32 min
Crafting a parser, part 3: designing the AST
Enums all the way down, spans on every node, and keeping semantics out of the syntax tree.
Part 43 min
Crafting a parser, part 4: Pratt parsing and precedence
One loop and a binding-power table replace a forest of precedence functions.
Part 52 min
Crafting a parser, part 5: error recovery and diagnostics
Report many errors per run and keep a usable tree — panic-mode recovery, sync points, and messages that don't lie.
Part 62 min
Crafting a parser, part 6: ambiguity, lookahead, and the lexer hack
The dangling else, the less-than-versus-generics problem, and how much backtracking is honest.
Part 72 min
Crafting a parser, part 7: resilient, incremental parsing
IDE-grade parsing: lossless trees, errors as the normal path, and reparsing only the edited subtree.
Part 83 min
Crafting a parser, part 8: testing, snapshots, and fuzzing
Snapshot the tree, round-trip for fidelity, and fuzz to enforce the never-panic contract.