0

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?

2
  • 1
    There's no way to fix it without changing the grammar. But there is a fix without changing the language. It's a bit annoying, though, and it needs more details about Expr Commented Sep 30, 2020 at 18:59
  • There's a sketch of how to do this sort of thing with an LALR(1) parser at the end of this answer. Commented Sep 30, 2020 at 19:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.