Semantic Analysis and the Intermediate Representation
A tree that parses can still be wrong: an undeclared name, a type mismatch, a call with the wrong arity. After those checks the compiler lowers the tree into a simpler representation, which is what lets one front end serve several targets.
What a learner can do afterwards
- Name three errors a parser accepts and a semantic pass rejects
- Explain what a symbol table holds and when it is consulted
- Say why lowering to an intermediate form is worth the extra pass
1 · Read
You already know a parser builds a tree from source text. A tree that parses can still be wrong. Calling a function with two arguments when it takes three, using a name nobody declared, or mixing types all sail through parsing.
The call paint(red) parses fine, yet paint expects three numbers. The semantic pass catches it by consulting the symbol table, which recorded paint with three parameters at its declaration. Parseable is not the same as meaningful.
The symbol table maps each name to its facts: kind, type, scope, and parameters. The compiler writes an entry at every declaration and reads it back at every use. Undeclared names and mismatches surface exactly there.
After checking, the compiler lowers the tree into a simpler intermediate form. That extra pass is worth it because one front end can then serve many targets: each target only learns the simple form, not every language.
Parsing accepts structure, the symbol table checks meaning, and a simpler middle form serves every target.
2 · Watch
Take it off screen
Where it sits
8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.