Search code examples
algorithmparsingcompiler-constructiongrammar

Bottom - Up SLR(1) Conflict / Reduce when both applies


If I have a situation where a state in the DFA have shift/reduce conflict, where both shift and reduce applies, let the next symbol be "t" and we have the following rules

X -> F.

Y -> F.tG

and t belongs the follow of X What should I do in this case? I know by definition that's not an SLR(1) Grammar but according to the algorithm shown https://i.sstatic.net/HNzKP.jpg, what should the algorithm do? Should it report an Error?

The algorithm says we report an error if neither (shift or reduce) applies, but what happens if both apply?


Solution

  • You should have detected this error when you attempted to construct the parser. The SLR parser generation algorithm must fail if there is a conflict.