Writing a C Compiler Cover

Writing a C Compiler

Build a Real Programming Language from Scratch
by Nora Sandler
May 2024, 504 pp.
Use coupon code PREORDER to get 25% off!

An approachable, hands-on tutorial to writing a C compiler: a computer program that translates code written by the programmer into code the computer can understand. By building a compiler, readers will gain invaluable knowledge about how programming languages work; knowledge that will make them better programmers. Readers are gently led step-by-step to build a small working compiler and will develop throughout the book. Writing a C Compiler offers readers an accessible, practical approach to this complex and often overly theoretical topic.

Author Bio 

Nora Sandler is a software engineer. After graduating from the University of Chicago, she worked as a penetration tester at Security Innovation, and then as a compiler developer at CrowdStrike, fuelling her interest and research into how computers work under the hood. Sandler writes C Compiler tutorials and has created test programs on her popular blog to make writing a C compiler more accessible.

Table of contents 

Part I: The Basics
1. Introduction to Compilers
2. Returning an Integer
3. Unary Operators
4. Binary Operators
5. Logical and Relational Operators

6. Local Variables
7. If Statements and Conditional Expressions
8. Compound Statements
9. Loops
10. Functions
11. Static Variables
Part II: Implementing Types
12. Long Integers
13. Unsigned Integers
14. Floating-point numbers
15. Pointers
16. Arrays and Pointer Arithmetic
17. Characters and Strings
18. Supporting Dynamic Memory Allocation
19. Structures
Part III: Optimizations
20. Optimizing TACKY Programs
21. Register Allocation
Conclusion: Next Steps

The chapters in red are included in this Early Access PDF.


"It is refreshing to read a book on compiler design with a focus on implementing a practical real-world language, rather than working through dry academic exercises . . . practical, fun, and exciting to read if you are sick of reading textbooks on the subject."
—Rick Battagline, author of The Art of WebAssembly

Extra Stuff 

Check out Nora Sandler's interview with Raincode Labs.