A minimalist, self-hosting C compiler. BCC is a fork of c4 by Robert Swier, extended with a preprocessor, a loader, and a small bare-metal-oriented C library (blibc).
The original c4 compiles a small but real subset of C — just enough to compile itself — in about four functions: next (lexer), expr (expression parser), stmt (statement parser), and main. BCC builds on that same idea while adding a few extra pieces for practical use.
| File | Purpose |
|---|---|
c4.c |
The core compiler — lexer, parser, and virtual machine in one file. |
hello.c |
A minimal demo program you can compile and run with BCC. |
loader.c |
|
preprocessor.c |
|
blibc/ |
|
Makefile |
Build script for the compiler and its components. |
make
Or manually with gcc:
gcc -o c4 c4.c
Compile and run a C source file directly:
./c4 hello.c
Run in step-trace mode:
./c4 -s hello.c
Compile the compiler with itself, then run a program:
./c4 c4.c hello.c
Compile the compiler with itself compiling itself, then run a program:
./c4 c4.c c4.c hello.c
Like the original c4, BCC only supports a small subset of C: char, int, and pointer types; if, while, return, and basic expressions; enough to be self-hosting. It is not a general-purpose, standards-compliant C compiler — it's built for minimalism and clarity.
Built on c4 by Robert Swier — see Thanks Robert.md.
See LICENSE.