Problem with Rules

Apr 7, 2016 at 2:39 PM
Hi,

i've got a problem with my some of my rules of my grammar.

The grammar is like the following:
defLINES : carrRet
         | defLine carrRet
         | defLines defLine carrRet
         ;

defLine  : error carrRet                             {yyerrok();}
         | "DEF" kwType attrbt ID
         | "DEF" kwType ID fieldSuff
         ;

kwType   : "INT"
         | "REAL"
         ;

fieldSuff : "[" expr "]"
         | "[" expr "," expr "]"
         ;

attrbt   : /* nothing */
         | "PHU" intValue
         ;
With the Input to check:
DEF INT testvar1
DEF REAL testvar2
For this Input the second rule of the production with the head "defLine" should be used.

Why doesn't it? The third rule will always be used and throws an error
Unexpected 'carRet', '[' expected.
Thanks a lot for help,
Alex
Apr 7, 2016 at 3:14 PM
I think there is a shift/reduce-conflict, but I don't know how to solve it.

This is the output in the .conflicts-file:

Shift/Reduce conflict on symbol "ID", parser will shift
 Reduce 65: attrbt -> /* empty */
 Shift "ID":    State-481 -> State-488
  Items for From-state State 481
    35 defLINE: "DEF" kwType . attrbt ID 
    36 defLINE: "DEF" kwType . ID fieldSuff
  Items for Next-state State 488
    36 defLINE: "DEF" kwType ID . fieldSuff
I hope, this helps to find a solution... Thanks!