Here is a part of C compiler:
Exp :
INTNUMBER { $$ = $1; }
| lvalue { $$ = $1; }
| REALNUMBER { $$ = $1; }
| CHARVALUE { $$ = $1; }
| TRUE { $$ = $1; }
| FALSE { $$ = $1; }
| Exp '+' Exp { $$ = $1 + $3; }
| Exp '*' Exp { $$ = $1 * $3; }
| Exp '/' Exp { $$ = $1 / $3; }
| Exp '-' Exp { $$ = $1 - $3; }
| Exp '%' Exp { $$ = $1 % $3; }
| Exp AND Exp { $$ = $1 && $3; }
| Exp OR Exp { $$ = $1 || $3; }
| Exp LEQ Exp { $$ = $1 <= $3; }
| Exp GEQ Exp { $$ = $1 >= $3; }
| Exp EQ Exp { $$ = $1 == $3; }
| Exp NEQ Exp { $$ = $1 != $3; }
| Exp GE Exp { $$ = $1 > $3; }
| Exp LE Exp { $$ = $1 < $3; }
| '-' Exp %prec UMINUS { $$ = -1 * $2; }
| STRING { $$ = $1; }
| '('Exp')' { $$ = $2; }
| lvalue '=' Exp { $1 = $3; }
| ID'('ExpList')' {printf("Exp");}
;
IDD :
ID { printf("IDD"); }
| IDD '[' Exp ']' {printf("IDD");}
;
ExpList
: { printf("ExpList"); }
ExpPlus {printf("ExpList");}
|
;
ExpPlus :
Exp { printf("Exp\n"); }
| Exp ',' ExpPlus {printf("ExpPlus");}
;
in which, ID is a terminal (that is, in C an ID can start with _ or [a-zA-Z]. While parsing this code with bison using the -v flag, I got a shift/reduce conflict as follow:
52 IDD: ID .
78 Exp: ID . '(' ExpList ')'
'(' shift, and go to state 56
'(' [reduce using rule 52 (IDD)]
$default reduce using rule 52 (IDD)
I have resolved all the shift/reduce conflicts that I faced so far. But I cannot understand how this one should be solved.
Thank you