1

I want to solve this Grammar.
S->SS+
S->SS*
S->a

I want to construct SLR sets of items and parsing table with action and goto. Can this grammar parse without eliminate left recursion. Is this Grammar SLR.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73

2 Answers2

3
  1. No, this grammar is not SLR. It is ambiguous.

  2. Left recursion is not a problem for LR parsers. Left recursion elimination is only necessary for LL parsers.

rici
  • 234,347
  • 28
  • 237
  • 341
  • How can say that this grammar is SLR? Is there any way to find out? – Himanshu Saini May 04 '15 at 19:56
  • @himanshusaini: construct the slr tables and observe that there are no conflicts. – rici May 04 '15 at 21:17
  • yes,there is conflict in parsing table. So this is no SLR Grammar? Is there any way to find the grammar is SLR or not without making parsing tree. – Himanshu Saini May 24 '15 at 03:58
  • 1
    @HimanshuSaini: Effectively, all algorithms to figure out whether a grammar is SLR are equivalent to "construct the SLR tables". – rici May 24 '15 at 04:21
1

I am not entirely sure about this, but I think this grammar is actually SLR(1). I constructed by hand the SLR(1) table and I obtained one with no conflicts (having added a 0-transition from S' (new start symbol) -> S).

Can somebody provide a sentence that can be derived in two different ways from this grammar? I was able to get a parser for it in Bison without any warning. Are you sure it is ambiguous?

Ryckes
  • 34
  • 6