diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-03-08 17:31:28 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-03-17 19:20:13 +0100 |
commit | 44ac18d13681e05f38626427783bb5aad7d08020 (patch) | |
tree | 09cbf6424f62a69f7a9e6c9841c3ad4acaa9248f /examples | |
parent | 0c3dd3a669aa563e0080ebde15862c880a2d6b91 (diff) | |
download | bison-44ac18d13681e05f38626427783bb5aad7d08020.tar.gz |
yacc.c: yypstate_expected_tokens
In push parsers, when asking for the list of expected tokens at some
point, it makes no sense to build a yyparse_context_t: the yypstate
alone suffices (the only difference being the lookahead). Instead of
forcing the user to build a useless shell around yypstate, let's offer
yypstate_expected_tokens.
See https://lists.gnu.org/r/bison-patches/2020-03/msg00025.html.
* data/skeletons/yacc.c (yypstate): Declare earlier, so that we can
use it for...
(yypstate_expected_tokens): this new function, when in push parsers.
Adjust dependencies.
* examples/c/bistromathic/parse.y: Simplify: use
yypstate_expected_tokens.
Style fixes.
Reduce scopes (reported by Joel E. Denny).
Diffstat (limited to 'examples')
-rw-r--r-- | examples/c/bistromathic/parse.y | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y index b91fd094..45bcfd62 100644 --- a/examples/c/bistromathic/parse.y +++ b/examples/c/bistromathic/parse.y @@ -332,24 +332,23 @@ int expected_tokens (const char *input, int *tokens, int ntokens) { - YYDPRINTF ((stderr, "expected_tokens(\"%s\")", input)); + YYDPRINTF ((stderr, "expected_tokens (\"%s\")", input)); // Parse the current state of the line. - YYLTYPE lloc; yypstate *ps = yypstate_new (); int status = 0; do { + YYLTYPE lloc; YYSTYPE lval; int token = yylex (&input, &lval, &lloc); + // Don't let the parse know when we reach the end of input. if (!token) break; status = yypush_parse (ps, token, &lval, &lloc); } while (status == YYPUSH_MORE); // Then query for the accepted tokens at this point. - yyparse_context_t yyctx - = {ps->yyssp, YYEMPTY, &lloc, ps->yyesa, &ps->yyes, &ps->yyes_capacity}; - int res = yyexpected_tokens (&yyctx, tokens, ntokens); + int res = yypstate_expected_tokens (ps, tokens, ntokens); yypstate_delete (ps); return res; } @@ -362,7 +361,7 @@ expected_tokens (const char *input, char ** completion (const char *text, int start, int end) { - YYDPRINTF ((stderr, "completion(\"%.*s[%.*s]%s\")\n", + YYDPRINTF ((stderr, "completion (\"%.*s[%.*s]%s\")\n", start, rl_line_buffer, end - start, rl_line_buffer + start, rl_line_buffer + end)); @@ -414,7 +413,7 @@ completion (const char *text, int start, int end) if (yydebug) { - fprintf (stderr, "completion(\"%.*s[%.*s]%s\") = ", + fprintf (stderr, "completion (\"%.*s[%.*s]%s\") = ", start, rl_line_buffer, end - start, rl_line_buffer + start, rl_line_buffer + end); @@ -452,7 +451,7 @@ void init_readline (void) int main (int argc, char const* argv[]) { // Enable parse traces on option -p. - if (argc == 2 && strcmp(argv[1], "-p") == 0) + if (argc == 2 && strcmp (argv[1], "-p") == 0) yydebug = 1; init_table (); init_readline (); |