I'm writing a compiler from (reduced) Pascal into ARM asm. I'm at the second step of the process - after writing lexical analyzer now I'm working on syntax analysis with java cup.
I have written my grammar, but got 5 S/R conflicts, which are all very similar. Example:
Warning : *** Shift/Reduce conflict found in state #150
between assign_stmt ::= val_expr ASSIGN val_expr (*)
and val_expr ::= val_expr (*) LBRACKET val_expr RBRACKET
under symbol LBRACKET
Resolved in favor of shifting
My grammar for this section:
assign_stmt ::=
val_expr ASSIGN val_expr;
val_expr ::=
NIL | BOOL_CONST | INT_CONST | CHAR_CONST | PTR val_expr %prec MEM | ADD val_expr %prec UADD |
SUB val_expr %prec USUB | NOT val_expr | val_expr PTR %prec VAL | val_expr MUL val_expr |
val_expr DIV val_expr | val_expr ADD val_expr | val_expr SUB val_expr | val_expr EQU val_expr |
val_expr NEQ val_expr | val_expr LTH val_expr | val_expr GTH val_expr | val_expr LEQ val_expr |
val_expr GEQ val_expr | val_expr AND val_expr | val_expr OR val_expr | IDENTIFIER |
val_expr LBRACKET val_expr RBRACKET | val_expr DOT IDENTIFIER | IDENTIFIER LPARENTHESIS params_list RPARENTHESIS |
LBRACKET type_desc RBRACKET | LPARENTHESIS val_expr RPARENTHESIS
;
How could I eliminate this conflict?
Thanks.