I have the following grammar (Yacc) that is the beginning of a simple C compiler, i'm starting from a simple if
statement:
S : E
;
E : COND_NO_ELSE
;
COND_NO_ELSE : IF BOOL_EXP BLOCK
;
BLOCK : LC EXP RC
BOOL_EXP : LP EXP BOOL_OP EXP RP
;
BOOL_OP : LT_OP
| GT_OP
| LE_OP
| GE_OP
| EQ_OP
| NE_OP
;
MATH_OP : PLUS_OP
;
EXP : IDENTIFIER
| EXP MATH_OP EXP
;
Here are the lexical analyzer scanner for the relevant rules:
"=" { yylval.string = strdup(yytext); return ASSIGN;}
"+" { yylval.string = strdup(yytext); return PLUS_OP;}
"-" { yylval.string = strdup(yytext); return MINUS_OP;}
"*" { yylval.string = strdup(yytext); return MULTIPLY_OP;}
"/" { yylval.string = strdup(yytext); return DIV_OP;}
"%" { yylval.string = strdup(yytext); return MOD_OP;}
"<" { yylval.string = strdup(yytext); return LT_OP;}
">" { yylval.string = strdup(yytext); return GT_OP; }
"<=" { yylval.string = strdup(yytext); return LE_OP; }
">=" { yylval.string = strdup(yytext); return GE_OP; }
"==" { yylval.string = strdup(yytext); return EQ_OP; }
"!=" { yylval.string = strdup(yytext); return NE_OP; }
"(" { yylval.string = strdup(yytext); return LP; }
")" { yylval.string = strdup(yytext); return RP; }
"{" { yylval.string = strdup(yytext); return LC; }
"}" { yylval.string = strdup(yytext); return RC; }
if { return IF; }
I do know that the conflict started when i added the MATH_OP
(i had all math operators than and got 5 conflicts, than removed all but the PLUS_OP
and got 1 shift/reduce conflict).
i used the -v
flag for the output file as suggested here, and checked this question but it doesn't resemble my grammar too much...
How can i find the conflict?