GATE CS 2024 Set 2 | Question 21

MCQ · 1 mark · −0.33

Consider the following two sets:

Set XSet Y
P. Lexical Analyzer1. Abstract Syntax Tree
Q. Syntax Analyzer2. Token
R. Intermediate Code Generator3. Parse Tree
S. Code Optimizer4. Constant Folding

Which one of the following options is the CORRECT match from Set X to Set Y ?

  1. Option A: P – 4; Q – 1; R – 3; S – 2
  2. Option B: P – 2; Q – 3; R – 1; S – 4 (correct)
  3. Option C: P – 2; Q – 1; R – 3; S – 4
  4. Option D: P – 4; Q – 3; R – 2; S – 1

Answer

(B)

Explanation

Match each phase with what it produces or does:

  • P → 2. The lexical analyzer groups the input characters into lexemes and passes them on as tokens.
  • Q → 3. The syntax analyzer checks the token stream against the grammar; the derivation it finds is a parse tree.
  • R → 1. An abstract syntax tree, a compact tree of operators and operands without the parse tree's extra grammar nodes, is a common intermediate representation.
  • S → 4. Constant folding, such as replacing 2 * 3 by 6 at compile time, is a code optimization.

This gives P – 2; Q – 3; R – 1; S – 4. Option C swaps the two trees, and A and D misplace tokens and constant folding.

Answer: B