for an if and if-else statement grammar I have some grammar.
The following is a simplified excerpt from my code to show how I have the if and if-else statement grammar, so if there are errors unrelated to that grammar then don't worry about it. I assure you there are no compilation errors in the code I am using:
%token IF ELSE VOID ID VOID_PARAMS
%nonassoc shift_else
%nonassoc ElSE
%%
Func: VOID ID VOID_PARAMS '{' Stmt '}'
;
If_Stmt: IF '(' L_expr ')' Stmt
;
Stmt: If_Stmt shift_else
;
| If_Stmt ELSE Stmt
;
| ';'
| ...
;
L_expr: ...
;
It has been working just fine for a while, but now it is finding errors when it reaches the end of a function. For example:
void foo(void) {
if (1 > 5)
;
}
gives this output ( using yyerror() ):
Found unexpected token: '}' on line 4
Any suggestions as to why this could be happening? And what can I do to fix this?
Stmt: If_Stmt shift_else ; | If_Stmt ELSE Stmt ; | ';' | ... ;
are not legal. It is impossible to help you if you don't post a legal, usable extract of your grammar. – user207421