THE READING ROOM / BOOK GUIDE
Writing A Compiler In Go
A working compiler, built one decision at a time in Go. Thorsten Ball continues the interpreter project by adding bytecode, a stack machine, and the machinery that turns source text into instructions a virtual machine can run.
About the book
Writing a Compiler in Go picks up where Ball's earlier interpreter work leaves off and moves from evaluating a parsed syntax tree to compiling that tree into bytecode. The book centers on a small language and a stack-based virtual machine, so the pieces stay visible: lexer, parser, symbol table, code generator, and VM. Go keeps the code compact and readable without hiding the underlying mechanics behind framework abstractions.
The subject is the compiler pipeline as a concrete engineering exercise. Expect to see how symbols are resolved, how scopes are tracked, how instructions are emitted and encoded, and how the VM executes them. The emphasis falls on the bridge between source-level constructs and the lower-level instructions that implement them, including the bookkeeping that makes closures and function calls work.
Ball writes for programmers who learn by building. The project grows incrementally, and each stage depends on the previous one, so steady progress serves you better than skimming. It sits in the tradition of hands-on compiler texts that favor a complete, small implementation over breadth.
How to read it
Read with the code open. The explanations track an evolving codebase, and the reasoning behind a design choice often becomes clear only when you see the surrounding functions. Type the code rather than copying it; the errors you introduce and fix are part of the instruction.
Pace yourself around the symbol table and VM sections, where state and instruction encoding interact. If a concept feels abrupt, return to the corresponding parser or AST stage and trace the data forward. The book assumes comfort with Go syntax and basic data structures. Readers new to either should expect slower going. Prior exposure to parsing helps but is not essential.
Who it suits
This suits programmers who have written an interpreter or worked through a similar tutorial and want the next step: generating and executing instructions instead of walking a tree. Go developers curious about language tooling will find the code idiomatic enough to follow. Students who prefer a single coherent project to a theoretical survey will get the most from it. Readers seeking formal compiler theory, optimization passes, or production-grade tooling should look elsewhere.
Reading considerations
The scope is deliberately narrow: one small language, one bytecode target, one VM. That focus is the point, but it means register allocation, advanced optimization, and real-world language features receive little attention. A few Go idioms may look dated against current releases. Treat the implementation as a teaching model rather than a template for production compilers.
Follow the HN conversation
33 different recommenders are recorded in the upstream dataset. These are AI-classified source counts, not an independent rating.
Search HN comments about this book ↗
Explore videos on the same subject ↗
Book notes prepared with DeepSeek, using catalogue records and Open Library subject information. They are reading guidance, not a personal review or a verified chapter-by-chapter account. Book details can vary by edition. HN data methodology · Book metadata and covers.
