Writing a C Compiler Cover

Writing a C Compiler

Build a Real Programming Language from Scratch
by Nora Sandler
August 2024, 776 pp.
ISBN-13: 
9781718500426
Use coupon code PREORDER to get 25% off!

Download Chapter 4: Logical and Relational Operators

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 

Introduction
Part I: The Basics
Chapter 1: A Minimal Compiler
Chapter 2: Unary Operators
Chapter 3: Binary Operators
Chapter 4: Logical and Relational Operators
Chapter 5: Local Variables
Chapter 6: If Statements and Conditional Expressions
Chapter 7: Compound Statements
Chapter 8: Loops
Chapter 9: Functions
Chapter 10: File-scope Variables and Storage-class
Specifiers
Part II: Types Beyond int
Chapter 11: Long Integers
Chapter 12: Unsigned Integers
Chapter 13: Floating-point Numbers
Chapter 14: Pointers
Chapter 15: Arrays and Pointer Arithmetic
Chapter 16: Characters and Strings
Chapter 17: Supporting Dynamic Memory Allocation
Chapter 18: Structures
Part III: Optimizations
Chapter 19: Optimizing Tacky Programs
Chapter 20: Register Allocation
Next Steps
Appendix A: Debugging Assembly Code with GDB or
LLDB
References

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

Reviews 

"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.