Question

Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:

Input Compiler Phase
(P) Syntax tree (i) Code generator
(Q) Character stream (ii) Syntax analyzer
(R) Intermediate representation (iii) Semantic analyzer
(S) Token stream (iv) Lexical analyzer
Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2017 answer key

Solution

Identify the standard input consumed by each compiler phase in the classic front-end and back-end pipeline.

Trace the phases of a compiler:

  1. Lexical analyzer: Reads the source program as a character stream and groups characters into tokens (token stream). Thus, input (Q) Character stream is processed by phase (iv) Lexical analyzer.
  2. Syntax analyzer (parser): Takes the token stream from the lexical analyzer and constructs a parse tree or abstract syntax tree. Thus, input (S) Token stream is processed by phase (ii) Syntax analyzer.
  3. Semantic analyzer: Takes the syntax tree and performs type checking, scope resolution, and semantic validations. Thus, input (P) Syntax tree is processed by phase (iii) Semantic analyzer.
  4. Code generator: Takes intermediate representation (IR) code and produces target machine code. Thus, input (R) Intermediate representation is processed by phase (i) Code generator.

Combining the pairs: P →\to (iii), Q →\to (iv), R →\to (i), S →\to (ii), which corresponds to option C.

Final answer

C

Common trap

Confusing the input of a compiler phase with its output.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 2
Question
5 of 65, printed as CS Q.5
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.