the whole stack, no fluff · every stage actually runs
Mini-Compiler — your words → the machine's jumps
You write one line. Watch it become four things: tokens (chopped into atoms), a
tree (the structure), assembly (real CMP + conditional jump + labels), and then it
executes to prove it computes what you meant. The while becomes exactly the
compare-and-jump pattern — that's the compiler's one real trick.
SOURCEsupports: x = EXPR and while (a < b) { ... } · EXPR = a + b etc.
edit the source and recompile — try x < 20 or x + 3
1 · Tokens (lexing)
Chop the text into atoms — keywords, numbers, names, operators. No meaning yet, just words.
2 · Tree (parsing)
Build the structure: what's a loop, what's its condition, what's its body.
3 · Assembly (code generation)
Walk the tree, emit real instructions. The while → LOAD, CMP, conditional jump out, body, JMP back. Labels mark where jumps land.
4 · Execute — prove it's real
ACC
0
x
—
CMP flag
—
PC
0
Compile first, then step through the generated assembly and watch the loop run.
The compiler's one trick, in plain sight: you wrote while once. It knew that means
"label the top, LOAD the variable, CMP it, jump OUT if the condition fails, run the body, JMP back to the top." Four
machine instructions from one word — that pattern-knowledge is the compiler. And notice: it audits the form
before running — bad syntax never makes it to assembly. But "it compiled" only proves the grammar is valid, not
that the logic is right. Only the execution (stage 4) proves the function. Form-check ≠ truth-check, one more time.