Subject: - Compiler Design (TCS-502) _________________________________________________________________ ____ Q1.Consider the following grammar find out the predictive parsing table . (i) E→ E+T │ T (ii) S→ iEtS│ iEtSeS │a T→ T* F │ F E→ b F→ (E) │ id
(10)
Q2. Construct all possible parse trees corresponding to the string i+ j * k for the following grammar . also comment on the precedence of operator + and * used in the grammar E → E+E, E → E*E , E → id Q3. Discuss the operator precedence parsing algorithm . Consider the following operator grammar and precedence functions ; explain the parsing of input string id +id*id , Precedence Functions :-
f g Q4.
Q5.
+ 4 3
* 2 1
id 4 5
$ 0 0
Consider the following grammar construct the predictive parsing table. S→ (L) │ a L→ L, S │ S Consider the following grammar :E→ E+T │ T T→ T* F │ F F→ (E) │ id (i) Remove the left recursion (ii) Compute the FIRST and FOLLOW sets of non terminals of the resulting grammar . (iii) Show the resulting grammar is LL(1) (iv) Construct the LL(1) parsing table for the resulting grammar .
Q6.Discuss algorithms for computation of the sets of LR(1) items . Also show that the following grammar is LR(1) but not LALR(1) G:S→ Aa │ bAc │Bc│ bBa A→ d B→d Q7. Consider the following grammar E→ E+T │ T T→ T* F │ F
F→ F*│ a │ b (a) Construct the collection of LR (0) items for the above grammar. (b) Construct DFA transition diagram. (c) Construct the parsing table using SLR algorithm. Q8. State the problems associated with Top-Down parsing .State and eliminate the problem associated with the following grammar for Top-Down parsing E→ E+T │ T T→ T* F │ F F→ (E) │ id Q9. What do you understand by Lexical phase errors and Syntactic phase error . Also suggest the methods of error recovery . Q10. Discuss the following parameters parsing techniques with suitable example :(i) Call by value (ii) Call by reference (iii) Call by name Q11. Construct the LALR parsing table for the following grammar :S→ AA │ T A→ aA │b Q12. Consider the following operator precedence matrix and compute the precedence function :-
a ( ) ; $
a
(
<.
<.
<. <.
<. <.
) .> = .> .>
; .> <. .> .>
$ .> .>
Q13. Give the algorithm for construction of predictive parsing table . Consider the following grammar construct predictive parsing table :S→ iEtSM │ T M→ eS │E E→ b