Radha Govind Engineering College, Meerut

II Sessional Test (2006-2007) B.Tech V Semester (CS) Compiler Design (TCS 502)
Time: 1:00 hr. Note: Attempt any three questions. Q.1 Consider the following grammar G E-> EBE/(E)/num B-> + / - / * / \ (i) (ii) (iii) Explain why this grammar is not suitable for a recursive descent parser. Obtain a grammar G’ from G, which can be use for recursive descent parser. Find the FIRST(G’) and FOLLOW(G’). MM: 30

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-

f g

+ 4 3

* 2 1

id 4 5

$ 0 0

Q.4 Consider the following grammar G S-> ACB / CbB / Ba A-> da / BC B-> g / ε C-> h / ε (i) (ii) (iii) Find FIRST(G) and FOLLOW(G). Check G is LL(1) or not. Construct parsing table for predictive parser.

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. Note: Attempt any four questions. MM: 30

Q.1

(a) What is parsing? Explain the role of the parser in the compiler. (b) Write the short note on LEX.

Q.2 Prepare the SLR parsing table for the grammarE-> 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 S-> iTCeb /CTe/ TeCb C-> aCb/ ε T-> bCT/CT/ ε Q.4 Write the algorithm for Recursive Descent parser for the following grammarE -> 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 isf g + 4 3 * 2 1 id 4 5 $ 0 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. Q2: Translate the arithmetic expression a*-( b+c) into a) A syntax tree b) Postfix notation c) Three-address code OR Translate the expression -( a+b) * (c+d) +( a+b+c) into a) Quadruples b) Triples c) Indirect triples Q.3 Consider the following grammar G S-> ACB / CbB / Ba A-> da / BC B-> g / ε C-> h / ε (iv) (v) (vi) Find FIRST(G) and FOLLOW(G). Check G is LL(1) or not. Construct parsing table for predictive parser.

-----------------------------------------------------