This is a list of reader implementations of the project from Writing a C Compiler, shamelessly ripped off from lovingly inspired by the list of implementations of Lox from Crafting Interpreters. I hope this will be a useful resource for readers planning to complete the project in a lots of different languages.
See the contributing section for details on how to add your implementation to the list. Incomplete, unpolished, and hacky implementations are welcome!
Disclaimer: I haven't code reviewed these implementations. As with any untrusted code, please be cautious about running these on your own computer.
Please add your C compiler to this page if:
- It's basically following the design in Writing a C Compiler (the book, not the blog posts, which are quite different).
- You've finished at least chapter 1.
Your compiler does not need to be complete, polished, or production-ready, and it does not need to follow the book exactly. Compilers that implement extra language features, target different processors or are organized into different passes are totally welcome.
Open a pull request to add your compiler to the list for the appropriate implementation language, in alphabetical order. If there isn't already a subheading for your implementation language, please go ahead and add one (make sure to add it to the the table of contents too!) If you don't have a Github account, you can email me and ask me to add it for you.
For projects hosted on Github, please use the following format:
- USERNAME/REPO - A few optional sentences about your project. E.g. if you've made different design decisions than the book suggests or implemented extra features, you can mention it here.
For projects hosted elsewhere, use this format:
- name of project - A few optional sentences about your project. E.g. if you've made different design decisions than the book suggests or implemented extra features, you can mention it here.
- JeremyGrosser/wacc - Handwritten lexer, using record types with discriminants to model ASDL structures.
- LesleyLai/mcc - A C23 implementation. While loosely following the book, I also consulted other resources, and this implementation has notable deviations, including a handwritten lexer, name resolution within the parser, and a slightly different IR design.
-
Gnomeball/C-Compiler - Implemented on Linux; only notable change from the intended design is the use of a byte code representation instead of an AST while parsing; so far only chapter one is 'complete', though it's extremely rough.
-
romainducrocq/wheelcc - C++ (>=17) implementation for linux and macOS: with some builtin preprocessing, comprehensive error messages with source locations and zero dependencies other than gcc. Covers 100% of the book and passes 100% of the test-suite (Parts 1, 2, 3 and extra-credits). While the overall design follows the book, many implementation details have been changed in all parts of the compiler. I am currently migrating the project to C.
-
Sh0g0-1758/scarlet - C++ (>=20) implementation featuring multiline error recovery and CI-verified builds. Completed Part 1 with all extra credits. Implementation largely follows the book with deviations in semantic analysis stage. Parts 2/3 in active development targeting x86_64 (Linux/macOS). Roadmap includes extensive static analysis optimizations and a future machine learning framework. Built with CMake and tested across GCC/Clang.
- romainducrocq/cube - An early version of romainducrocq/wheelcc that implements chapters 1 to 13, before switching the compiler implementation to C++. It is discontinued and will no longer receive updates.
- JusticeProject/Go-C-Compiler - Following the book closely. Runs on Linux. Finished Chapter 9. No extra credit features implemented (yet).
- 0xpantera/halcyon - Uses parser combinators for lexer and parser instead of regular expressions. Work in progress. Check out the project README for details on current functionality and progress.
- amantuladhar/jai-c-compiler - [WIP Ch 8] A work-in-progress implementation of a compiler in Jai. The project is not complete but implements extra credit features from the book. Error reporting is handled as a separate concern, allowing it to point to the exact location of errors in the source file. Output in different stage are written to support polymorphic writers to make output verification easier.
-
dplassgit/adventofcompilers - Java 21 implementation. Hand-rolled lexer (no regexp). Pretty faithful to the book, except with more meaningful names to disambiguate AST nodes from Tacky nodes from Assembly nodes. Complete through Chapter 11 (not including extra credits.)
-
mikeyreilly/mcc - Java implementation with heavy use of pattern matching. Aiming to do extra credit stuff after I finish Chapter 20.
-
nlsandler/nqcc2 - This is the official reference implementation for the book!
-
lc - Work in progress, Part I completed, implements extra credit features (Duff's device!). Follows the book fairly closely. Has no dependencies beyond the OCaml stdlib.
- sir-galahad/adcc - C compiler in Perl, for Linux seemed like a good idea, Perl hashes make it quick to build complex data structures.
- gh-nate/wacc - Part I completed without extra credits. Verification relies on test suite mentioned in the book.
-
ceronman/writing-a-c-compiler - Work in progress, I have implemented up to chapter 12 including all extra-credit. Only macOS supported for now. I push updates almost every day.
-
ianyourgod/batpu-c-compiler - Rust implementation for the BATPU2, a CPU made for/in minecraft: uses the GCC preprocessor, and has absolutely terrible error messages. All parts finished. A few part 2 features are missing (floats, longs, unsigned), as the CPU does not support them.
-
neildanson/c_compiler - Rust implementation based entirely on the book, following x86-64. Verified working on WSL2 on Windows and MacOS. Work In progress.
-
ysono/compiler-c-sandler - Implementation details diverge from the book's instructions in various ways. The behavior is consistent with the way the book clamps down on undefined behaviors. Tested on Linux and Intel Mac. Work in progress.
-
asibahi/trjm - Lexer and Parser written using parser combinator library
nom
andnom-language
, but otherwise faithful to the book. As of Mar 16 it is up to chapter 13 (doubles), including extra features.
- asibahi/paella - Straightforward implementation in Zig 0.14.0, with some ideas from the Zig compiler itself. Currently halfway to chapter 5 (variables).