Medium ●●

🏭 Phases of a Compiler

Why it matters: Easy conceptual marks: which phase does what, and which phase catches which error.

Subtopics

Each subtopic has its own page: idea, why, how, example, play, check. Mark each one understood when it clicks. 0 of 3 done.

Formulas

Front end
lexical + syntax + semantic + intermediate code generation (machine independent)
Back end
code optimisation (machine dependent part) + code generation + target-specific peephole
Pass
one complete traversal of the source or its intermediate form; several phases can be grouped in one pass

What GATE asks from this

Question types seen repeatedly in past papers. More stars means more frequent.

★★★
Which phase detects the given error
Classify an erroneous code snippet as lexical, syntax or semantic (or run time).
★★★
Order / purpose of phases
Which phase produces tokens, parse tree, three-address code, which uses the symbol table.
★★★
Cross compiler / bootstrapping
Identify the machine a cross compiler runs on and the one it targets.

Ratings are approximate, based on recurring patterns in past GATE CSE papers.

Previous year questions

4 real questions from the official GATE CSE papers (2018 to 2025), newest first, each with the official answer key and a worked solution. Questions are the property of the GATE organising institutes; this copy is for your personal study.

4 questions · 0 correct of 0 attempted · marks 0 / 4

Year:
GATE 2025 CS1 · Q12MCQ1 mark
Which ONE of the following statements is FALSE regarding the symbol table?
GATE 2024 CS2 · Q21MCQ1 mark
Consider the following two sets: Set X: P. Lexical Analyzer, Q. Syntax Analyzer, R. Intermediate Code Generator, S. Code Optimizer. Set Y:
1. Abstract Syntax Tree,
2. Token,
3. Parse Tree,
4. Constant Folding. Which one of the following options is the CORRECT match from Set X to Set Y?
GATE 2020 · Q9MCQ1 mark
Consider the following statements. I. Symbol table is accessed only during lexical analysis and syntax analysis. II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment. III. Errors violating the condition "any variable must be declared before its use" are detected during syntax analysis. Which of the above statements is/are TRUE?
GATE 2018 · Q8MCQ1 mark
Which one of the following statements is FALSE?

Common traps

Undeclared variable and type mismatch are semantic, not syntax errors.
The parser (syntax analysis) does not check types; it only checks structure.