Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q05 — Lexical Analysis

Explain with AI

Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:
P. Syntax treei. Code generatorQ. Character streamii. Syntax analyserR. Intermediate representationiii. Semantic analyserS. Token streamiv. Lexical analyser\begin{array}{|l|l|}\hline \text{P. Syntax tree} & \text{i. Code generator} \\ \hline \text{Q. Character stream} & \text{ii. Syntax analyser} \\ \hline \text{R. Intermediate representation} & \text{iii. Semantic analyser} \\ \hline \text{S. Token stream} & \text{iv. Lexical analyser} \\ \hline \end{array}

Choose one option
View worked solution

Answer: C

To find the correct matching, let us analyze the input processed by each phase of a standard compiler:

  • Q. Character stream is the raw input program. It is processed by the iv. Lexical analyser to produce a stream of tokens. Thus, Q → iv.
  • S. Token stream is the output of the lexical analyzer and serves as the input to the ii. Syntax analyser (parser) to construct a parse tree or syntax tree. Thus, S → ii.
  • P. Syntax tree is the input to the iii. Semantic analyser, which performs type checking and other static semantic checks. Thus, P → iii.
  • R. Intermediate representation (IR) is processed by the i. Code generator to produce the target machine code. Thus, R → i.

Combining these matches:

  • P→iii\text{P} \rightarrow \text{iii}
  • Q→iv\text{Q} \rightarrow \text{iv}
  • R→i\text{R} \rightarrow \text{i}
  • S→ii\text{S} \rightarrow \text{ii}

This corresponds to Option C.

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

Published
Report a correction
Keep exploringMore Lexical Analysis questions