0
這是錯誤:關於12移進/歸約涉及EXP衝突ML-Yacc的錯誤 - > EXP BINOP EXP
12 shift/reduce conflicts
error: state 34: shift/reduce conflict (shift OR, reduce by rule 11)
error: state 34: shift/reduce conflict (shift AND, reduce by rule 11)
error: state 34: shift/reduce conflict (shift GE, reduce by rule 11)
error: state 34: shift/reduce conflict (shift GT, reduce by rule 11)
error: state 34: shift/reduce conflict (shift LE, reduce by rule 11)
error: state 34: shift/reduce conflict (shift LT, reduce by rule 11)
error: state 34: shift/reduce conflict (shift NEQ, reduce by rule 11)
error: state 34: shift/reduce conflict (shift EQ, reduce by rule 11)
error: state 34: shift/reduce conflict (shift DIVIDE, reduce by rule 11)
error: state 34: shift/reduce conflict (shift TIMES, reduce by rule 11)
error: state 34: shift/reduce conflict (shift MINUS, reduce by rule 11)
error: state 34: shift/reduce conflict (shift PLUS, reduce by rule 11)
這是語法:
program : exp ()
exp:
exp binop exp ()
| ID ()
| lvalue ()
| STRING ()
| INT ()
| NIL ()
| LPAREN expseq RPAREN ()
| lvalue ASSIGN exp ()
| ID LPAREN explist RPAREN ()
| LET declist IN expseq END()
| IF exp THEN exp ELSE exp ()
| IF exp THEN exp ()
binop:
EQ ()
| NEQ ()
| LT ()
| GT ()
| LE ()
| GE ()
| AND ()
| OR ()
| PLUS ()
| MINUS ()
| TIMES ()
| DIVIDE ()
如何解決這個問題?我是否需要重新思考語法並找到另一種描述這種語法的方法?
我曾嘗試也宣告優先順序(雖然我使用這些真最小的經驗)如:
%nonassoc OR NEQ EQ LT LE GT GE AND
%right PLUS MINUS
%right TIMES DIVIDE
,但沒有。