Lesson 2.5

References & Further Reading

Crafting Interpreters Ch. 5-8, Pratt parsing, and recursive descent resources.

links 5 min read

The essential reads.

Crafting Interpreters — Chapters 5-8

by Robert Nystrom

Four chapters that build a complete parser. Ch. 5 (Representing Code) designs the AST with the visitor pattern. Ch. 6 (Parsing Expressions) implements a recursive descent expression parser. Ch. 7 (Evaluating Expressions) shows why the tree shape matters. Ch. 8 (Statements and State) adds variable declarations and blocks. Read these chapters alongside building Monk's parser — the architecture maps almost 1:1.

craftinginterpreters.com/representing-code.html

Writing An Interpreter In Go — Chapters 2-3

by Thorsten Ball

Builds a Pratt parser for the Monkey language in Go. Ch. 2 implements parsing with prefix and infix functions. Ch. 3 extends it with if expressions, function literals, and call expressions. The code is Go, making it directly applicable to Monk's implementation. Ball's approach uses Pratt parsing rather than precedence climbing, so comparing the two side by side is instructive.

interpreterbook.com

Read both. Nystrom teaches the concepts; Ball shows you how to write them in Go. Together they cover everything needed to build Monk's parser.

Pratt parsing deep dives.

Bob Nystrom — "Pratt Parsers: Expression Parsing Made Easy"

The clearest explanation of Pratt parsing ever written. Builds a complete expression parser in Java, explaining each concept as it goes. Even though Monk uses precedence climbing instead of Pratt, understanding Pratt parsing shows you the elegant alternative and why some language authors prefer it.

journal.stuffwithstuff.com/.../pratt-parsers-expression-parsing-made-easy

Douglas Crockford — "Top Down Operator Precedence"

The paper that brought Pratt parsing back from obscurity. Crockford (of JavaScript fame) implemented a Pratt parser for a subset of JavaScript. More academic than Nystrom's blog post, but historically important — this paper inspired many modern parsers.

crockford.com/javascript/tdop/tdop.html

Vaughan Pratt — "Top Down Operator Precedence" (1973)

The original paper. Dense and academic (it's from 1973), but short. Worth reading after you've understood the concept from Nystrom or Crockford, just to see how the idea was first articulated.

Go parser implementations to study.

Go's own parser: go/parser

The Go standard library includes a complete hand-written recursive descent parser for Go itself. It handles operator precedence, statement parsing, and error recovery — all the same problems Monk's parser solves. Production-quality code, well-commented, excellent for browsing once your parser is working.

pkg.go.dev/go/parser

Go AST package: go/ast

The AST node types for Go. Compare with Monk's AST design — similar expression/statement split, similar node types. Notice how Go uses interfaces for the Node, Expr, and Stmt types with a marker method pattern.

pkg.go.dev/go/ast

If you want the theory.

Engineering a Compiler — Ch. 3: Parsers

by Cooper & Torczon

The formal treatment: context-free grammars, LL and LR parsing, FIRST and FOLLOW sets. Explains why recursive descent is a specific case of LL(1) parsing. Not required for building Monk, but gives you the vocabulary to read other compiler literature.

Compilers: Principles, Techniques, and Tools (Dragon Book) — Ch. 4

by Aho, Lam, Sethi, Ullman

The classic textbook treatment of syntax analysis. Covers more parsing strategies than you'll ever need. Good as a reference when you encounter terms like "LR(1)" or "LALR" in other resources.

Suggested reading order.

1

Crafting Interpreters Ch. 5-6 — read alongside building Monk's expression parser. AST design and recursive descent.

2

Nystrom's Pratt parsing blog post — after your expression parser works. Understand the alternative approach.

3

Writing An Interpreter In Go Ch. 2-3 — to see the same ideas implemented in Go with Pratt parsing.

4

Crafting Interpreters Ch. 7-8 — after adding statements. See how evaluation uses the tree structure your parser built.

5

Go's go/parser source — after your parser is complete. Compare production patterns with yours.