You are on page 1of 3

Bangladesh University of Business & Technology (BUBT)

Department of Computer Science and Engineering


Mid-Term Examination: Summer 2021
Course Code: CSE 323 │Course Title: Compiler Design
Intake: 43, Shift: Day

Time: 2 hrs. Marks – 30


[Answer all the questions]

Outcome SLN Questions Marks


CO1 1. (a) Explain how a compiler converts the following high-level 6
language statement into a statement of low level language:
z = (n/a) * (r+a) / (p – q)
[Here, replace r with the last digit of your ID and replace p with the
first letter of your name (in lowercase letter).]
CO1 (b) Consider the following block of code: 4

int n=10, i, @sum = 0;


printf("Sum is:);
//calculation is done here
fro (i = 1; i <= n; I++) {
sum += i
)
.................

There are some errors in the given block of code. Which of the
errors will be found by the lexical analyzer and which will not?
Correct only the lexical errors. Then convert the corrected block of
code into stream of tokens.

Page | 1
CO1 2. (a) Consider the following context free grammars (CFG): 5
i. ii.
B→ dBb | bBd | dCb E→FG
C→aC | Ɛ F→ fgFg | fgGg | f
G→ g

Do left factoring of the above grammars (if necessary).


Why is it needed to do left factoring of a grammar? Explain with
proper example.

CO1 (b) Write down the regular expression and draw the transition 5

diagram of how a lexical analyzer will detect all the positive or


negative floating point numbers (eg. 1.5, .45, 2. , – 98. , – 6.71,– .39
etc.).
CO2 3. (a) Consider the following grammar:
4
S→ 1PQ | P1Q
P→0P | Ɛ
Q→ 0Q | 1Q | Ɛ
Show the simulation of Recursive Descent Parsing using the above
grammar for the input string: 0110

CO2 (b) Identify if the following grammar is LL(1) or not. 6

X→ Xcd | Yb | Zc
Y→b
Z→a| Ɛ
Show the simulation of Table-Driven Predictive Parsing using the
above grammar for the input string “bbcd”, if possible.
[Here, replace c in every case with the first letter of your name (in

Page | 2
lowercase character)]

Page | 3

You might also like