mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
yyparse returns 0, 1, 2 since ages (accept, reject, memory exhausted). Some of our auxiliary functions such as yy_lac and yyreport_syntax_error also need to return error codes and also use 0, 1, 2. Because it uses yy_lac, yyexpected_tokens also needs to return "problem", "memory exhausted", but in case of success, it needs to return the number of tokens, so it cannot use 1 and 2 as error code. Currently it uses -1 and -2, which is later converted into 1 and 2 as yacc.c expects it. Let's simplify this and use consistently -1 and -2 for auxiliary functions that are not exposed (or not yet exposed) to the user. In particular this will save the user from having to convert yyexpected_tokens's -2 into yyreport_syntax_error's 2: both return -1 or -2. * data/skeletons/yacc.c (yy_lac, yyreport_syntax_error) (yy_lac_stack_realloc): Return -1, -2 for errors instead of 1, 2. Adjust callers. * examples/c/bistromathic/parse.y (yyreport_syntax_error): Do take error codes into account. Issue a syntax error message even if we ran out of memory. * src/parse-gram.y, tests/local.at (yyreport_syntax_error): Adjust.
bistromathic - all the bells and whistles
This example demonstrates best practices when using Bison.
- Its hand-written scanner tracks locations.
- Its interface is pure.
- Its interface is "incremental", well suited for interaction: it uses the push-parser API to feed the parser with the incoming tokens.
- It features an interactive command line with completion based on the
parser state, based on
yyexpected_tokens. - It uses a custom syntax error with location, lookahead correction and token internationalization.
- It supports debug traces with semantic values.
- It uses named references instead of the traditional $1, $2, etc.