← back

How a compiler turns source into a running program

Click the highlighted words to expand each idea.

Source code
the text you write characters in a file, meant for humans to read
becomes tokens,
a lexer scans the characters
splitting them into keywords, names, numbers, and symbols discarding spaces and comments along the way
then a syntax tree,
a parser groups the tokens
following the language grammar nesting expressions inside statements inside blocks
gets checked for meaning,
a semantic pass verifies names and types catching mistakes long before the program ever runs
turns into an intermediate form,
a simpler internal language easier to reason about than the original text
is optimized,
the compiler rewrites the intermediate form
to run faster and take less space without changing what the program actually does
and finally lowered
a backend picks real machine instructions matching the target processor and its rules
to machine code,
numbers the CPU can decode directly each one a tiny, concrete operation
that runs.
the processor executes the instructions one after another, billions per second

Original explainer written for revealing_text_26.