1

I have the following grammar:

S -> A
A -> B | B[*]
B -> [AB]
AB -> *,AB | epsilon

S,A,B,AB are variables and [ ] , * are terminals

Is it:

  1. LR(0)?
  2. LR(1)? and how can I prove it?
CS2000
  • 51
  • 4
  • Have you tried building the configurating sets? What did you find? – templatetypedef Jun 04 '22 at 18:29
  • The easy way to prove that it's LR(1) is, as @templatetypedef suggests, building a parser. The parser only has 12 states, so it shouldn't be too challenging. While you're doing that, you'll find the conflict which prevents it from being LR(0). – rici Jun 05 '22 at 03:37
  • @rici can you please explain what you mean by the conflict in LR(0)? – CS2000 Jun 06 '22 at 10:42
  • I'm talking about parser conflicts, in this case a shift/reduce conflict. Since an LR(0) parser cannot use lookahead to decide which action to take, a production like `N -> A | A b` leads to a conflict; after the `A` is recognised, the parser must decide whether to *reduce* using the first alternative or to *shift* using the second alternative. The reduce action decides that the `N` has been recognised; the shift action decides that `N` is not yet complete. An LR(1) parser could look at the next input symbol, which might or might not be an `a`, but an LR(0) parser cannot. – rici Jun 06 '22 at 16:51
  • If that explanation seems unfamiliar, I'd suggest you (return to) the textbook on parsing theory from which that problem was taken. – rici Jun 06 '22 at 16:51

0 Answers0