GATE CS 2024 Set 2 — Question 21

MCQ+1 / -0.33EasyLexical AnalysisCompiler DesignSyntax AnalysisIntermediate Code GenerationCode Optimization

Compiler Design → Code Optimization

Last updated

Question

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?
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

Correct answer

(B) P – 2; Q – 3; R – 1; S – 4

Solution

The correct mapping between the compiler phases and their associated concepts is:
  • P. Lexical Analyzer: Reads the source program character by character and groups them into meaningful sequences called lexemes, producing Tokens (2).
  • Q. Syntax Analyzer: Takes tokens as input and generates a Parse Tree (3) (or Concrete Syntax Tree) checking for syntax errors.
  • S. Code Optimizer: Improves the intermediate code. Constant Folding (4) is a standard optimization technique where constant expressions are evaluated at compile time.
  • R. Intermediate Code Generator: Generates an intermediate representation. While Syntax Analysis produces the Parse Tree, the Abstract Syntax Tree (AST) (1) is often considered a high-level intermediate representation or the output of a syntax analyzer used for intermediate code generation. Given the options, R maps to 1.
Matching:
  • P \rightarrow 2
  • Q \rightarrow 3
  • R \rightarrow 1
  • S \rightarrow 4
This corresponds to option (B).

More questions on Code Optimization

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free