Study a real, working example of how a C compiler's lexer, parser, and code generator fit together.
Follow along with the Writing a C Compiler book using a completed Zig implementation as reference.
See how someone applies Zig's data oriented design principles to a compiler project.
| igor84/wcc | electricalgorithm/protomq | kristoff-it/zig-bundler | |
|---|---|---|---|
| Stars | 35 | 31 | 27 |
| Language | Zig | Zig | Zig |
| Setup difficulty | moderate | moderate | easy |
| Complexity | 4/5 | 4/5 | 2/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Requires the Zig toolchain, and generated assembly only runs correctly on Linux.
This project is a C compiler, built by one person while working through the book Writing a C Compiler by Nora Sandler. It compiles a subset of the C programming language, specifically the parts covered in that book, and it targets Linux systems only. It is not meant to handle the full C standard, so it will not compile every C program you might throw at it, but it does include all the extra features the book describes. The compiler is written in the Zig programming language, and the author chose to lean into Zig's data oriented design style rather than following the book's structure line for line. That means the code tries to keep memory allocations and stored data to a minimum. The project is organized into clear stages: reading the source code and breaking it into tokens, building a tree that represents the program's structure, checking that the program makes sense, generating an intermediate representation called Tacky IR, optimizing that representation, and finally producing x86_64 assembly code for the processor to run. The README goes into real technical detail about how the internal data structures work, showing code snippets of how syntax tree nodes and instructions are represented compactly using small structs and numeric indexes rather than named variables. This is aimed at readers who already understand compiler concepts and want to see how one specific implementation handles them in Zig. The project took about 10 months of part time work, mostly evenings and weekends. The author includes an unusually detailed disclaimer about AI use: no code was written by AI, but AI chat tools were used to help debug incorrect assembly output and to adjust a test suite to parse a different assembly syntax, at a cost of about $35. Configuration files for VS Code and Zed editors are included, along with build and test commands, making it easier for someone following the same book to get the compiler running and test it against the book's official test suite.
A hand-written C compiler in Zig, built while working through the book Writing a C Compiler, targeting Linux only.
Mainly Zig. The stack also includes Zig, x86_64 Assembly.
Setup difficulty is rated moderate, with roughly 1h+ to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Don't trust strangers blindly. Verify against the repo.