Skip to content

annurdien/bcc

Repository files navigation

BCC (Bakpia C Compiler)

My implementation of a C compiler for x64 processors.

Reference: Writing a C Compiler — Build a Real Programming Language from Scratch by Nora Sandler

Checkpoint (Jan 7, 2026)

  • Stage 1 - Minimal C Program (function decl, return constant)
  • Stage 2 - Unary Operators
    • Negation (-)
    • Bitwise Complement (~)
    • Logical Negation (!)
  • Stage 3 - Binary Operators
    • Addition (+)
    • Subtraction (-)
    • Multiplication (*)
    • Division (/)
  • Stage 4 - Relational & Logical Operators
    • Relational (<, >, <=, >=)
    • Equality (==, !=)
    • Logical AND (&&)
    • Logical OR (||)
  • Stage 5 - Local Variables & Assignment
    • Variable Declaration (int x = ...)
    • Variable Usage (return x)
    • Assignment (x = y)
  • Stage 6 - Conditionals
    • If Statements (if (cond) { ... } else { ... })
    • Conditional Operator (cond ? true : false)
    • Compound Statements / Blocks ({ ... })
  • Stage 7 - Loops
    • While (while)
    • Do-While (do ... while)
    • For (for)
    • Break (break)
    • Continue (continue)
  • Stage 8 - Functions
    • Function Function Definition & Calling (Multi-argument)
    • System V ABI (Arguments in registers)
  • Stage 9 - Global Variables
    • Global Variable Declaration
    • Global vs Local Scope (Shadowing)
  • Stage 10 - Static Variables
    • Static Global Variables (Internal Linkage)
    • Static Local Variables (Persistence)
  • Stage 11 - Long Integers
    • 64-bit Integer type (long)
    • Type Promotion
  • Stage 12 - Unsigned Integers
    • Unsigned types (unsigned int, unsigned long)
    • Unsigned Arithmetic & Comparison
  • Stage 13 - Bitwise Operators
    • AND (&)
    • OR (|)
    • XOR (^)
    • Shift Left (<<)
    • Shift Right (>>)
  • Stage 14 - Compound Assignment
    • Arithmetic Compound (+=, -=, *=, /=, %=)
    • Bitwise Compound (&=, |=, ^=, <<=, >>=)
  • Stage 15 - Increment & Decrement
    • Pre-increment (++x)
    • Post-increment (x++)
    • Pre-decrement (--x)
    • Post-decrement (x--)
  • Stage 16 - Pointers
    • Pointer Declaration (int *p)
    • Address-Of Operator (&x)
    • Dereference Operator (*p)
    • Pointer Arithmetic (Basic)

Test System

CI The test runner test_runner.py supports Automatic Test Discovery.

  • Add a .c file to tests/.
  • Include // RETURN: <expected_code> in the file.
  • make test-all will automatically compile, run, and verify the exit code.

About

Bakpia C Compiler

Topics

Resources

Stars

Watchers

Forks