0

I'm trying to solve question on LR(1) grammar :

S->AA 
A->Aa
A-> b

I got stuck in state 4 when :

S-> AA. ,$
A-> A.a ,$
A->.Aa ,$
A->.a ,$

a and A shifted to other state and A is reduced in the same state should I consider this grammar is not LR(1) and SLR(1) because of this conflict ?

user207421
  • 305,947
  • 44
  • 307
  • 483
M.Alamer
  • 55
  • 8
  • No. The reduce is only possible with `$` as a lookahead, and there is no such thing as a shift/shift conflict, because shift is just shift. – rici Mar 11 '15 at 01:31
  • @rici No means this gammar is LR(1)? , and is it ok to have shift and reduce in one state ? – M.Alamer Mar 11 '15 at 05:12
  • You can have shift and reduce or multiple reduce in one state as long as you can decide which action to take using the lookahead. I didn't look carefully at the whole grammar, but this state is not a problem. – rici Mar 11 '15 at 07:10
  • can any one provide more explanation ? – M.Alamer Mar 11 '15 at 22:58
  • How did you get into this state? I constructed the LR1 automata for this grammar and it doesn't have such a state. @EJP – Amin Nov 24 '17 at 13:58

1 Answers1

1

You need to check shift-reduce(SR) or reduce-reduce(RR) problem

In state 4 which yo have mentioned there is only one reduce entry S-> AA., $ therefore there is no RR problem. Check for SR :

Reduce entry for S-> AA.,$ will be at $ for LR(1) and at follow(S), which is $, for SLR(1).

Shift entries are only checked for terminals and not variables. Variables entry are made in GOTO part of the table while shift entries are made in ACTION part of table. Shift is only at terminal a in case of both SLR(1 ) and LR(1).

Therefore in state provided by you there is no problem (neither SR nor RR).

obmjo
  • 135
  • 10