compipler questions
compipler questions
Enrolment No:
S. No. Marks CO
Q1 How a parser generator can be used to facilitate the construction of the front end compiler. 4 CO1
Q2 Define the term reduction, handle and right sentential form. Explain with a suitable
4 CO2
example.
Q3 Find the reduced grammar equivalent to the following CFG:-
S AC / SB
A BaSC / a 4 CO2
B aSB / bbC
C Bc /ad
Q4 Discuss the peephole optimization? 4 CO4
Q5 What is a directed acyclic graph? Discuss the steps for constructing DAG. 4 CO5
SECTION B
Q6 Write Syntax Directed translation rules such that along with the parsing, the infix expression
will be converted into postfix form for the following grammar.
EE+T
ET
T T*F 10 CO3
TF
F (E)
F id
Illustrate the rules with a suitable example.
Q7 Convert the following pseudo code into 3-Address code.
Q 10 Construct SLR parsing table for the following grammar and identify the problem
which may encounter while parsing a string. Resolve the problem encountered by
constructing the CLR parsing table. Parse id=id*id + id*id with LALR parsing table
constructed for the same grammar prescribed below. CO2/C
20
O3
G → E = E | id
E→E+T|T
T → T * id | id
Q11 Construct the basic blocks, draw the flow graph and identify the loop invariant
statements for the following pseudo code.
x =1
i= 1
y =1
while( i <= n){
x= x + A[i]
y=2
i=i+1 20 CO5
}
Or,
Q9 Create a cross compiler for EQN using following compilers (i) C compiler, written in
PDP-11, producing code in PDP-11 (ii) An EQN language compiler producing code for text
formatter, TROFF and written in C. Show your steps using T-diagram.
Or,
Consider the following grammar: - CO1/C
10
A AcB | cC | C O2
B bB | id
C CaB | BbB | B
Construct the first and follow sets for the grammar. Also design a LL(1) parsing table for the
grammar.
SECTION C
(All questions are compulsory)
Q 10 Construct LALR(1) for the following grammar.
S B
B begin DA end
D Dd; / 𝜖
20 CO2
AA,E/𝜖
EB/S
Check the validity of the string “ begin d ; end”.
Q 11 Perform different code optimizations for the following code by first constructing Basic Blocks
and flow graph
(1) PROD := 0
(2) I: = 1
(3) T1:= 4*I
(4) T2 := addr(A) - 4
(5) T3 := T2[T1]
(6) T4:= addr(B) - 4
(7) T5:= T4[T1]
(8) T6:= T3*T5 CO5/C
(9) PROD:= PROD+T6 O1/C0
20
(10) I:= I+1 2/CO3
(11) If I ≤ 20 goto (3) /CO4
Or,
a) DAG
b) Handle Pruning
c) Trailing
d) L-Attributed SDD