Skip to content
Official PYQ · 2024

GATE CS 2024 Set 2 Q11 — Lexical Analysis

Explain with AI

​​​Consider the following two sets:

Set XSet Y P.Lexical Analyzer 1.Abstract Syntax Tree Q.Syntax Analyzer2.Token R.Intermediate Code Generator3.Parse Tree S.Code Optimizer4.Constant Folding\begin{array}{|ll|ll|}\hline & \textbf{Set X} & & \textbf{Set Y} \\ \hline \text{ P.} & \text{Lexical Analyzer } & \text{1.}& \text{Abstract Syntax Tree} \\ \hline \text{ Q.}& \text{Syntax Analyzer} & \text{2.} & \text{Token} \\ \hline \text{ R.} & \text{Intermediate Code Generator} &\text{3.} & \text{Parse Tree} \\ \hline \text{ S.} & \text{Code Optimizer} &\text{4.} & \text{Constant Folding} \\ \hline \end{array}
Which one of the following options is the CORRECT match from Set X\boldsymbol{X} to Set Y\boldsymbol{Y}?

Choose one option
View worked solution

Answer: B

We can determine the correct match by analyzing the primary functions and outputs of each compiler phase:

  • P. Lexical Analyzer →\rightarrow 2. Token:
    The lexical analyzer reads the source program as a stream of characters and groups them into meaningful sequences called lexemes, which are mapped to tokens.
  • Q. Syntax Analyzer →\rightarrow 3. Parse Tree:
    The syntax analyzer (parser) takes the tokens as input and verifies their grammatical structure against the source language's context-free grammar, producing a parse tree.
  • R. Intermediate Code Generator →\rightarrow 1. Abstract Syntax Tree:
    The intermediate code generator often uses an abstract syntax tree (AST) as a high-level intermediate representation of the program structure before translating it into lower-level intermediate code (like three-address code).
  • S. Code Optimizer →\rightarrow 4. Constant Folding:
    Constant folding is a standard compile-time optimization technique where expressions with constant operands (e.g., 3 + 5) are evaluated at compile-time to simplify the code.

Combining these matches, we get:
P - 2; Q - 3; R - 1; S - 4

Therefore, the correct option is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Lexical Analysis questions