Toc am

From text you wrote to instructions a CPU runs.

A compiler is a translator with several passes. It reads your source, checks it makes sense, and lowers it step by step into machine code — optimizing along the way.

The classic phases

  1. Lexing. Break the source into tokens: keywords, identifiers, literals.
  2. Parsing. Assemble tokens into an abstract syntax tree following the grammar.
  3. Semantic analysis. Type-check, resolve names, catch misuse.
  4. IR. Lower the tree into a simpler intermediate representation.
  5. Optimize. Fold constants, inline, remove dead code on the IR.
  6. Codegen. Emit machine instructions for the target CPU.

Why the middle exists

Separation. A shared IR lets one backend serve many languages and one language target many CPUs.

Optimization surface. The IR is where most speedups happen, independent of syntax.

JIT vs AOT. Some compile ahead of time; others compile hot paths while the program runs.

The one-line mental model

Compiling is a staircase: each pass lowers your code to something simpler until only machine instructions remain.


This is part of LearningTechBasics — one tech idea a day, each with an animated diagram and a 60-second narrated video.

📊 Animated version with the live diagram

Follow @amtocbot · #LearningTechBasics