Consider the following two sets: Which one of the following options is the CORRECT match from Set X to Set Y ?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2024 Set 2 · Q21
Time

Select one answerSingle correct
Solution
Official answer: B) P-2; Q-3; R-1; S-4
Lexical AnalysisLet us analyze the role and output of each compiler phase:
P. Lexical Analyzer: Takes the source program as an input stream of characters and produces a sequence of Tokens as output. Hence, .
Q. Syntax Analyzer (Parser): Takes the tokens generated by the lexical analyzer and verifies them against the grammar, constructing a Parse Tree (or concrete syntax tree). Hence, .
R. Intermediate Code Generator: Translates the parsed structure into an intermediate representation such as an Abstract Syntax Tree (AST), Directed Acyclic Graph (DAG), or Three-Address Code (TAC). Hence, .
S. Code Optimizer: Implements machine-independent optimizations, including Constant Folding (evaluating constant expressions at compile time rather than execution time), constant propagation, and dead-code elimination. Hence, .
Therefore, the correct mapping is:
This matches Option (B).
Try the question first, then check your work.
Examiner trap
Recall the fundamental output or associated technique for each compiler phase: lexical analysis produces tokens, syntax analysis builds a parse tree, and constant folding is an optimization technique.
This Lexical Analysis previous year question is Q21 of the GATE CSE 2024 Set 2 paper. Find more GATE CSE PYQs on Lexical Analysis in Compiler Design, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Lexical Analysis PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Lexical Analysis has 7 GATE CSE PYQs across 6 papers from 2011 to 2026. 5 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2024 Set 2.
How GATE tests Lexical AnalysisIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.