减少班次冲突CUP

问题描述

我正在尝试在cup文件中定义语法,但出现以下错误

Warning : *** Shift/Reduce conflict found in state #4
  between fielddecls ::= (*) 
  and     type ::= (*) INT 
  under symbol INT
  Resolved in favor of shifting.

Warning : *** Shift/Reduce conflict found in state #4
  between fielddecls ::= (*) 
  and     type ::= (*) CHAR 
  under symbol CHAR
  Resolved in favor of shifting.

Warning : *** Shift/Reduce conflict found in state #4
  between fielddecls ::= (*) 
  and     type ::= (*) BOOL 
  under symbol BOOL
  Resolved in favor of shifting.

Warning : *** Shift/Reduce conflict found in state #4
  between fielddecls ::= (*) 
  and     type ::= (*) FLOAT 
  under symbol FLOAT
  Resolved in favor of shifting.

Warning : *** Shift/Reduce conflict found in state #8
  between fielddecls ::= (*) 
  and     type ::= (*) INT 
  under symbol INT
  Resolved in favor of shifting.

Warning : *** Shift/Reduce conflict found in state #8
  between fielddecls ::= (*) 
  and     type ::= (*) CHAR 
  under symbol CHAR
  Resolved in favor of shifting.

Warning : *** Shift/Reduce conflict found in state #8
  between fielddecls ::= (*) 
  and     type ::= (*) BOOL 
  under symbol BOOL
  Resolved in favor of shifting.

Warning : *** Shift/Reduce conflict found in state #8
  between fielddecls ::= (*) 
  and     type ::= (*) FLOAT 
  under symbol FLOAT
  Resolved in favor of shifting.

以下是我的cup文件中定义的语法。

program ::= CLASS ID:i CURLBRACKETBEGIN memberdecls:m CURLBRACKETEND
            {: RESULT = new Program(i,m); :};
memberdecls ::= fielddecls:fds methoddecls:m
            {: RESULT = new Memberdecls(fds,m); :};
fielddecls ::= fielddecl:f fielddecls:fds 
            {: RESULT = new Fielddecls(f,fds); :}
            |
            {: RESULT = new Fielddecls(); :};
methoddecls ::= methoddecl:md methoddecls:mds
            {: RESULT = new Methoddecls(md,mds); :}
            |
            {: RESULT = new Methoddecls(); :};
methoddecl ::= type:t ID:i PARENTHESISBEGIN argdecls:a PARENTHESISEND CURLBRACKETBEGIN fielddecls:f stmts:st CURLBRACKETEND optionalsemi:s
            {: RESULT = new Methoddecl(t,i,a,f,st,s); :}
            |
            VOID ID:i PARENTHESISBEGIN argdecls:a PARENTHESISEND CURLBRACKETBEGIN fielddecls:f stmts:st CURLBRACKETEND optionalsemi:s
            {: RESULT = new Methoddecl(i,s); :}
            ;
type ::=    INT
            {: RESULT = new Type("int"); :}
            |
            CHAR
            {: RESULT = new Type("char"); :}
            |
            BOOL
            {: RESULT = new Type("bool"); :}
            |
            FLOAT
            {: RESULT = new Type("float"); :};
optionalsemi ::= SEMI
            {: RESULT = new Optionalsemi(";"); :}
            |
            {: RESULT = new Optionalsemi(); :};
fielddecl ::= FINAL type:t ID:i optionalexpr:oe SEMI
            {: RESULT = new Fielddecl("final",t,oe); :}
            |
            type:t ID:i optionalexpr:oe SEMI
            {: RESULT = new Fielddecl(t,oe); :}
            |
            type:t ID:i SQUAREBRACKETBEGIN INTLIT:intl SQUAREBRACKETEND 

我认为这与Fielddecls如何引用Type非终结符有关。但是,我不确定如何消除它。如果可能的话,有人可以提供一些指导来消除这些减少偏移的错误吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)