Follow the book commit by commit to learn how tokenizing, preprocessing, parsing, and code generation work in a real compiler.
Read the source to understand how a C11 preprocessor expands macros and handles include directives.
Compile SQLite or libpng with chibicc to see how far a teaching compiler can handle real-world C code.
| rui314/chibicc | tsl0922/ttyd | klipper3d/klipper | |
|---|---|---|---|
| Stars | 11,617 | 11,612 | 11,529 |
| Language | C | C | C |
| Setup difficulty | moderate | easy | hard |
| Complexity | 4/5 | 2/5 | 4/5 |
| Audience | developer | ops devops | ops devops |
Figures from each repo's GitHub metadata at analysis time.
Requires a C compiler and build tools, the repo rewrites history when bugs are fixed so pull requests are not accepted.
chibicc is a C compiler built primarily as a teaching tool. A compiler is a program that reads source code written in a programming language and converts it into instructions the computer can actually run. Most people who write software in C use professional compilers like GCC or Clang, this project builds a simpler one, step by step, to show how the process works. The compiler was written by a Japanese author as the reference implementation for a book about C compilers and low-level programming. The book is structured so that readers start by building a compiler that understands only a single number, then add one language feature at a time until the compiler handles the C11 standard. Each commit in this repository corresponds to one section of the book, and the author wrote every commit with first-time readers in mind. You can follow the entire learning path from the very first commit. Despite being called small, chibicc is more capable than most projects in that category. It can compile real programs including Git, SQLite, and libpng without modifying them, and the resulting programs pass their test suites. It supports most of the C11 standard, including a preprocessor, floating-point types, variable-length arrays, and thread-local variables. It does not include an optimization step, so the code it generates runs slower than what a production compiler would produce. The compiler processes code in four stages: tokenize (split the source text into pieces), preprocess (expand macros and handle directives), parse (build a tree structure representing the code's meaning), and code generation (produce assembly output). The source code is intentionally kept simple and avoids clever abstractions so that readers encountering compiler internals for the first time can understand it. The project does not accept pull requests in the conventional way. Because the repository also serves as the book's commit-by-commit narrative, the author rewrites history when bugs are found, keeping every commit clean and correct.
A teaching C compiler that handles most of C11, built commit by commit as the reference code for a book on compilers, starting from a single-number parser and growing to compile real programs like SQLite.
Mainly C. The stack also includes C.
No license information was mentioned in the explanation.
Setup difficulty is rated moderate, with roughly 1h+ to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.