Consider the following grammar:S → Aa | bAc | dc | bdaA → eWhich of t...
There is no conflict in any of the state so it SLR, LALR(1), CLR(1).
For LL(1)
First(S) = First (AA) ∩ First (bAC) ∩ First (dC) ∩ First (bda)
= {e} ∩ {b} ∩ {d} ∩ {b} ∩ Φ
Not LL(1).
View all questions of this test
Consider the following grammar:S → Aa | bAc | dc | bdaA → eWhich of t...
SLR(1) and CLR(1)
To determine if the given grammar is SLR(1) and CLR(1), let's analyze the grammar based on the properties of these parsing techniques.
SLR(1)
SLR(1) parsing requires that the grammar be unambiguous and have no shift-reduce or reduce-reduce conflicts. It also requires that for each state in the parsing table, there should be at most one action for each terminal symbol and at most one goto action for each non-terminal symbol.
Let's construct the SLR(1) parsing table for the given grammar:
Grammar:
S → Aa | bAc | dc | b
A → e
First and Follow Sets:
First(S) = {b, d}
First(A) = {e}
Follow(S) = {$, a}
Follow(A) = {a}
Canonical LR(0) Items:
S' → .S
S → .Aa
S → .bAc
S → .dc
S → .b
A → .e
LR(0) Closure:
Closure({S' → .S}) = {S' → .S}
Closure({S → .Aa}) = {S → .Aa, A → .e}
Closure({S → .bAc}) = {S → .bAc}
Closure({S → .dc}) = {S → .dc}
Closure({S → .b}) = {S → .b}
Closure({A → .e}) = {A → .e}
LR(0) Transitions:
Closure({S' → .S})
- On 'S': Go to {S' → S.}
Closure({S → .Aa, A → .e})
- On 'a': Go to {S → A.a, A → .e}
Closure({S → .bAc})
- On 'b': Go to {S → b.Ac}
Closure({S → .dc})
- On 'd': Go to {S → d.c}
Closure({S → .b})
- On 'b': Go to {S → b.}
Closure({A → .e})
- No transitions
SLR(1) Parsing Table:
State | a | b | c | d | $ |
------|---|---|---|---|---|
0 | | s1| | s3| |
1 | | | | | acc |
2 | | r5| s4| | r5|
3 | | | | | r4|
4 | | | | | r3|
s -> shift
r -> reduce
acc -> accept
SLR(1) Analysis:
- There are no shift-reduce or reduce-reduce conflicts in the parsing table.
- The table has at most one action for each terminal symbol and at most one goto action for each non-terminal symbol.
Therefore, the given grammar is SLR(1).
CLR(1)
CLR(1) parsing requires that the grammar be unambiguous and have no shift-reduce or reduce-reduce conflicts. It also requires that for each state in the parsing table