I have some grammar rules for a C compiler and translator to Matlab language. I want to capture the syntax error due to missing ';' at the end of a statement.
For example I have the return statement:
stmt_return : RETURN {...some actions...}
exp ';' {...others actions...}
| RETURN {...some actions...}
';' {...others actions...}
How can I handle the lack of ';' and print a custom error message instead of the default message "syntax error".
I tried to add these rules but rightly produce conflicts:
stmt_return : RETURN exp { yyerror("...")}
| RETURN { yyerror("...")}