Consider the following two sets: Set X: P. Lexical Analyzer Q. Syntax Analyzer…
2024
Consider the following two sets:
Set X:
P. Lexical Analyzer
Q. Syntax Analyzer
R. Intermediate Code Generator
S. Code Optimizer
Set Y:
1. Abstract Syntax Tree
2. Token
3. Parse Tree
4. Constant Folding
Which one of the following options is the CORRECT match from Set X to Set Y?
- A.
P – 4; Q – 1; R – 3; S – 2
- B.
P – 2; Q – 3; R – 1; S – 4
- C.
P – 2; Q – 1; R – 3; S – 4
- D.
P – 4; Q – 3; R – 2; S – 1
Attempted by 135 students.
Show answer & explanation
Correct answer: B
Answer: P – 2; Q – 3; R – 1; S – 4
Why this mapping?
Lexical Analyzer → Token: The scanner groups characters into tokens (identifiers, numbers, keywords, symbols) which are the input to the parser.
Syntax Analyzer → Parse Tree: The parser analyses the token sequence and constructs a parse (concrete) tree showing the syntactic structure of the program.
Intermediate Code Generator → Abstract Syntax Tree: The parsing/semantic phase produces an AST (a simplified tree representation). The intermediate-code generator is associated with this AST because it consumes the AST (or an equivalent IR) to produce intermediate code.
Code Optimizer → Constant Folding: Constant folding is an optimization that evaluates constant expressions at compile time, a typical task performed during code optimization.
Summary: match each compiler phase with the artifact it produces or primarily works with: tokens for scanning, parse tree for parsing, AST/IR for intermediate-code generation, and transformations like constant folding during optimization.
A video solution is available for this question — log in and enroll to watch it.