I'm a newbie to yacc and not really understand how to write the rules, especially handle the recursive definitions.
%token NUMBER
%token VARIABLE
%left '+' '-'
%left '*' '/' '%'
%left '(' ')'
%%
S: VARIABLE'='E {
printf("\nEntered arithmetic expression is Valid\n\n");
return 0;
}
E : E'+'E
| E'-'E
| E'*'E
| E'/'E
| E'%'E
| '('E')'
| NUMBER
| VARIABLE
;
%%
The above example is work well, but when I changed it as below, it got "5 shift/reduce conflicts".
%token NUMBER
%token VARIABLE
%token MINS
%token PULS
%token MUL
%token DIV
%token MOD
%token LP
%token RP
%left MINS PULS
%left MUL DIV MOD
%left LP RP
%%
S: VARIABLE'='E {
printf("\nEntered arithmetic expression is Valid\n\n");
return 0;
}
E : E operator E
| LP E RP
| NUMBER
| VARIABLE
;
operator: MINS
| PULS
| MUL
| DIV
| MOD
;
%%
Can any one tell me what is the difference between these examples? Thanks a lot..