Phases of Compiler MCQs: 12 Solved Questions with Explanations

Solve 12 compiler-phase MCQs and learn why each answer is correct through a source-to-target trace, phase handoffs and a quick trap checklist.

KnowledgeGate Team

Exam prep & CS education

3 Sep 20268 min read

Compiler-phase questions look like memory checks, but distractors repeatedly swap a phase's input, output, formal model or responsibility. Identify the representation entering and leaving a phase before selecting an answer. First trace total = base + rate * 4; from source statement to target code, then apply the same handoff check to each MCQ.

Choose an option first. Then explain the relevant phase handoff in one sentence before reading the solution. Open the linked solved page after each explanation to retry the question in its topic context. If you are building a broader study plan, place this topic within GATE CS Exam Preparation.

1. Compiler phases in one worked source-to-target trace

The usual sequence is lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization and target code generation. The symbol table and error handling support several phases, so they are not merely extra stages in a one-way chain. The broader Compiler Design syllabus places these handoffs in context.

Assume the symbol table records two compile-time integer constants, base: const int = 12, rate: const int = 3 and total: int. Compile total = base + rate * 4;.

  1. Lexical output: eight tokens: <id,total>, <assign,=>, <id,base>, <plus,+>, <id,rate>, <mul,*>, <int,4>, <semicolon,;>.

  2. Syntax output: =(total, +(base, *(rate, 4))). The tree preserves multiplication before addition.

  3. Semantic result: rate * 4 is int; base + (...) is int; assignment to total: int is valid.

  4. Unoptimized three-address code: t1 = rate * 4; t2 = base + t1; total = t2.

  5. Optimization: rate * 4 = 3 * 4 = 12, then base + 12 = 12 + 12 = 24, so the result becomes total = 24.

  6. Illustrative target code: MOV R0, #24, followed by STORE total, R0.

The invariant is simple: each phase consumes one representation and hands a more structured or more target-specific representation to the next.

2. Phases of compiler MCQs 1-3: tokens, parser input and grammar

Question 1

Exam reference: BEL 2023, Probationary Engineer.

Name the phase of compiler, which separates characters of the source language into groups that logically belong together, these groups are called tokens.

  • A. Code optimization

  • B. Syntax analysis

  • C. Error handling

  • D. Lexical analysis

Correct answer: D. Lexical analysis.

Lexical analysis groups characters into tokens. Parsing consumes them later; optimization and error handling do not perform that grouping. Solved page.

Question 2

Exam reference: Indian Space Research Organization 2025.

Which compiler phase receives tokenized output?

  • A. Lexical Analyser

  • B. Parser

  • C. Pre-processor

  • D. Assembler

Correct answer: B. Parser.

The lexical analyser produces tokens; the parser receives them and checks grammar. The pre-processor and assembler work at other points. Solved page.

Question 3

Exam reference: UGC NET 2023.

Which phase of compiler checks the grammar of programming?

  • A. Code Optimization

  • B. Semantic Analysis

  • C. Code Generators

  • D. Syntax Analysis

Correct answer: D. Syntax Analysis.

Syntax analysis checks grammatical structure. Semantic analysis instead checks meaning, including type and declaration consistency. The correct choice is D. Solved page.

3. Phases of compiler MCQs 4-6: types, static checking and phase functions

Question 4

Exam reference: DSSSB 2024, TGT.

Which of the following phase of the compiler, gathers type information and saves it in either the syntax tree or the symbol table, for subsequent use during intermediate code generation?

  • A. Semantic Analyzer

  • B. Code Analyzer

  • C. Syntax Analyzer

  • D. Lexical Analyzer

Correct answer: A. Semantic Analyzer.

The semantic analyser records type information for later code generation. The lexer classifies tokens, while the parser checks grammatical form. Solved page.

Question 5

Exam reference: Beltron Programmer 2025, Shift-3.

Which of the following statements about statically typed languages is true?

  • A. Types are associated with values, not variables

  • B. Variable types can change during execution

  • C. Type checking is done at runtime

  • D. Type errors are caught during compilation

Correct answer: D. Type errors are caught during compilation.

Static checking happens before execution. Here the integer operands produce an int, valid for total: int; a string assignment would fail compilation. Solved page.

Question 6

Exam reference: BEL 2023, Probationary Engineer.

Match the phases of compiler with its function.

Phases

Function

I

Intermediate code generator

1

Keeps track of the names used by the program

II

Code generation

2

Create a stream of simple instructions

III

Table management

3

Produces the object code

  • A. I - 1; II - 2; III - 3

  • B. I - 1; II - 3; III - 2

  • C. I - 2; II - 3; III - 1

  • D. I - 2; II - 1; III - 3

Correct answer: C. I - 2; II - 3; III - 1.

Intermediate code generation creates simple instructions, code generation emits object code, and table management records names. Thus I-2, II-3 and III-1. Solved page.

4. Phases of compiler MCQs 7-9: order and front-end roles

Question 7

Exam reference: UGC NET 2023, December.

Arrange the following phases of a compiler as per their order of execution (start to end)

(A) Target code generation

(B) Syntax Analysis

(C) Code optimization

(D) Semantic Analysis

(E) Lexical Analysis

Choose the

correct

answer from the options given below :

  • A. (B), (E), (D), (A), (C)

  • B. (E), (D), (B), (A), (C)

  • C. (E), (B), (D), (C), (A)

  • D. (B), (D), (E), (A), (C)

Correct answer: C. (E), (B), (D), (C), (A).

Characters become tokens before parsing and semantic checking. Optimization precedes target code. Intermediate-code generation normally appears before optimization but is not listed. Solved page.

Question 8

Exam reference: UGC NET 2017, November.

Match the description of several parts of a classic optimizing compiler in List–I with the names of those parts in List–II

List–I

(a) A part of a compiler that is responsible for recognizing syntax

(b) A part of a compiler that takes as input a stream of characters and produces as output a stream of words along with their associated syntactic categories

(c) A part of a compiler that understands the meanings of variable names and other symbols and checks that they are used in ways consistent with their definitions

(d) An IR-to-IR transformer that tries to improve the IR program in some way

List–II

(i) Optimizer

(ii) Semantic Analysis

(iii) Parser

(iv) Scanner

  • A. iii,iv,ii,i

  • B. iv,iii,ii,i

  • C. ii,iv,i,iii

  • D. ii,iv,iii,i

Correct answer: A. iii,iv,ii,i.

Syntax recognition means parser, character conversion means scanner, symbol meaning means semantic analysis, and IR improvement means optimizer. The match is (iii), (iv), (ii), (i). Solved page.

Question 9

Exam reference: UGC NET 2017, November.

Consider the following statements related to compiler construction:

I. Lexical Analysis is specified by context-free grammars and implemented by pushdown automata.

II. Syntax Analysis is specified by regular expressions and implemented by finite-state machine.

Which of the above statement(s) is/are correct?

  • A. Only I

  • B. Only II

  • C. Both I and II

  • D. Neither I nor II

Correct answer: D. Neither I nor II.

The associations are swapped. Lexical work uses regular expressions and finite automata; syntax uses context-free grammars and pushdown automata. Both statements are false. Solved page.

5. Phases of compiler MCQs 10-12: tools, code and data handoffs

Question 10

Exam reference: GATE 2009.

Match all items in Group 1 with correct options from those given in Group 2.

Group 1 Group 2

P. Regular expression 1. Syntax analysis

Q. Pushdown automata 2. Code generation

R. Dataflow analysis 3. Lexical analysis

S. Register allocation 4. Code optimization

  • A. P-4. Q-1, R-2, S-3

  • B. P-3, Q-1, R-4, S-2

  • C. P-3, Q-4, R-1, S-2

  • D. P-2, Q-1, R-4, S-3

Correct answer: B. P-3, Q-1, R-4, S-2.

Regular expressions support lexical analysis, pushdown automata support parsing, dataflow analysis supports optimization, and register allocation belongs to code generation. Solved page.

Question 11

Exam reference: Indian Space Research Organization 2008.

Which of the following class of statement usually produces no executable code when compiled?

  • A. declaration

  • B. assignment statements

  • C. input and output statements

  • D. structural statements

Correct answer: A. declaration.

A plain declaration mainly supplies compile-time information, usually without an executable instruction. Initialization or language-specific runtime work can differ, hence “usually.” Solved page.

Question 12

Exam reference: GATE 2017, Set 2.

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

\(\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}\)

  • A. \(\text{P-ii; Q-iii; R-iv; S-i}\)

  • B. \(\text{P-ii; Q-i; R-iii; S-iv}\)

  • C. \(\text{P-iii; Q-iv; R-i; S-ii}\)

  • D. \(\text{P-i; Q-iv; R-ii; S-iii}\)

Correct answer: C. \(\text{P-iii; Q-iv; R-i; S-ii}\).

Semantic analysis consumes the syntax tree, lexical analysis the character stream, code generation the IR, and parsing the token stream. Solved page.

6. The compiler-phase traps these 12 MCQs expose

Trap

Correct distinction

Questions

Tokens

Lexer produces; parser consumes

Q1-Q3

Syntax/semantics

Structure versus types and names

Q3-Q5

Order

Follow data dependencies

Q7-Q8

Formal tools

Regex/FA: lexical; CFG/PDA: syntax

Q9-Q10

Symbol table

Supports several phases

Q4 and Q6

Declarations

May emit no executable instruction

Q11

Use this 20-second routine: identify whether the stem asks for input, output, job, order or model. Write the adjacent handoff, then reject options that confuse producer and consumer.

Then use Compiler Design MCQs for wider practice.

7. Phases of compiler: the next practice step

Redo Q7, Q9, Q10 and Q12 without looking, on a blank page. Q7, Q9, Q10 and Q12 test phase order, formal models, tools and representation handoffs. Then replay total = base + rate * 4; and state the artifact after every phase. Your optimized value must still be 24.

Use GATE Guidance by Sanchit Sir for a sequenced Compiler Design learning route. Move to the GATE Test Series as a timed follow-up only after concept practice.

The short version: when a phase question feels ambiguous, identify the representation entering the phase and the representation leaving it. That single input-output check resolves most distractors.