Shift Reduce Conflict (CUP)

82 views Asked by At

I am trying define my grammar in my cup file and I'm getting the following errors.

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.

The following is the grammar that is defined in my cup file.

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,a,f,st,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, i, oe); :}
            |
            type:t ID:i optionalexpr:oe SEMI
            {: RESULT = new Fielddecl(t,i,oe); :}
            |
            type:t ID:i SQUAREBRACKETBEGIN INTLIT:intl SQUAREBRACKETEND 

I believe this has something to do with how Fielddecls is referring to the Type nonterminal. However, I'm not really sure how to eliminate it. If possible, can someone please offer some guidance to eliminate these shift reduce errors?

0

There are 0 answers