I am writing a small expression analyser parser for a project at the company where I work. The parser is supposed to check, for example, a division by zero or an undefined identifier, report the error and stop. What is the best way to do this? Assuming that my own code has no memory leaks, can I simply do this:
if ($3 == 0) {
yyerror("Division by zero");
return 1;
}
should I rather do:
if ($3 == 0) {
yyerror("Division by zero");
YYERROR;
}
is there a third better alternative?
If you call
yyerrorexplicitly, how about usingYYABORT?As far as I see,
bisonseems to perform some cleanups at exit.So,
YYABORTorYYERRORwill be more preferable toreturn 1.