# rui314/chibicc

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/rui314-chibicc).**

10,945 stars · 1,016 forks · C · mit

## Links

- GitHub: https://github.com/rui314/chibicc
- awesome-repositories: https://awesome-repositories.com/repository/rui314-chibicc.md

## Description

Chibicc is a C11 compiler designed as a reference implementation for studying compiler construction. It translates C source code into machine-specific assembly instructions by utilizing a pipeline that includes lexical analysis, recursive descent parsing, and single-pass code generation. The project serves as an educational tool for understanding the internal architecture of compilers, from initial tokenization to the final emission of machine code.

The compiler distinguishes itself through its self-hosting capability, which allows the software to compile its own source code into a functional executable binary. This process is supported by a verification suite that ensures language feature compliance and binary integrity. To manage the complexities of the C language, the implementation includes a preprocessor that handles conditional directives and macro expansion, utilizing hidesets to prevent infinite recursion during the translation process.

The system incorporates diagnostic reporting to provide visual feedback on syntax and structural violations. It also includes internal utilities for handling UTF-8 character processing, identifier validation, and dynamic memory management for strings and arrays, ensuring the compiler can process diverse source code inputs efficiently.

## Tags

### Development Tools & Productivity

- [C11](https://awesome-repositories.com/f/development-tools-productivity/compilers-toolchains/compilers/c11.md) — Provides a functional C11 compiler that translates source code into machine instructions for modern architectures.
- [C11 Parsers](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis/static-analysis-engines/static-analysis-tools/static-code-analyzers/source-code-analysis/source-parsers/c11-parsers.md) — Translates C11 source code into assembly while providing detailed diagnostic feedback for errors.
- [Self-Hosting Verification Tools](https://awesome-repositories.com/f/development-tools-productivity/compilers-toolchains/compilers/self-hosting-verification-tools.md) — Ensures compiler reliability by successfully compiling its own source code into a working binary.

### Programming Languages & Runtimes

- [C Implementations](https://awesome-repositories.com/f/programming-languages-runtimes/programming-language-varieties/programming-languages/systems-languages/c/algorithm-libraries/c-implementations.md) — Implements a minimal C11 compiler that supports self-hosting and language feature validation.
- [C Source Translators](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/c-source-translators.md) — Translates C11 source files into machine-specific assembly instructions for target processor architectures. ([source](https://github.com/rui314/chibicc#readme))
- [Compiler Construction Tutorials](https://awesome-repositories.com/f/programming-languages-runtimes/compiler-interpreter-internals/compiler-construction-tutorials.md) — Serves as a reference implementation for studying compiler construction techniques.
- [Compiler Verification Suites](https://awesome-repositories.com/f/programming-languages-runtimes/compiler-interpreter-internals/compiler-infrastructure/compiler-verification-suites.md) — Executes comprehensive test suites to ensure accurate processing of language features. ([source](https://github.com/rui314/chibicc/blob/main/Makefile))
- [Preprocessors](https://awesome-repositories.com/f/programming-languages-runtimes/programming-language-varieties/programming-languages/systems-languages/c/preprocessors.md) — Handles complex macro expansions and conditional compilation directives to prepare source code for translation.
- [Macro Expansion Engines](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/metaprogramming-macros/hygienic-macro-systems/macro-expansion-engines.md) — Replaces macro tokens with defined bodies while preventing infinite recursion. ([source](https://github.com/rui314/chibicc/blob/main/preprocess.c))
- [Recursion Protection Mechanisms](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/metaprogramming-macros/hygienic-macro-systems/recursion-protection-mechanisms.md) — Prevents infinite recursion during macro expansion using hidesets to ensure predictable processing.
- [Lexical Analyzers](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/lexical-analyzers.md) — Converts raw character streams into structured tokens by identifying identifiers, keywords, and punctuators. ([source](https://github.com/rui314/chibicc/blob/main/tokenize.c))

### DevOps & Infrastructure

- [Compiler Bootstrapping](https://awesome-repositories.com/f/devops-infrastructure/cicd-pipeline-automation/core-build-engines/build-toolchains/compiler-bootstrapping.md) — Verifies compiler integrity by using the generated binary to successfully compile its own source code.

### Education & Learning Resources

- [Compiler Reference Implementations](https://awesome-repositories.com/f/education-learning-resources/educational-programming-tools/compiler-reference-implementations.md) — Provides a reference implementation for learning compiler construction, including tokenization, macro expansion, and code generation.

### Data & Databases

- [Recursive Descent Parsers](https://awesome-repositories.com/f/data-databases/data-transformation-functions/recursive-processors/recursive-logic-implementations/recursive-descent-parsers.md) — Translates source code into an abstract syntax tree using recursive function calls corresponding to grammar rules.

### Software Engineering & Architecture

- [Single-Pass Generators](https://awesome-repositories.com/f/software-engineering-architecture/compile-time-code-generation/single-pass-generators.md) — Emits machine-specific assembly instructions directly during parsing to minimize memory usage.
