GateAI
Lexical Analysis

GATE CSE 2024 Set 2 · Q21

MCQ1 markEasy

Time

Consider the following two sets: Which one of the following options is the CORRECT match from Set X to Set Y ?

GATE CSE 2024 Set 2 Q21 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) P-2; Q-3; R-1; S-4

Lexical Analysis

Let us analyze the role and output of each compiler phase:

  1. P. Lexical Analyzer: Takes the source program as an input stream of characters and produces a sequence of Tokens as output. Hence, P→2\text{P} \rightarrow 2.

  2. 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, Q→3\text{Q} \rightarrow 3.

  3. 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, R→1\text{R} \rightarrow 1.

  4. 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, S→4\text{S} \rightarrow 4.

Therefore, the correct mapping is:

P−2;  Q−3;  R−1;  S−4\text{P} - 2;\; \text{Q} - 3;\; \text{R} - 1;\; \text{S} - 4

This matches Option (B).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Lexical Analysis in GATE CSE

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 Analysis

More from GATE CSE 2024 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2024 Set 2 · Q21 · MCQ

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.