hacker tutorialscourse catalogue

Courses / Course 02 · Compilers

Build an interpreter and a compiler

You end up withTwo interpreters for one language (a tree-walker, then a bytecode VM with a garbage collector), a compiler that turns a real language into assembly you can run, and enough LLVM to know what you'd use in production.

  • 26 sources
  • 333 HN threads
  • 24,263 points
  • 2007–2026
  • 3–5 months part-time; add 3–4 months for the optional book in step 7

Data pulled 2026-11-08 · time estimates are editorial

Why build one when an agent can write the code for you? Because every line your agent writes goes through one. When you know what a parser, a type checker and a code generator do, error messages stop being noise, “the compiler will optimise it” stops being faith, and a language’s design choices start to make sense. Hacker News has voted these tutorials up for almost twenty years. Every step below shows its HN score and quotes what HN said.

HN adrianmonk, 2023, in the thread on John Regehr’s “Why take a compiler course?” (320 points) · comment

“My unexpected side benefit: some compiler error messages became comprehensible.”

How to read the receipts.

  • Points are summed across every HN submission of the same URL. For books on their own site (Crafting Interpreters, Let’s Build a Simple Interpreter), that includes chapters submitted on their own.
  • “Submitted N×” means HN rediscovered it N times.
  • Quotes come from the highest-ranked top-level comments in those threads, and a quote is sometimes a criticism. Quotes keep the commenter’s spelling.
  • Steps are ordered for learning, not by points.
  • Times are our estimates, not the authors’. They assume evenings and weekends, and a reader who already programs comfortably in at least one language.

Optional on-ramp: From Nand to Tetris (nand2tetris.org) · Noam Nisan, Shimon Schocken

1,428 points, submitted 16× (2012–2026) · Free course materials; book and Coursera certificate are paid · ~one semester

If “assembly” and “stack” are fuzzy words for you, start here. You build a computer from logic gates, then (in part 2) a VM translator and a compiler for a small object-based language.

HN emschwartz, 2023 · thread

“This course does an exceptional job of giving you an intuitive understanding of some critical parts of how a computer works that affect higher-level programs and programming languages (for me the biggest aha! was grokking the difference between the stack and the heap).”

Stage 11–2 eveningsSee the whole pipeline

1.

The Super Tiny Compiler (github.com) · Jamie Kyle

764 points, submitted 10× (2016–2023) · Free · JavaScript · ~2 hours

One file that turns Lisp-style calls into C-style calls, with tokenizer, parser, transformer and code generator in a row. Read it for the shape of a compiler before you build one.

HN Stratoscope, 2016 · thread

“It’s about 200 lines of actual code plus another 500 lines of comments explaining what is going on.”

2.

(How to Write a (Lisp) Interpreter (in Python)) (norvig.com) · Peter Norvig

1,111 points, submitted 17× (2010–2026) · Free · Python · ~1 evening

A working Scheme interpreter in about a page of Python. It shows that “interpreter” means read, then evaluate in an environment, and not much else. The sequel, lispy2, adds tail calls, macros and error handling.

HN chombier, 2026 · thread

“If you ever wondered how to write a programming language, this is probably the best resource to get started (and then of course Crafting Interpreters).”

HN jimbokun, 2010 · thread

“Every time I read code from Norvig, programming seems so simple and powerful, and I wonder how it is I spend such effort getting such meager results.”

Stage 24–8 weeksA tree-walking interpreter

3.

Crafting Interpreters, part II: a tree-walk interpreter (craftinginterpreters.com) · Robert Nystrom

5,969 points, submitted 65× (2017–2026, book and chapters) · Free to read online; print, ebook and PDF are paid · Java · ~4–6 weeks

The core of the track, and by far the highest-scoring resource in the dataset. You build jlox, a complete interpreter for a small dynamic language called Lox: a scanner, a hand-written recursive-descent parser, an evaluator, scopes and closures, classes and inheritance.

HN chris37879, 2024 · thread

“I feel like this is a book most programmers should work through at some point or another… It’s also one of the most well written technical guides I’ve ever followed…”

HN recursivedoubts, 2021 · thread

“I used the website for my compilers class this last semester and it was great.”

HN’s top comments had no substantial criticism of this book.

Read alongside: Pratt Parsers: Expression Parsing Made Easy (Nystrom, 2011) · https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/ · 374 points, submitted 9×. It’s the cleanest explanation of operator-precedence parsing. “There’s Pratt parsing, precedence climbing, and shunting yard. But really they’re all the same algorithm.” (timhh, 2024 · comment)

Alternatives HN votes for, if Java isn’t your language:

  • Learn C and Build Your Own Lisp · Daniel Holden · https://buildyourownlisp.com/ · 2,431 points, submitted 15× · Free online; print and ebook paid · C. It teaches C and a Lisp at the same time. “It’s still one of my favorite computer science books.” (iafisher, 2018). The caveat: it uses the author’s parser-combinator library instead of a hand-written parser. “I dislike the use of a parser generator libary.” (blt, 2014 · comment)
  • Writing An Interpreter In Go · Thorsten Ball · https://interpreterbook.com/ · 397 points, submitted 10× · Paid: $29 ebook, $39 paperback · Go. “I’ve read a couple of similar online-books in the past, but this was the first one I worked my way through completely.” (stevekemp, 2019 · thread)
  • Make a Lisp (mal) · Joel Martin · https://github.com/kanaka/mal · 1,197 points, submitted 13× · Free · any language. A step-by-step guide plus tests, with reference implementations in dozens of languages. The caveat: “The actual guide is pretty sloppily written and doesn’t outline all that much” (chc4, 2017 · comment).
  • Let’s Build a Simple Interpreter · Ruslan Spivak · https://ruslanspivak.com/lsbasi-part1/ · 1,161 points across 75 submissions of its parts · Free · Python. A long blog series that builds a Pascal interpreter one part at a time.

Stage 34–8 weeksA bytecode virtual machine

4.

Crafting Interpreters, part III: a bytecode virtual machine · Robert Nystrom

Same book as step 3 · Free online · C · ~5–8 weeks

You rebuild Lox as clox: a single-pass compiler to bytecode, a stack-based VM, hash tables, closures with upvalues, and a mark-sweep garbage collector. Doing the same language twice is the point.

HN sunday_serif, 2024 · thread

“My favorite part of this book is that guides you through writing two separate interpreters for the same language… when you revisit them again in the second interpreter, you can actually absorb the interesting parts.”

Alternative: Writing A Compiler In Go (Thorsten Ball) · https://compilerbook.com/ · 131 points, submitted 6× · Paid: $29 ebook, $39 paperback, $50 for both Go books. It’s the sequel to the interpreter book and compiles that book’s language to bytecode for a VM. “I read this book — typing/modifying the code as I went, and enjoyed it immensely.” (nappy-doo, 2018 · thread)

Stage 48–12 weeksCompile to real assembly

Read first (10 minutes): Want to Write a Compiler? Just Read These Two Papers · James Hague · https://prog21.dadgum.com/30.html · 1,199 points, submitted 5× (2008–2026)

The essay that sets up this stage. It recommends Crenshaw (step 5) for how simple a working compiler can be, and Sarkar, Waddell and Dybvig’s “A Nanopass Framework for Compiler Education” for the idea that a compiler is a series of small transformations.

5.

Let’s Build a Compiler (compilers.iecc.com) · Jack Crenshaw

1,139 points, submitted 17× (2007–2026) · Free · Pascal, emitting 68000 assembly · ~2–3 weeks

The classic, written 1988–1995. It builds a single-pass compiler by hand, one feature at a time, with parsing and code generation done together.

HN groovy2shoes, 2013 · thread

“It doesn’t cover everything and it’s 25 years old now, but it is the only guide I know of that will hold your hand as you build a working compiler from scratch.”

The modern answer: Revisiting “Let’s Build a Compiler” (Eli Bendersky, 2025) · https://eli.thegreenplace.net/2025/revisiting-lets-build-a-compiler/ · 276 points, submitted 1×. It’s a part-by-part translation of Crenshaw’s compilers into Python, emitting WebAssembly, so you can follow the original text with code you can run today.

HN statictype, 2025 · thread

“Building a recursive descent parser from scratch was an eye opener to 17yo me on how a seemingly very complex problem that I had no idea how to approach can be made simple by breaking it down into the right primitives.”

6.

An Incremental Approach to Compiler Construction (scheme2006.cs.uchicago.edu) · Abdulaziz Ghuloum

621 points, submitted 12× (2008–2024) · Free paper · Scheme, emitting x86 · ~3–4 weeks

The paper behind the method that step 7 and chibicc use. Compile a language that is only integer constants all the way to x86, then add one feature at a time, keeping a working compiler at every step. Nada Amin’s step-by-step implementation and tutorial are at https://github.com/namin/inc.

HN jpolitz, 2016, who built a compilers course on it · thread

“I think the incremental approach is terrific, because it allows you to get to a program the emits assembly and builds a working binary in week one.”

7.

Writing a C Compiler (blog series) (norasandler.com) · Nora Sandler

1,024 points, submitted 12× (2017–2024) · Free · any language · ~3–5 weeks

The end of the main track. You compile a growing subset of C to x86-64 assembly, Ghuloum-style. The ten parts go from returning a constant, through expressions, variables, conditionals, loops and functions, to global variables, and every part comes with a test suite. At the end you have a compiler that turns real C programs into binaries you can run.

HN userbinator, 2017 · thread

“I really like Ghuloum’s approach: you start by compiling a tiny, trivial subset of your source language all the way down to x86 assembly. Then you add new language features, one step at a time.”

HN synack, 2024, implementing it in Ada · thread

“It feels like a more advanced version of Crafting Interpreters.”

Alternatives HN votes for:

  • A Compiler Writing Journey · Warren Toomey · https://github.com/DoctorWkt/acwj · 802 points, submitted 11× · Free · C. It’s a journal of writing a self-compiling C-subset compiler, part by part.
  • Writing a C compiler in 500 lines of Python · Theia Vogel · https://vgel.me/posts/c500/ · 757 points, submitted 2× · Free · Python, emitting WebAssembly. It’s a single-pass compiler in a weekend. “This article breaks it down well enough to make me feel like I could write my own C compiler targeting AVR.” (Liftyee, 2025)
  • chibicc · Rui Ueyama · https://github.com/rui314/chibicc · 489 points, submitted 3× · Free · C. The commit history is the tutorial. “chibicc’s each commit was carefully written so that you can read one commit at a time.” (rui314, the author, 2022 · comment). The book he planned around it is not available.
  • Compiling to Assembly from Scratch · Vladimir Keleshev · https://keleshev.com/compiling-to-assembly-from-scratch/ · 294 points, submitted 5× · Free online since the 2024 edition; $49 hardcover · TypeScript, emitting ARM. “Many modern compiler books (such as Torczon & Cooper’s “Engineering a Compiler”) take the approach of showing low-level, linear IRs rather than actual assembly…” (leapis, 2020 · comment)

Stage 52–4 weeksHow production compilers do it

8.

My First Language Frontend with LLVM (Kaleidoscope) (llvm.org) · LLVM project

661 points, submitted 11× (2008–2025) · Free · C++ · ~2–3 weeks

Real compilers don’t usually emit assembly themselves. They lower to an IR and let a backend such as LLVM do optimisation and code generation. This official tutorial builds a small language on LLVM, with a JIT, control flow and optimisation passes.

HN program, 2013 · thread

“LLVM is quite complex and the documentation is far from stellar but it’s usable for teaching how a compiler works.”

Side quest: types and functional languages

Write You a Haskell · Stephen Diehl · https://sdiehl.github.io/write-you-a-haskell/ · 641 points, submitted 8× (2015–2020) · Free

A compiler for a small Haskell-like language, covering lambda calculus, Hindley-Milner type inference and evaluation. This is the gap in every other step: none of them does type inference.

HN exDM69, 2015 · thread

“There are plenty of compiler writing tutorials for conservative, imperative programming languages with a straightforward static type system (like C).”

The theory shelf (read alongside, not in sequence)

Book HN signal Cost Read it during
Compiler Construction · Niklaus Wirth · https://people.inf.ethz.ch/wirth/CompilerConstruction/ 266 points over 3 submissions Free PDF Stage 4
Compilers: Principles, Techniques, and Tools (“the Dragon Book”) · Aho, Lam, Sethi, Ullman Named in 935 comments Paid book After Stage 4
Lisp in Small Pieces · Christian Queinnec Named in 245 comments Paid book After Stage 3
Engineering a Compiler · Cooper, Torczon Named in 135 comments Paid book After Stage 4
Modern Compiler Implementation in ML/Java/C · Andrew Appel Named in 116 comments Paid book After Stage 4

Hague’s essay (Stage 4) puts the Dragon Book at the end: “After writing a compiler or two, then go ahead and plunk down the cash for the infamous Dragon Book or one of the alternatives.” This track does the same.

Before you design your own language

HN deterministic, 2022, maintainer of a production JIT compiler · comment

”> Writing a parser by hand is tricky and not worth the alleged performance increases

Not my experience at all. It is easy and fun. And I can actually debug the parser instead of staring at generated noise/tables.”

Editorial backlog

Checked against HN on 2026-11-08 (candidates_receipts.json), not used:

  • Let’s make a Teeny Tiny compiler (Austin Henley): 435 points over 12 submissions. A good Python alternative to step 1, but it overlaps with steps 1 and 5.
  • 7 lines of code, 3 minutes: Implement a programming language (Matt Might): 420 points over 8 submissions. It overlaps with step 2.
  • Build a Compiler in Five Projects (Kristopher Micinski, 2025): 208 points over 2 submissions. A course-shaped alternative to Stage 4; consider it when it has more history.
  • Essentials of Compilation (Jeremy Siek): 93 points over 8 submissions, named in 30 comments. It’s the textbook version of Ghuloum’s incremental method (Racket or Python to x86-64). HN signal is weak, but it’s an obvious editorial candidate for Stage 4.

Not yet checked: Stanford’s Compilers MOOC (several commenters recommend it, but the original lagunita.stanford.edu links are dead), Crafting Interpreters ports to other languages, “A Nanopass Framework for Compiler Education” as a separate entry.

Method

  • Candidates came from the 287 compiler-tagged stories in the 4,140-story pull, plus a compilers topic pull with 39 terms: 538 candidates in all (phase1-stories/data/compilers_candidates.json). The topic terms were reviewed before the run; terms that pulled in mostly noise were dropped or tightened (see the comment in pull_topic.py).
  • Selection. 30 resources had receipts pulled; 26 are used here, chosen by hand for followability and sequence. Points were then totalled across every submission of each URL.
  • Comment mentions are Algolia counts of comments containing the exact book title.
  • Quotes come from the top five top-level comments of the two best-scoring threads per resource, in HN’s ranked order via the Firebase API. Some quotes are trimmed with ”…”; links go to the full comment or thread. Every ID and quote is checked with phase1-stories/scripts/check_track.py.
  • Costs were checked on each paid or mixed resource’s site on 2026-11-08. Time estimates are editorial, not measured.
  • Data: tracks/compilers/receipts.json (resources used) and candidates_receipts.json (all 30 checked).