Compiler Design and Construction (BSc CSIT, CSC365): the questions likely to come
29 analyzed questions from 7 past papers (2074-2081), grouped by syllabus unit — each with its probability, how often it's been asked, and where to study the answer.
Explain top-down parsing. Construct the predictive (LL(1)) parsing table for the grammar E -> E+T | T, T -> T*F | F, F -> (E) | id after removing left recursion.
Top-Down Parsing
Top-down parsing builds the parse tree from the root (start symbol) down to the leaves (terminals), attempting a leftmost derivation of the input. The two main approaches are:
- Recursive-descent parsing (may use backtracking).
- Predictive / LL(1) parsing — a non-backtracking, table-driven method that uses one symbol of look-ahead. It requires the grammar to be free of left recursion and to be left-factored.
Step 1: Remove Left Recursion
Given grammar:
After eliminating left recursion:
Step 2: FIRST and FOLLOW Sets
| Non-terminal | FIRST | FOLLOW |
|---|---|---|
| { (, id } | { ), $ } | |
| { +, } | { ), $ } | |
| { (, id } | { +, ), $ } | |
| { *, } | { +, ), $ } | |
| { (, id } | { +, *, ), $ } |
Step 3: LL(1) Predictive Parsing Table
Entry M[A, a] holds the production used when non-terminal is on the stack and is the look-ahead.
| id | + | * | ( | ) | $ | |
|---|---|---|---|---|---|---|
| E | ||||||
| E' | ||||||
| T | ||||||
| T' | ||||||
| F |
Blank cells denote error entries. Since no cell has more than one production, the grammar is LL(1) and can be parsed top-down without backtracking.
Syntax Analysis (Parsing)
Explain top-down parsing. Construct the predictive (LL(1)) parsing table for the grammar E -> E+T | T, T -> T*F | F, F -> (E) | id after removing left recursion.
Explain the general structure of an LR parser. Construct the LR(0) item sets for the grammar S -> AA, A -> aA | b.
Construct the LR(1) parsing table for the grammar S -> CC, C -> cC | d and parse the input string cdd.
Eliminate left recursion and perform left factoring on the grammar A -> Aab | Ac | bd | f.
What is an ambiguous grammar? Show with an example.
Differentiate between LL(1) and LR parsers.
Explain the handle and handle pruning in shift-reduce parsing.
What is operator precedence parsing?
Differentiate between top-down and bottom-up parsing.
Differentiate between a parse tree and a syntax tree.
Sit a probable paper
A full mock exam built from the most likely questions, mirroring the real paper's structure. Every slot is a real past question.
Most Probable Paper
Mirrors the real structure · 60 marks · based on 7 past papers
- 1.[10 marks]
Explain the different phases of a compiler with a suitable diagram, showing the output of each phase for the statement
position = initial + rate * 60.This question has recurred in 3 of 7 years; so far only in internal assessments, not the board; and its topic (Introduction) appears in 100% of years.
- 2.[10 marks]
Explain top-down parsing. Construct the predictive (LL(1)) parsing table for the grammar E -> E+T | T, T -> T*F | F, F -> (E) | id after removing left recursion.
This question has recurred in 2 of 7 years; so far only in internal assessments, not the board; and its topic (Syntax Analysis (Parsing)) appears in 100% of years.
- 3.[10 marks]
Explain the general structure of an LR parser. Construct the LR(0) item sets for the grammar S -> AA, A -> aA | b.
This question has recurred in 2 of 7 years; so far only in internal assessments, not the board; and its topic (Syntax Analysis (Parsing)) appears in 100% of years.
- 1.[5 marks]
Eliminate left recursion and perform left factoring on the grammar A -> Aab | Ac | bd | f.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Syntax Analysis (Parsing)) appears in 100% of years.
- 2.[5 marks]
What is an ambiguous grammar? Show with an example.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Syntax Analysis (Parsing)) appears in 100% of years.
- 3.[5 marks]
Differentiate between LL(1) and LR parsers.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Syntax Analysis (Parsing)) appears in 100% of years.
- 4.[5 marks]
Explain the handle and handle pruning in shift-reduce parsing.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Syntax Analysis (Parsing)) appears in 100% of years.
- 5.[5 marks]
Differentiate between a compiler and an interpreter.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Introduction) appears in 100% of years.
- 6.[5 marks]
What is a symbol table? Explain its role in a compiler.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Introduction) appears in 100% of years.
- 7.[5 marks]
Explain the role of the lexical analyzer in a compiler.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Lexical Analysis) appears in 100% of years.
- 8.[5 marks]
What are regular expressions? Write a regular expression for identifiers.
This question has recurred in 4 of 7 years; so far only in internal assessments, not the board; and its topic (Lexical Analysis) appears in 100% of years.
- 9.[5 marks]
What is operator precedence parsing?
This question has recurred in 3 of 7 years; so far only in internal assessments, not the board; and its topic (Syntax Analysis (Parsing)) appears in 100% of years.
Behind the numbers
The raw evidence the predictions are computed from: marks per unit per year, syllabus weights, trends, and coverage.
Show the heatmap, topic table and coverage analysis
The receipt: marks per unit, per year
Each row is a syllabus unit, each column an exam year, each cell the marks that unit earned that year. Click any cell to see the actual questions behind it.
| # | Syllabus unit | Probability | Appeared | Avg marks | Syllabus weight | Exam vs syllabus | Trend | Questions |
|---|---|---|---|---|---|---|---|---|
| 1 | U3Syntax Analysis (Parsing) | Very likely100% | 25.7 | 31%14 lecture hrs | Balancedexam 34% · syllabus 31% | Fading | 10 recurring10 total | |
| 2 | U1Introduction | Very likely100% | 12.1 | 9%4 lecture hrs | Over-examinedexam 16% · syllabus 9% | Steady | 4 recurring4 total | |
| 3 | U2Lexical Analysis | Very likely100% | 10.7 | 18%8 lecture hrs | Balancedexam 14% · syllabus 18% | Steady | 4 recurring4 total | |
| 4 | U4Syntax-Directed Translation | Likely71% | 13 | 13%6 lecture hrs | Balancedexam 12% · syllabus 13% | Steady | 4 recurring4 total | |
| 5 | U6Code Optimization | Likely57% | 12.5 | 9%4 lecture hrs | Balancedexam 10% · syllabus 9% | Steady | 3 recurring3 total | |
| 6 | U5Intermediate Code Generation | Likely71% | 7 | 13%6 lecture hrs | Under-examinedexam 7% · syllabus 13% | Steady | 2 recurring2 total | |
| 7 | U7Code Generation | Likely71% | 7 | 7%3 lecture hrs | Balancedexam 7% · syllabus 7% | Steady | 2 recurring2 total |
Study smart, not hard
Drag the slider: studying the top 5 units in priority order covers ~87% of all observed marks.
- ~80% line
Lecture time vs exam marks
Where the exam pays more than the curriculum spends: ● lectures vs ● exam marks, as a share of the whole course. A long teal-leading bar = high-yield unit.