2nd Sess Comp
2nd Sess Comp
E-> EBE/(E)/num
B-> + / - / * / \
(i) Explain why this grammar is not suitable for a recursive descent parser.
(ii) Obtain a grammar G’ from G, which can be use for recursive descent
parser.
(iii) Find the FIRST(G’) and FOLLOW(G’).
Q.2 Discuss algorithm for computation of the sets of LR(0) or SLR items. Also compute
LR(0) items and draw transition diagram for the grammar G
E-> E+T/ T
T-> TF / F
F-> F* / a / b
Q.3 Discuss the operator precedence parsing algorithm. Parse the input string
id+id*id
for the grammar
T->T+T / T*T/ (T) / id
Where precedence function is-
+ * id $
f 4 2 4 0
g 3 1 5 0
Q.5 What is shift reduce parser. Parse the string id+id*id with the help of stack implementation of
shift reduce parser for the grammar given in Q. 3
RADHA GOVIND ENGINEERING COLLEGE, MEERUT
2ND Sessional Test (2005-06)
Subject: Compiler Construction (CS-604)
Class: B.Tech (CS) VI Sem
Time: 1:15 hr. MM: 30
Note: Attempt any four questions.
Q.1 (a) What is parsing? Explain the role of the parser in the compiler.
(b) Write the short note on LEX.
E-> E+T/ T
T-> TF / F
F-> F* / a / b
Q.3 Write the algorithms for calculating FIRST and FOLLOW of grammar and
find the first and follow for
Q.4 Write the algorithm for Recursive Descent parser for the following grammar-
E -> TE'
E'-> +TE'/ ε
T -> FT'
T'-> *FT'/ ε
F -> (E) / id
Q.5 What is LL(1) grammar? Write the procedure to check LL(1) and for
constructing LL(1) parsing table
Radha Govind Engineering College, Meerut
Second Sessional Test(2004-05)
B.Tech(CS) VI Sem
Subject: Compiler Construction Code: CS-604
Time: 1:15 hr. MM: 30
Note: Attempt All questions.
Q.1 Discuss the operator precedence-parsing algorithm. Parse the input string
id+id*id for the grammar
E->E+E / E*E/ (E) / id
Where precedence function is-
+ * id $
f 4 2 4 0
g 3 1 5 0
OR
What is left factoring? Why it is done? How we remove the left factor from a
grammar show with the help of an example and also explain left-recursion.
-----------------------------------------------------