Coursify

Compiler Design (CD)

The Complete Compiler Design Exam Preparation Kit

60 mins

A data-driven, all-module survival guide built from analyzing 113+ questions across 2019–2024 exam papers. Contains the guaranteed questions, the exact mark distribution, the 6-week study plan, figure integration guide, and the critical mistakes that fail students in Compiler Design.


The Exam Architecture: Understanding the Paper

Before studying a single topic, understand how the exam is built. Based on 2019–2024 paper analysis across 113 questions:

Paper Structure:

  • Total Marks: 70–80 marks (external exam)
  • Duration: 3 hours
  • Section A: 8–10 MCQs × 2 marks = 16–20 marks (compulsory — all must be answered)
  • Section B: 5–6 long-answer questions × 7–14 marks = 50–60 marks (often with internal choices)

The Critical Implication: Section A (MCQs) is worth ~20 marks — nearly 25–30% of the paper — and takes only 15–20 minutes. This is the highest marks-per-minute section. The 2-mark questions consistently test: parser hierarchy, LR properties, ambiguity definitions, token counting, and phase responsibilities.

Year-wise PYQ Distribution

The 10 Guaranteed Question Types (Appear EVERY Year)

These are questions that have appeared in every exam from 2019 to 2024, or in 3+ of the 4 years. If you master these 10, you can answer at least 55 out of 70 marks on any paper.


🔴 GUARANTEED #1: LR/SLR/LALR Parsing Table Construction (14 Marks)

Module 2 | Appeared: 2019, 2022, 2023, 2024

Given a grammar, construct the canonical collection of LR(0) items, build the SLR(1) or LALR(1) parsing table, and trace a string.

What to practice:

  • Augment the grammar (S' → S)
  • Compute FIRST and FOLLOW sets
  • Build all LR(0) states (I₀ through Iₙ) — the expression grammar has 12 states
  • Construct ACTION and GOTO tables
  • Check for conflicts (S-R, R-R)
  • Trace the input string on the stack

Time to solve: 22–28 min


🔴 GUARANTEED #2: FIRST/FOLLOW + LL(1) Parsing Table (7 Marks)

Module 2 | Appeared: 2019, 2022, 2023, 2024

Compute FIRST and FOLLOW sets for all non-terminals, construct the LL(1) parsing table, and check for conflicts.

What to practice:

  • FIRST rules: terminals, ε-productions, nullable tracking across chain rules
  • FOLLOW rules: $ in start symbol, FIRST(β) for A→αBβ, propagate for nullable
  • Table construction: FIRST(α) for each production, ε → FOLLOW(A) placement
  • Conflict inspection: every cell must have at most one entry

Time to solve: 12–15 min


🔴 GUARANTEED #3: Phases of Compilation with Diagram (7 Marks)

Module 1 | Appeared: 2019, 2022, 2024

Explain the working of each phase of a compiler in detail with an example and a neat labeled diagram.

What to practice:

  • Draw the 6-phase flowchart + symbol table + error handler
  • Use the Dragon Book example: position = initial + rate * 60
  • Show output of each phase (tokens → parse tree → annotated AST → TAC → optimized code → assembly)
  • Include Lexical, Syntax, Semantic, Intermediate Code Gen, Code Optimization, Code Generation

Time to solve: 10–12 min


🔴 GUARANTEED #4: S-Attributed vs L-Attributed SDDs (7 Marks)

Module 3 | Appeared: 2019, 2022, 2023, 2024

Differentiate between S-attributed and L-attributed SDDs with suitable examples.

What to practice:

  • 3-column comparison table (property, S-attributed, L-attributed)
  • S-attributed: only synthesized, bottom-up eval, LR parser compatible
  • L-attributed: synthesized + inherited, left-to-right DFS, LL parser compatible
  • One mathematical example for each (e.g., desk calculator for S, type rules for L)

Time to solve: 10–12 min


🔴 GUARANTEED #5: Left Recursion Elimination (7 Marks)

Module 2 | Appeared: 2019, 2023

Eliminate left recursion from the given grammar. Also apply left factoring if needed.

What to practice:

  • Immediate left recursion formula: A → Aα | βA → βA', A' → αA' | ε
  • Apply to expression grammar: E → E+T | T
  • Check for indirect left recursion
  • After elimination, state whether grammar is suitable for top-down parsing

Time to solve: 8–10 min


🟠 GUARANTEED #6: NFA to DFA Conversion (7 Marks)

Module 1 | Appeared: 2024 (high probability for future years)

Differentiate between DFA and NFA, and explain the procedure to convert NFA to DFA with a suitable example.

What to practice:

  • DFA vs NFA comparison table (5+ differences)
  • ε-closure and move function definitions
  • Subset construction algorithm steps
  • Trace example: NFA for (a|b)*abb → DFA

Time to solve: 12–15 min


🟠 GUARANTEED #7: Quadruples, Triples, Indirect Triples (7 Marks)

Module 4 | Appeared: 2022, 2023

Translate an arithmetic expression into quadruples and triples representation.

What to practice:

  • Break expression into TAC first
  • Quadruples: 4 fields (op, arg1, arg2, result)
  • Triples: 3 fields (op, arg1, arg2) — results referenced by index
  • Indirect Triples: pointer array + triples table
  • Example: A = -b * (c + d) / e

Time to solve: 10–12 min


🟠 GUARANTEED #8: DAG Construction + Optimization (7 Marks)

Module 4 | Appeared: 2022, 2023, 2024

Construct a DAG for a basic block, identify common subexpressions, and generate optimized TAC.

What to practice:

  • Create leaf nodes for constants and variables
  • Build interior nodes for each operation
  • Node-label merging for copy propagation (e.g., prod = t6 → single node)
  • Reuse constant nodes across operations
  • Traverse in topological order for optimized TAC

Time to solve: 10–12 min


🟠 GUARANTEED #9: Symbol Table / Activation Records (Short Notes — 7 Marks)

Module 3 | Appeared: 2019, 2022, 2023, 2024

Write short notes on: Symbol Table OR Activation Records.

What to practice:

  • Symbol Table: Hash table structure, identifier→attribute mapping, scope stack, cross-phase usage (Lexer inserts, Parser structures, Semantic Analyzer checks types)
  • Activation Records: Runtime stack frame components (return value, parameters, dynamic link, static link, saved status, local data, temporaries), push/pop on function call

Time to solve: 8–10 min


🟠 GUARANTEED #10: Code Optimization Techniques (7 Marks)

Module 4 | Appeared: 2019, 2022, 2024

Discuss code optimization techniques — peephole, code motion, strength reduction, register allocation.

What to practice:

  • Peephole: 5 categories (redundant load/store, algebraic simplification, unreachable code, control flow optimization, null sequences)
  • Code motion: Hoisting loop-invariant computations to pre-header
  • Strength reduction: Replace i*4 with t+=4 in loops
  • Register allocation via graph coloring: Build interference graph, k-coloring, spill when degree ≥ k

Time to solve: 10–12 min

Topic-wise PYQ Frequency Analysis (All 2019–2024)

Difficulty-Level Segmentation

🟢 Easy (Foundation — Must Score):

  • All 2-mark objective questions (30+ across all modules)
  • Phases of compilation description + diagram
  • Compiler vs Interpreter comparison
  • Short notes: Handle Pruning, YACC, Symbol Table, Activation Records
  • Peephole optimization definition + examples

🟡 Medium (Application — Requires Practice):

  • FIRST/FOLLOW computation
  • LL(1) parsing table construction
  • Left recursion elimination + left factoring
  • NFA → DFA subset construction
  • DFA design (complement technique)
  • Quadruples/Triples/Indirect Triples conversion
  • DAG construction from basic blocks
  • S-attributed vs L-attributed comparison
  • SDT semantic action tracing
  • Symbol table structure & management
  • Basic block identification + CFG drawing
  • Syntax tree drawing from expressions

🔴 Hard (Mastery — High-Value Targets):

  • LR(0) canonical collection of items (12+ states)
  • SLR(1) parsing table + conflict detection
  • LALR(1) / CLR(1) table construction
  • Proof: LL(1) but not SLR(1)
  • Reaching definitions — iterative data flow (4+ iterations)
  • Register allocation via graph coloring
  • 14-mark full parser construction + trace

Figure Integration Guide (Essential Diagrams by Module)

Every 7-mark descriptive question requires a diagram for full marks. Below is the complete figure inventory mapped to specific PYQs:

Module 1 — Introduction & Lexical Analysis:

FigurePYQ ReferencePurpose
6-Phase Compiler Flowchart2019 Q6a, 2022 Q2a, 2024 Q2aShow Lexical→Syntax→Semantic→ICG→Opt→Code Gen + Symbol Table + Error Handler
Language Processing System2023 Q2aPreprocessor→Compiler→Assembler→Linker/Loader flow
NFA from Thompson's Construction2024 Q2bε, a, union, concat, Kleene star rules
DFA from Subset Construction2024 Q2bε-closure + move → state transition table
DFA for Complement Language2024 Q3aSwap accepting/non-accepting states for "NOT containing 101"
Lex Pipeline Diagram2023 Q9bspec.l → lex → lex.yy.c → gcc → scanner executable

Module 2 — Syntax Analysis:

FigurePYQ ReferencePurpose
LR(0) DFA States (12-state)2022 Q3, 2024 Q4aI₀ through I₁₁ with goto transitions
SLR(1) Parsing Table2022 Q3, 2024 Q4bACTION/GOTO with sₙ, rₙ entries
LALR(1) State Merging2022 Q4Merge LR(1) states with same core
CLR(1) with Lookaheads2023 Q5aLR(1) items with exact lookahead sets
LL(1) Parsing Table2024 Q3b, 2022 Q6bFIRST/FOLLOW-driven predictive table
Shift-Reduce Parse Trace2024 Q4d13-step stack + input + action sequence
Syntax Tree2023 Q7ca * -(b + c/d) precedence tree
Non-recursive Predictive Parser2019 Q4bStack + parsing table + input driver
Operator Precedence Relations2023 Q8b<, >, = between operators

Module 3 — Semantic Analysis & Run-time Environment:

FigurePYQ ReferencePurpose
Annotated Parse Tree2023 Q2b, 2024 Q5bAttribute values propagated bottom-up
Dependency Graph2024 Q5bTopological sort for attribute eval order
Symbol Table (Hash Table)2024 Q6a-bBuckets with identifier→attribute mappings
Activation Record Layout2019 Q2a, 2023 Q9aReturn value, links, params, locals, temps
Runtime Memory Layout2022 Q9aCode/Static/Stack/Heap regions
Scope Stack2024 Q6aNested block scope management with push/pop
Parse Tree with SDT Actions2022 Q2b{print()} at reduction points
Infix to Prefix SDT Tree2023 Q2bPrefix concatenation from bottom-up eval

Module 4 — Intermediate Code Generation & Optimization:

FigurePYQ ReferencePurpose
DAG for Basic Block2022 Q8b, 2023 Q3bNode sharing + CSE optimization
Control Flow Graph (CFG)2023 Q7bBasic blocks + edges for nested loops
Quadruple/Triple Tables2022 Q7a, 2023 Q4cop, arg1, arg2, result structure
Syntax Tree → TAC2024 Q7bExpression breakdown to 3-addr code
Reaching Definitions Flow2022 (14M)GEN/KILL propagation across CFG
Register Interference Graph2024 Q9aNodes + edges for graph coloring
Peephole Optimization Window2022 Q9dSliding window patterns
Instruction Scheduling2024 Q8bReordering to reduce pipeline stalls

Module 5 — Advanced Topics:

FigurePYQ ReferencePurpose
Object Memory Layout2024 Q9bFields + vptr at offset 0
VTable Structure2024 Q9bVirtual function dispatch mechanism
Inheritance Layout2024 Q9bSingle/multiple inheritance memory

The 6-Week Study Timeline

WeekFocusDaily TimeKey Deliverables
1Module 1: Introduction & Lexical Analysis1 hrDraw compiler phases 3x from memory; solve all 2-mark PYQs; practice NFA→DFA conversion
2Module 2 — Top-Down Parsing (LL(1))1.5 hrsFIRST/FOLLOW on 3 grammars; left recursion elimination; LL(1) table construction
3Module 2 — Bottom-Up Parsing (LR)2 hrsBuild LR(0) items; SLR table; trace id+id*id; practice one 14-mark question
4Module 3: Semantic Analysis & Run-time1 hrS-vs-L table; SDT tracing; symbol table; activation records
5Module 4: ICG & Optimization1.5 hrsQuadruples/Triples; DAG construction; basic blocks + CFG; peephole examples
6Revision + Mock Tests2 hrsModule 5 overview; Mock Test 1; error review; Mock Test 2; 2-mark blitz

The 7-Day Intensive Plan

DayTopicsPractice
1Phases of compilation + NFA/DFA + Lex7-mark phase diagram; NFA→DFA conversion
2Left recursion + FIRST/FOLLOW + LL(1) table3 FIRST/FOLLOW problems; 2 LL(1) tables
3LR(0) items + SLR(1) tableOne full 14-mark SLR problem + trace
4LR(1) + LALR(1) + CLR(1) tablesOne LALR problem + conflict check
5S-vs-L SDD + Symbol Table + Activation RecordsWrite 3 short notes from memory
6TAC + Quadruples + DAG + Peephole3 expression→Quadruple conversions; 1 DAG
7Mock test + 2-mark blitz + weak area reviewTimed 2-hour mock; review all errors

The 72-Hour Cram Plan

BlockHoursTopics
Block 16 hrsPhases diagram (1 hr), FIRST/FOLLOW + LL(1) (2 hrs), LR(0) items + SLR(1) (3 hrs)
Block 26 hrsS-vs-L SDD + Symbol Table (2 hrs), Quadruples/Triples + DAG (2 hrs), Peephole + Optimization (2 hrs)
Block 36 hrsRe-do SLR table (2 hrs), Re-do LL(1) table (1 hr), 2-mark PYQ blitz (2 hrs), Module 5 overview (1 hr)

10 Common Exam Mistakes That Cost Marks

Exam Day Quick Reference (Cheat Sheet)

Final Exam Strategy

Order of Execution in Exam:

  1. 14-mark numerical first (LR/SLR/LALR table or Reaching Definitions) — mechanical, highest weight, partial marks assured even if incomplete
  2. 7-mark numerical questions (FIRST/FOLLOW, Quadruples, DAG) — quick construction, diagram-heavy
  3. 7-mark theory questions (short notes, compare/contrast) — write templates from memorized structure
  4. 2-mark objectives last — answer concisely, polish wording

Time Allocation (3-hour exam):

Question TypeCountTime per QuestionTotal Time
2-mark objectives8–103 min24–30 min
7-mark theory/numerical3–412–15 min36–60 min
14-mark numerical125–28 min25–28 min
Buffer / review30 min

Minimum Score Targets by Module:

ModuleTargetStrategy
M114/14Diagrams + 2-mark definitions
M218/25Master parsing tables (14 marks)
M315/20Memorize S-vs-L table + short notes
M415/22Practice Quadruple + DAG numericals
M52/7Brief overview of vtables
Total64/88 (73%)Guaranteed A-grade

Diagrams are non-negotiable. For any 7-mark question asking to explain or compare, start with the diagram. Examiners award 2-3 marks for the diagram alone.

Learn the Dragon Book example. The position = initial + rate * 60 trace is universally recognized for the 6 phases question.

Show your work in numericals. Do not jump to the final parsing table. Examiners award partial marks for FIRST/FOLLOW sets, LR(0) items, and intermediate iteration tables in data flow analysis.

The Complete Compiler Design Exam Preparation Kit | Compiler Design (CD) | Coursify