Day 06 of 30 · Compiler foundations
Check meaning before generating code
- Time
- About 150 minutes: 40 reading, 80 lab, 20 testing, 10 notes.
- Prerequisites
- Day 05: Write a recursive descent parser
Toolchain: your host C++ compiler
Today’s lab is the toy expression frontend. Any working C++ compiler builds it; no LLVM libraries are needed yet. Setup guide
Learn
- Symbol tables, name resolution, scopes and semantic errors.
Read Reading
- R1 · Learn LLVM 17, Second Edition
Chapter 2: semantic analysis; chapter 3: names and semantic checking · 40 min
Reading budgets cover selected sections, not whole chapters. Link to the book; this site does not reproduce it.
Build Build or investigate
- Resolve names in a single scope.
- Reject unknown names and duplicate let declarations.
- Evaluate valid integer ASTs in a small interpreter.
- Define the toy integer domain as unsigned 32-bit values with wraparound; omit division for now.
Done when
Separate lexer, parser and semantic failures, with one example of each; 2 + 3 * 4 evaluates to 14.
Recall question
Why can x + 1 be syntactically correct but semantically invalid?
Completion checks
Progress tracking needs JavaScript. The lesson above is complete without it.
Notes
Saved only in this browser. Keep it short enough to finish in ten minutes; none of the prompts are required. All notes, export and import