Compilers

How source code is turned into a program the computer can run.

A compiler reads your code and produces an equivalent program in another language, usually machine code. This track walks through each stage (lexing, parsing, type checking, optimization and code generation), which also helps you read error messages and understand tools like linters and formatters.

  • Advanced
  • 7 lessons
  • Runs in your browser
Not started yet
Start lesson 1

Lessons

  1. The Compiler PipelineMost compilers, from GCC to the TypeScript checker, follow the same sequence of stages. This lesson gives an overview of each stage so the rest of the track has a map.
  2. Lexing — Text to TokensThe lexer reads raw characters and groups them into tokens such as words, numbers and operators. It's the simplest stage, and you'll write a working one in about 40 lines.
  3. Parsing — Tokens to TreesThe parser turns a flat list of tokens into a tree that shows structure and order of operations. This tree, the abstract syntax tree (AST), is what most language tools work with.
  4. Names, Scopes & Type CheckingSemantic analysis checks whether names exist and whether types fit, which the parser does not. It's the stage that catches many real bugs before the program runs.
  5. OptimizationOptimizers rewrite a program in many small steps that keep its behavior the same but make it faster. You'll see the common passes and what they mean for how you write code.
  6. Code Generation, Linking & JITsThis lesson covers the final stages: turning IR into real instructions, linking separate files into one executable, and how JIT compilers do all of this while a program runs.
  7. Compilers CheatsheetThe pipeline, the vocabulary, and the experiments — one page.

Install it on your own computer

This is a concepts track, so any compiler you already have will do for the experiments. Compiler Explorer (godbolt.org) shows compiler output for 40+ languages in the browser with nothing to install. You do not need this to follow the lessons: the examples run in your browser.

Bash
# Zero install: https://godbolt.org
# paste code, see assembly, toggle optimization flags

# Or a local C compiler via WSL:
wsl --install
# then inside WSL:
sudo apt install gcc
gcc -O2 -S hello.c -o hello.s   # emit assembly

What people build with Compilers

Learn the basics first, then pick up these tools when a project needs them.

Practical uses

  • Translate languages into executable behavior
  • Build linters, formatters, and code analyzers
  • Create domain-specific languages
  • Optimize programs and developer tooling

Projects to try

  1. Arithmetic parser
  2. Tiny interpreted language
  3. Static-analysis linter
  4. Bytecode compiler and virtual machine

Common tools and packages

LLVMANTLRTree-sitterBisonFlexMLIRCraneliftWebAssembly

Well-known software

ClangGCCRust compilerTypeScript compilerV8Babel