Compiler Foundations

Core pipeline

  • Lexing -> Parsing -> Semantics -> Lowering -> Runtime
  • each stage has a strict contract

Ownership discipline

  • lexer: token classes + locations
  • parser: grammar + AST shape
  • semantics: symbol and type/rule checks
  • lowering: representation transform

Why phases help

  • each stage has small failure surface
  • isolated tests for each transformation
  • deterministic errors and artifacts

Tokens, lexemes, AST

  • lexeme is raw text
  • token is typed chunk + position
  • AST is structural meaning

Precedence via grammar

  • term/factor hierarchy gives precedence
  • loop-based parser with precedence levels keeps associativity stable

Error design

  • first-stage failures should be surfaced early
  • include line/column + expected token context

Determinism

  • same source -> same outputs at every stage
  • avoids flaky diagnostics and non-reproducible builds

Practice checks

  • map which stage handles which rule
  • reason about which stage emits which error class
1 / 1
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.