
Writing a C Compiler
by Nora Sandler · first published 2023
100% recommend
Why HN recommends it
Hands-on guide to building a working C compiler that emits x86-64 assembly, starting from a minimal program and adding features chapter by chapter. Suits programmers who want to learn compilers by building one.
Summarised by Claude from recommending comments
A fun, hands-on guide to writing your own compiler for a real-world programming language. Compilers are at the heart of everything programmers do, yet even experienced developers find them intimidating. For those eager to truly grasp how compilers work, Writing a C Compiler dispels the mystery. This book guides you through a fun and engaging project where you’ll learn what it takes to compile a real-world programming language to actual assembly code. Writing a C Compiler will take you step by step through the process of building your own compiler for a significant subset of C—no prior ex
Affiliate links. As an Amazon Associate I earn from qualifying purchases.


Yeah. My favorite are books that guide you through implementing complex systems projects from scratch, like Nora Sandler's "Writing a C compiler", or Sy Brand's "Building a Debugger". I wish they produced A LOT more of them.
on “The Book of PF, 4th edition” ↗A good place to start is "Crafting interpreters" by Bob Nystrom. Then, after you gain some experience, you could try tackling Nora Sandler's "Writing a C compiler".
on “Ask HN: Where to start when creating a programming language?” ↗This might interest you: Writing a C Compiler by Nora Sandler (No Starch Press). You create a working C compiler that outputs x64 assembly language in the first chapter (as long as the program only returns an integer from main) and then you keep…
on “Snowdrop OS – a homebrew operating system from scratch, in assembly language” ↗…concepts that the OP talks about (liveness analysis, constant folding, dead code elimination), and similar stuff revolving around IR optimization, can be found explained in great detail in Nora Sandler's "Writing a C compiler".
on “Ask HN: What Are You Working On? (June 2025)” ↗If you like Ghuloum's paper, there are three fairly recent compiler books that are inspired by it: https://nostarch.com/writing-c-compiler - Writing a C Compiler by Nora Sandler, language agnostic for the implementation. https://mitpress.mit.edu/9780262047760/essentials-of-compila... - Essentials of Compilation (using Racket) by Jeremy Siek https://mitpress.mit.edu/9780262048248/essentials-of-compila...…
on “Compiling a Lisp: Lambda lifting” ↗…instructions to handle the memory stack. But it's much more cleaner than something like x86_64. If you are interesting in learning in more detail how to write a C compiler, I highly recommend the book "Writing a C Compiler" by Nora Sandler [0]. This is a super detailed, incremental guide on how to write a C compiler. This also uses the traditional architecture of using multiple passes. It uses its own IR called Tacky and…
on “Writing a C compiler in 500 lines of Python (2023)” ↗Inspired by Ghuloum's book is this really nice book by Nora Sandler: Writing a C Compiler https://norasandler.com/book/
on “Want to Write a Compiler? Just Read These Two Papers (2008)” ↗I've been going through Nora Sandler's Writing a C Compiler book and writing a compiler in Python. I'm excited to start the chapters on optimization - those seem like the most fun algorithm problems. I recommend the book. It certainly isn't easy (maybe 3x harder…
on “Ask HN: What Are You Working On? (May 2026)” ↗…adding optimizer passes. Building stuff yourself, the hard way, is definitely the best way to learn. I wish I had unbounded time to do it… Edit: I like the Appel compiler book. One of my students enjoyed “Writing a C compiler” by Nora Sandler. There are also a number of classic compiler books that feel more relevant once you are deep in the weeds.
on “Small Programs and Languages” ↗How does this compare to Nora Sandler's "Writing a C compiler" in terms of the potential gains for the reader?
on “Advanced Compilers: The Self-Guided Online Course” ↗