Caffeinated Coder
Book an appointment
Lesson S5 · Special topics

Inside a compiler

Open up a real, tiny compiler and watch one expression, x + 2 * 3, change shape at every stage. A lexer cuts it into tokens, a recursive-descent parser builds an abstract syntax tree, a type checker marks every node int, and the tree is flattened into intermediate code. The optimiser folds 2 * 3 into 6 before the program ever runs, and the code generator writes three instructions for a stack machine, which runs them to get 10. Finally, see why compilers such as LLVM split into a front end and a back end.

14 min10 steps5 questionsAdvanced
Fig S5 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.