0% found this document useful (0 votes)
59 views2 pages

CSE 331 Semester Final Question For Section-MC-FG

This document provides instructions for a term assessment exam for the Compiler Design course at Daffodil International University. It includes instructions for the exam such as the date, time, duration, and marks allocated. It then lists 4 questions for the exam. Question 1 has two parts, part (a) asks to analyze a three address code (TAC) including identifying leader instructions and basic blocks. Part (b) asks to perform leftmost derivation on a context free grammar. Question 2 has two parts, part (a) asks to represent an expression in three address code, quadruples, and indirect triples format. Part (b) asks to draw the syntax tree and directed acyclic graph for an expression. Question 3 has

Uploaded by

Papon Sarker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views2 pages

CSE 331 Semester Final Question For Section-MC-FG

This document provides instructions for a term assessment exam for the Compiler Design course at Daffodil International University. It includes instructions for the exam such as the date, time, duration, and marks allocated. It then lists 4 questions for the exam. Question 1 has two parts, part (a) asks to analyze a three address code (TAC) including identifying leader instructions and basic blocks. Part (b) asks to perform leftmost derivation on a context free grammar. Question 2 has two parts, part (a) asks to represent an expression in three address code, quadruples, and indirect triples format. Part (b) asks to draw the syntax tree and directed acyclic graph for an expression. Question 3 has

Uploaded by

Papon Sarker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Daffodil International University

Department of Computer Science and Engineering


Faculty of Science & Information Technology
Term Assessment, Spring 2021 @ DIU Blended Learning Center
Course Code: CSE 331 (Day), Course Title: Compiler Design
Level: 3 Term: 3 Section: F & G
Date: Sunday 18 April, 2021 Time: 09:00 AM - 01:00 PM
Four hours (4:00) to support online open/case study-based assessment Marks: 40
Life will give you many options, but today you have to “Answer all the questions”
Q1. (a) Considering the following three address code (TAC) and answer the following
questions.
1. i = m-1 18. goto (27) 35. goto (24)
2. j=n 19. t9 = a[t8] 36. t19 = a[t18]
3. t1 = 4 * n 20. a[t7] = t9 37. a[t17] = t19
4. goto (2) 21. t10 = 4 * j 38. t20 = 4 * j
5. v= a[t1] 22. a[t10] = x 39. t11 = 4 * n goto (35)
6. i = i+1 23. goto (2) 40. goto (12)
7. t2 = 4 * i 24. t11 = 4 * i 41. v= a[t21]
8. t3 = a [t2] 25. x = a[t11] 42. i = i+1
9. If t3<v goto (7) 26. t12 = 4 * i 43. t22 = 4 * i
10. goto (13) 27. goto (2) 44. t23 = a [t2]
11. t4 = 4 * j 28. t12 = 4 * i 45. If t23<v goto (2)
12. t5 = a[t4] 29. a[t12] = t14 goto (19) 46. goto (24)
13. if t5>v goto (9) 30. t15 = 4 * n 47. t24 = 4 * j
14. if i>=j goto (36) 31. a[t15] = x 48. t25 = a[t24]
15. t6 =4 * i 32. t16 =4 * i 49. if t25>v goto (9)
16. x = a[t6] 33. x = a[t16] 50. if i>=j goto (39)
17. t7 = 4 * i 34. t17 = 4 * i
Three address code for Q1 [8]
I. Which lines of the above code are leader instructions by leader selection rule-
2 and rule-3? Explain briefly.
II. Is there any instruction line which has been selected as leader more than once?
Explain briefly.
III. Determine and draw the basic blocks of the above code.
IV. Draw the flow graph using the basic blocks and dependencies among the
blocks.
(b) Consider the following CFG and perform LMD for “abaabbabababaa”. [2]
S → A B A | aaBA
A → aBa | bA
B → bBB | ba
Q2. (a) Consider the following expressions. [6]
((a + b) – ((a + b) * (a - b))) + ((t + q) * (t -q))
For the given expressions stated produce
I. Three Address Code (TAC),
II. Quadruples and
III. Indirect Triples data structure. Consider “71” as the starting statement
number for indirect triples.
(b) Create an expression using the following description. [4]
X = - (b * c + (b * c - SCode) / CCode * ID)
Where, ID = last two digits of your Student ID
CCode = Last two digit of the Compiler Design Course Code
SCode = Last two digit of the Software Engineering Course Code
Draw the Syntax Tree & Directed Acyclic Graph (DAG) for the above expression.
Q3. (a) Consider the following CFG and answer the following questions. [6]
T → SS
E → (E) | F
S→ xS | y
I. Produce LR(0) diagram and
II. Find the kernel and non-kernel items from the LR(0) diagram
III. Produce Canonical Table from the following grammar.
(b) Consider the following grammars and answer the following questions. [4]
(i) S → Ab | C (ii) S→ (L) | x
A → CaX L→ L,T | S
C→c T→ TTym | r| ɛ
X→x
A. Which of the above-mentioned grammar is left recursive? Explain briefly.
B. If you find a left recursive grammar, convert it into a right recursive grammar.
Q4. (a) Draw the following Table in your answer booklet and Find the FIRST () and [5]
FOLLOW () functions from the following productions.
Productions FIRST () FOLLOW ()
S → (L) | Eb | a
L → cL' | (L) L' | EbL' | aL'
L' → , SL' | ε
E → [E] E' | cL' c E' | (L) L' c E' | aL'cE'
E' → dE' | b L' c E' | ε
(b) Construct a predictive parsing table from the grammar in Question 4(a) using LL [3]
(1) parser.
(c) Apply left factoring techniques to eliminate non-determinism from the following [3]
CFG.
P → rPPssP | rPPsPr | rPP | rP | sPs | r
E → id | ɛ

"It is during our darkest moments that we must focus to see the light." -Aristotle
Best of luck ☺

You might also like