Compiler Design
CSE · Final · Spring 25
Batch 61
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, Spring - 2025
Course Code: CSE331, Course Title: Compiler Design
Level: 4 Term: 1 Batch: 6i
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) Apply left factoring technique in the following grammar.
domain -> web | website | webapp | diu.bd | edu.bd | diu.edu | edu.ac [3]
b) Consider the following grammar to produce LR (0) parser and Canonical Table from the following grammar.
A -> AxyB | XC
B -> cbxy | a
C -> cBC | y
D -> a | m [7]
2. a) State the rules of the FIRST () and FOLLOW () functions. [3]
b) Construct a predictive parsing table from the following grammar using LL (1) parser.
Productions | FIRST () | FOLLOW ()
Expense -> Tax Salary |
Salary -> Grocery Tax Salary | / |
Grocery -> + | - |
Tax -> Factor Benefit |
Benefit -> Cost Factor Benefit | / |
Cost -> * |
Factor -> (Expense) | num [7]
3. a) Consider the following expression:
x+x*(y-z)+(y-z)*p+q-x+z
Write the Three Address code, Quadruples, Indirect Triples and draw the DAG for the above expression. [6]
b) Describe the following Code Optimization techniques with proper example.
i. Copy Propagation
ii. Strength Reduction [4]
4. a) Consider the following Instructions and answer the following questions:
1. t1 = a + 5
2. j = b - 3
3. t1 = 2 * t
4. k = t1 + j
5. if i >= j goto (3)
6. v = c[t1]
7. i = i + 1
8. t2 = 3 * i
9. x = y + 4
10. t3 = x * 2
11. z = t3 - j
12. a[t12] = t14 goto (9)
13. q = d[t2]
14. j = j - 1
15. t4 = 5 * i
16. p = r + t4
17. w = e[j]
18. m = p * 3
19. w = e[j] goto (16)
20. a = t5 / 2
21. t5 = 6 * m
22. b = n + t6
23. t6 = t4 + 2
24. y = a + 3
25. j = j - 1 goto (22)
26. goto (6)
27. y = o[t9]
28. z = x - t6
29. n = t3 + t8
30. t8 = 8 * x
31.
32. t9 = 4 * y
33. goto (28)
34. t10 = 9 * z
35. l = m + t10
36. o = q[t8]
37. t8 = 8 * x
38. z = x - t6
39. t2 = 3 * i goto (31)
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]
b) Draw the flow graph for the above mentioned instructions. [4]