For homework, I was given the following grammar:
S: D
D: AbBb | BaAb
A: ε
B: ε
I computed it using LL(1) just fine. The first sets were:
S: a, b
D: a,b
A: ε
B: ε
The follow sets were:
S: $
D: $
A: b
B: a,b
When I made my parsing table, the example string "ab" parsed just fine. However, when I tried to parse the same exact grammar using LR(1), I ran into errors.
For item set 0 I got the following: (the , separates the look ahead terminals)
Item set 0:
S: .D, $
D: .AbBb, $
D: .BaAb, $
A: ., b
B: ., a,b
If you make the table, you will clearly see that there is a reduce-reduce conflict between A and B in item set 0. If I'm asked to parse the string "ab", the parser won't know whether to reduce my empty to A or to reduce it to B. What am I doing wrong? I was always told that LR(1) can actually parse more grammars than LL(1), so what is the deal here? I would appreciate if somebody could help me out because it's driving me nuts. Thanks