CD Questions (Unit-3)
CD Questions (Unit-3)
11. Construct the LL(1) parsing table for the following grammar:
S → aABb
A→c|ϵ
B→d|ϵ
Parse the input string using parsing table: acd (6 Marks)
12. Check whether the following grammar is LL(1) or not. (6 Marks)
S → iEtSeS | iEtS | a
E→b
13. Construct LL(1) parsing table for the following grammar: (6 Marks)
S → iCtSeS | iCtS |a
C→b
14. For the following grammar, find FIRST and FOLLOW sets for each non-terminal.
Also construct predictive parsing table. (6 Marks)
S → aAB | bA | ε
A → aAb | ε
B → bB | ε
15. Construct the predictive parser for the following grammar: (6 Marks)
S → (L) | a
L → L,S | S
16. Check whether the following grammar is LL(1) or not. (6 Marks)
S → 1AB | ε
A → 1AC | 0C
B → 0S
C→1
17. Construct LL(1) parsing table for the following grammar: (6 Marks)
E→E+T|E
T→T*F|F
F → (E) | id
18. Consider the grammar
E → TE’
E’ → +TE’ | ε
T → FT’
T’ → *FT’ | ε
F → (E) | id
a. Find the FIRST and FOLLOW functions for the above grammar.
b. Construct the predictive parsing table.
c. Parse the following string using parsing table: id+id*id. (6 Marks)
19. Construct LL(1) parsing table for the following grammar. Also show moves
made by input string: abba (6 Marks)
S → aBa
B → bB | ε
20. Construct LL(1) parsing table for the following grammar: (6 Marks)
E → TA
T → +TA | ε
T → VB
B → *VB | ε
V → (E) | id
21. Check whether the following grammar is LL(1) or not. (6 Marks)
S → aB | ε
B → bC | ε
C → cS | ε
22. Define: Handle, Handle pruning, Viable prefix (3 Marks)
23. Explain conflicts in shift-reduce parsing. (3 Marks)
24. What is operator grammar? Give an example. (3 Marks)
25. Define operator grammar. Explain steps to create precedence functions from
operator precedence table by taking an appropriate example. (6 Marks)
26. Write operator-precedence parsing algorithm. (3 Marks)
27. Construct operator precedence parser for the following grammar: (6 Marks)
E → EAE | (E) | -E | id
A→+|-|*|/|↑
28. Consider the following grammar:
S → (L) | a
L → L,S | S
Construct operator precedence parser and parse the string (a, (a, a)). (6 Marks)
29. Differentiate SLR, CLR and LALR parsers. (3 Marks)
30. Enlist the steps to construct the SLR parser. Consider the following grammar:
S → AA
A → aA | b
Construct the SLR parsing table for the grammar. Parse the input string: aabb
(6 Marks)
31. Construct the SLR parsing table for the following table: (6 Marks)
S → cA | ccB
A → cA | a
B → ccB b
32. Consider the following grammar:
E→E+T|E
T→TF|F
F → F *| a | b
Construct the SLR parsing table for this grammar. Also parse the input string
a*b+a. (6 Marks)
33. Check whether the following grammar is SLR(1) or not. Explain your answer
with reason. (6 Marks)
S→L=R
S→R
L→*R
L → id
R→L
34. Generate the SLR parsing table for the following grammar: (6 Marks)
S → Aa | bAc | bBa
A→d
B→d
35. Show that the following grammar is not a SLR(1) grammar: (6 Marks)
S → AaBa | BbBa
A→ε
B→ε
36. Construct the SLR parsing table for the following grammar: (6 Marks)
E→E+T|E
T→T*F|F
F → (E) | id
37. Consider the following grammar:
S → AA
A → aA | b
Construct the CLR parsing table for the grammar. Parse the input string: aabb
(6 Marks)
38. Construct the CLR parsing table for the following grammar: (6 Marks)
S → CC
C → aC
C→d
39. Construct the CLR parsing table for the following grammar. Also, parse the
input string ‘abac’ using generated table. (6 Marks)
S → aSA | ε
A → bS | c
40. Consider the following grammar:
S → AA
A → aA | b
Construct the LALR parsing table for the grammar. Parse the input string: aabb
(6 Marks)
41. Construct LALR parsing table for the following grammar. (6 Marks)
S → Aa
S → bAc
S → dc
S → bda
A→d
Prepared by – Mr. Viral H. Panchal 4
Compiler Design Question Bank
42. Show that the following grammar is LR(1) but not LALR(1). (6 Marks)
S → Aa | bAc | Bc | bBa
A→d
B→d
43. Construct LALR parser for the following grammar. (6 Marks)
S→L=R
S→R
L→*R
L → id
R→L
44. Explain error recovery for ambiguous grammar in SLR parsing with an
example. (6 Marks)