Weeks 2–5 · Sep 14 – Oct 11, 2026 · A whole compiler, end to end, for the smallest language worth compiling.
Start here
Lecture notes →
Context-free grammars and the two families of parser; how attributes turn a parse into a translation; and what happens between a syntax tree and a running program.
The full theory for this topic, with diagrams, worked examples and Dragon Book references. This page you are on is only an index.
Your starter code
The compiler you are extending this topic, with every TODO spelled out.student/topic-2-minimal-compiler/
Assignment: Project 2 · Minimalist Language Compiler
Full requirements and submission checklist. Due Oct 11, 2026.
Stuck on the tools rather than the theory? The toolchain tutorials cover make, Git and GitHub, flex and bison.
Reference for this topic
Explainers for the parts of this topic that reliably cause trouble. Consult them while you work.
Two Symbol Tables, One Compiler →
Your textbook describes one symbol table. This compiler has two, in different files, with different shapes and opposite lifetimes. What each one is for, and why the split is forced rather than chosen.
Temporaries & Registers →
How the compiler recycles TAC temporaries with allocTemp/freeTemp, then caches them in $t0-$t9 with spills and LRU eviction. Includes a step-through lab and two real allocator bugs, with their fixes.
Class activities
One per class meeting. Ungraded — they exist so that the assignment is not the first time you meet the idea.
Activity 1 — Derivations, Parse Trees, and Ambiguity
Derive by hand, find two trees for one string, then fix it both of the ways the Dragon Book offers and argue for one.
Activity 2 — First Contact with Bison
One rule at a time, a deliberate conflict, and your first reading of parser.output — items, dots and all.
Activity 3 — Parse Tree, Syntax Tree, and Attributes
Draw both trees, count what you threw away, then annotate with attributes and check the arrows only point upward.
Activity 4 — Build the Tree, Then Print It
Semantic actions as a syntax-directed definition, and a deliberate strdup bug that will save you a week.
Activity 5 — Predict the Symbol Table
Write down what the table will hold before you run anything, grade your own error messages, and say why the parser could not have caught any of it.
Activity 6 — Three-Address Code by Hand
Translate a tree yourself, redraw it as quadruples, then make the compiler agree with you.
Activity 7 — Your First Running Program
Hand-write the MIPS, run it in SPIM, name the three code-generation decisions you just made, then make the compiler produce it.
Activity 8 — Error Message Clinic
Score your diagnostics out of four, classify your recovery strategy, rewrite the worst, and swap compilers.