I am currently having the following grammar which I am asked if it is SLR(1) or not. The grammar is:
E -> E + A + A | E - A + A | E + A - A | E - A - A | T .
T -> T + A | T - A | A .
A -> A * B | A / B | B .
B -> ( E ) | x .
The grammar is ambigius and with the help of the software of grammophone in github ( http://mdaines.github.io/grammophone/#/ just copy paste the grammar into the edit section) i am locating a conflict of shift/reduce in the line 2 of the board when +
and -
are coming. Now the next question is to fix the grammar so that it becomes SLR(1). How can I do that ?? I am searching the net and I cannot find the answer. Sorry for my bad english.
Edit:
The grammar was at first like
E->E+E+E|E-E-E|E+E-E|E-E+E
E->E+E|E-E|E*E|E/E
E->(E)|x
and the exercise tells you that *
and /
has equally priority but higher than +
and -
where +
and -
has equal priority. Given those you have to change the given grammar into another one which is SLR(1). All I could come up with was the very first one. The production comes from left to right and we cannot remove any rules.