0% found this document useful (0 votes)
17 views

CD Questions (Unit-3)

o

Uploaded by

testmg875
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

CD Questions (Unit-3)

o

Uploaded by

testmg875
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Compiler Design Question Bank

Unit – 3 Syntax Analysis


1. What is the role of parser? Explain different error recovery strategies that a
parser uses to recover from a syntactic error. (6 Marks)
2. Define CFG. Construct CFG for the following languages: (6 Marks)
a. L = {anbn: n ≥ 1}.
b. L = {wcwR: w ϵ {a, b}*}.
3. Let G be the grammar
S→0B|1A
A→0|0S|1AA
B→1|1S|0BB
For the string 00110101, find (a) left-most derivation (b) right-most derivation
(c) derivation tree. (3 Marks)
4. Generate leftmost derivation, rightmost derivation, and parse tree for the string
aa+a* from the given grammar. Check whether this grammar is ambiguous or
not. (3 Marks)
S→SS+|SS*|a
5. Check whether the following grammar is ambiguous or not. (3 Marks)
S → iCtS
S → iCtSeS
S→a
S→b
6. Explain the following terms with suitable example: (6 Marks)
a. Left recursion
b. Left factoring
7. Remove left-recursion from the following grammar: (3 Marks)
A → Abd | Aa | a
B → Be | b
8. Consider the following grammar for arithmetic expressions.
E→E+T|T
T→T*F|F
F → (E) | id
Remove the left recursion. (3 Marks)
9. Perform left factoring on the following grammar: (3 Marks)
S → iEtSeS | iEtS | a
E→b
10. Perform left factoring on the following grammar: (3 Marks)
A → aAB | aA | a
B → bB | b

Prepared by – Mr. Viral H. Panchal 1


Compiler Design Question Bank

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 | ε

Prepared by – Mr. Viral H. Panchal 2


Compiler Design Question Bank

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)

Prepared by – Mr. Viral H. Panchal 3


Compiler Design Question Bank

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)

Prepared by – Mr. Viral H. Panchal 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy