mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
multistart: also give access to yynerrs
This is something that has always bothered me: with pure parsers (and they all should be) the user does not have an (easy) access to yynerrs at the end of the parse. In the case of error recovery, that's the only direct means to know if there were errors. The usual approach being having the user maintain a counter incremented each time yyerror is called. So here, also capture yynerrs in the return value of the start-symbol parsing functions. * data/skeletons/yacc.c (yy_parse_impl_t): New. (yy_parse_impl): Use it. (b4_accept): Fill it. * examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l: No longer pass nerrs as lex- and parse-param, just use the resulting yynerrs. bistromathic and reccalc both demonstrate %param.
This commit is contained in:
@@ -61,7 +61,7 @@
|
||||
errno = 0;
|
||||
long n = strtol (yytext, NULL, 10);
|
||||
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
|
||||
yyerror (yylloc, nerrs, "integer is out of range");
|
||||
yyerror (yylloc, "integer is out of range");
|
||||
yylval->TOK_NUM = (int) n;
|
||||
return TOK_NUM;
|
||||
}
|
||||
@@ -71,7 +71,7 @@
|
||||
/* Ignore white spaces. */
|
||||
[ \t]+ LOCATION_STEP (); continue;
|
||||
|
||||
. yyerror (yylloc, nerrs, "syntax error, invalid character"); continue;
|
||||
. yyerror (yylloc, "syntax error, invalid character"); continue;
|
||||
|
||||
<<EOF>> return TOK_YYEOF;
|
||||
%%
|
||||
|
||||
Reference in New Issue
Block a user