C in 4 Funs

This self-compiling subset of C is written in one 500 line file containing four functions. Branches add syntactic sugar like struct and switch. github

Inspiration for Another Mini ARM C Compiler (AMaCC) built from scratch, supporting ARM architecture, with three execution modes: interpret, JIT or ELF for ARM. github

# Functions

next() scans for next token.

expr(int lev) compiles expressions.

stmt() compiles statements.

main(int argc, char **argv) alloc, compile and execute.

# Use

Bootstrap the compiler with gcc.

gcc -o c4 c4.c

Compile and execute one file.

./c4 hello.c

Compile the compiler which then executes to compile and execute the next argument.

./c4 c4.c hello.c

Nest the compiler-compiles which execute recursively.

./c4 c4.c c4.c hello.c