This capstone project takes you through the complete journey of building a C compiler for a subset of C89. You will learn lexing, recursive-descent parsing, type checking with symbol tables, intermediate representation design, and x86-64 code generation. By the end, you will have a working compiler that takes C source files and produces executable binaries.
Build a lexer that tokenizes C source into keyword, identifier, number, string, and operator tokens. Then build a recursive-descent parser that produces an AST.
Implement a symbol table with block scoping. Walk the AST to perform type checking, resolve identifiers, and detect semantic errors like type mismatches and undefined variables.
Design a three-address intermediate representation. Translate the AST to IR with temporaries, labels, and control flow. Implement basic optimizations like constant folding and dead code elimination.
Translate IR to x86-64 assembly. Implement register allocation (linear scan), stack frame management, and the System V calling convention. Link against libc for I/O.
Add dataflow analysis and peephole optimization. Implement common subexpression elimination and register coalescing. Benchmark against GCC -O0 for comparable output.
Complete all prerequisite tracks to unlock this capstone. Once submitted, your project will be peer-reviewed by 3 fellow completers.
Start Prerequisites