How to remove ambiguity in grammar using CUP?

96 views Asked by At

I have this grammar

S-> Stat
Stat -> Exprs WRITE
Stat -> Vars READ
Vars -> ID COMMA Vars
Vars -> ID
Exprs -> Expr COMMA Exprs
Exprs -> Expr
Expr -> ID
Expr -> ...
...

(You can test it here http://jsmachines.sourceforge.net/machines/lalr1.html)

The grammar is ambiguous and it produces S/R conflicts, but the real problem comes out with input ID COMMA ID WRITE meanwhile with ID COMMA ID READ the parser works.

Is there a way to prevent this without change the grammar in CUP?

0

There are 0 answers