Compiler Design
CSE · Final · Summer 25
Paper 2 of 3Batch 64 · ChandSwitch
Batch 64
Paper 2 of 3
Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Daffodil International University
Faculty of Science & Information Technology
Department of Computer Science & Engineering
Final Examination, Summer 2025
Course Code: CSE313, Course Title: Compiler Design
Level: 3 Term: 1 Batch: 64
Time: 02:00 Hrs.
Marks: 40
Answer ALL Questions
[The figures in the right margin indicate the full marks and corresponding course outcomes. All portions of each question must be answered sequentially.]
1. a) Consider the following grammar to produce LR(0) parser and Canonical Table.
S -> N@D.T
N -> a | b
D -> Gm | m
G -> e | y | g
T -> c | d
[8] | CO2
b) int main() {
int x = 5, y = 10;
int p = x + y;
int q = x + y;
int z = p * 2;
int r = z;
int w = r + 1;
r = 20;
return w;
}
Explain the techniques of Code Optimization(s) that can be applied to the code and rewrite the code after applying these optimization(s) to improve its efficiency.
[2]
2. a) Develop FIRST and FOLLOW functions for the following production rules and determine the LL(1) Parsing Table:
S -> S+M | M
M -> M*R | R
R -> aSb | int
[8] | CO2
b) State the rules of the FIRST() and FOLLOW() functions.
[2]
3. a) Consider the following arithmetic expression:
(a + b) * (c - d) + e * f - (g + h) * i
Apply intermediate code generation techniques to evaluate the expression.
i. Apply your knowledge to write the Three Address Code (TAC) for the expression.
ii. Generate the corresponding Quadruples representation.
iii. Analyze the structure and produce the Indirect Triples representation where you have 27, 29, 31, 33, 67, and 91 available memory in STACK.
[6] | CO3
b) Consider the following arithmetic expression:
a + b * (c - d) - e + b * (c - d)
i. Construct the Syntax Tree
ii. Construct the DAG (Directed Acyclic Graph)
[4]
4.
1 | i = m-1 | 16 | t7 = 4 * i
2 | j = n | 17 | t8 = 4 * j
3 | t1 = 4 * n | 18 | t9 = a[t8]
4 | v = a[t1] | 19 | a[t7] = t9
5 | i = i+1 | 20 | t10 = 4 * j
6 | t2 = 4 * i | 21 | a[t10] = x
7 | t3 = a[t2] | 22 | goto (5)
8 | if t3 < v goto (5) | 23 | t11 = 4 * i
9 | j = j-1 | 24 | x = a[t11]
10 | t4 = 4 * j | 25 | t12 = 4 * i
11 | t5 = a[t4] | 26 | t13 = 4 * n
12 | if t5 > v goto (9) | 27 | t14 = a[t13]
13 | if i >= j goto (23) | 28 | a[t12] = t14
14 | t6 = 4 * i | 29 | t15 = 4 * n
15 | x = a[t6] | 30 | a[t15] = x
Answer the following questions from the above three address code:
a) i. Which lines in the code qualify as leaders by leader selection rule 2?
ii. Is / Are there any instruction(s) designated as leaders more than twice?
iii. What is the total number of basic blocks identified in the code?
[6] | CO3
b) Draw the flow graph for the above mentioned instructions.
[4]