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 |
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:
- 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.
- 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.
- 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.
- 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 (iii), Q (iv), R (i), S (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.