Home › GATE CSE › computerscience › Compiler Design › After the parser produces an AST, the next compi…
After the parser produces an AST, the next compiler phase is typically
Ascanning
Bsemantic analysis
Clinking
Dgarbage collection
Answer & Solution
Correct answer: B. semantic analysis
1. Typical compiler pipeline:
- Scanner → tokens
- Parser → AST
- Semantic analyser → annotated AST (types, scopes, etc.)
- Optimiser → intermediate representation
- Code generator → machine code
2. Semantic analysis catches errors the parser cannot:
- Type mismatches (e.g. adding string to integer)
- Undefined variables / functions
- Scope rules (variable used out of scope)
3. Scanning (A) is the FIRST phase, not after parsing. Linking (C) and GC (D) are unrelated to AST processing.
_Source: Bob Nystrom, "Crafting Interpreters", Ch 1 (compiler pipeline overview)._
Related questions
The FOLLOW(A) set in LL parsing isThe FIRST(α) set of a string α in LL parsing isA SHIFT/REDUCE CONFLICT in an LR parser occurs whenWhich of these is a BOTTOM-UP (LR) parser feature?An LL(1) grammar requires that, given the leftmost non-terminal and ONE token of lookaheadLL parsers (recursive descent) parse from thePANIC MODE error recovery in a parser works byWhat is a SYNTAX ERROR?