-1

So I have this grammar I'm trying to build an LR(1) table for

      E' -> E
      E -> E + E
      E -> E * E
      E -> ( E )
      E -> a

So far, this my table

enter image description here

I'm trying to solve the conflicts here. I thought about changing the grammar to postfix instead of infix but I'm not really sure if I can do that. Any ideas?

Ruba Sbeih
  • 27
  • 1
  • 6
  • 2
    If you're trying to resolve the conflicts using precedence, you should use the precedence resolution algorithm. It's described in the Dragon Book (see Parsing Ambiguous Grammars), in the [Bison manual](https://www.gnu.org/software/bison/manual/bison.html#Precedence), and in any number of SO answers, such as [this one](https://stackoverflow.com/a/26785562/1566221). If after reading the material, you have a specific question about this simple algorithm, feel free to ask it. – rici May 08 '20 at 14:32

1 Answers1

0

Here is your grammar, with precedence:

E' -> E
E -> E + T
E -> T
T -> T * F
T -> F
F -> ( E )
F -> a

Don't forget the extra E -> T, and T -> F, as without it the grammar will be useless.

Note: This will not work with LR(0), because you'll get a conflict.

xilpex
  • 3,097
  • 2
  • 14
  • 45