From 01af4ad9c3498c0b5d25bc8f89aebf42490d61f7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 20 Jun 2020 17:32:18 +0200 Subject: [PATCH] multistart: toy with it in lexcalc * examples/c/lexcalc/parse.y: Define several start symbols. * examples/c/lexcalc/lexcalc.test: Check support. --- examples/c/lexcalc/lexcalc.test | 23 +++++++++++++++++++++++ examples/c/lexcalc/parse.y | 18 ++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/examples/c/lexcalc/lexcalc.test b/examples/c/lexcalc/lexcalc.test index 48a51575..ef02f6c1 100644 --- a/examples/c/lexcalc/lexcalc.test +++ b/examples/c/lexcalc/lexcalc.test @@ -20,6 +20,15 @@ cat >input <input <input <input <input <input < // printf. #include // getenv. +#include // strcmp. } // Include the header in the implementation rather than duplicating it. @@ -78,6 +79,8 @@ %type exp %printer { fprintf (yyo, "%d", $$); } +%start input line + // Precedence (from lowest to highest) and associativity. %left "+" "-" %left "*" "/" @@ -121,12 +124,23 @@ void yyerror (YYLTYPE *loc, int *nerrs, const char *msg) ++*nerrs; } -int main (void) +int main (int argc, const char *argv[]) { int nerrs = 0; // Possibly enable parser runtime debugging. yydebug = !!getenv ("YYDEBUG"); - yyparse (&nerrs); + // Enable parse traces on option -p. + int parse_line_p = 0; + for (int i = 0; i < argc; ++i) + if (1 < argc && strcmp (argv[1], "-p") == 0) + yydebug = 1; + else if (strcmp (argv[i], "-l") == 0) + parse_line_p = 1; + + if (parse_line_p) + yyparse_line (&nerrs); + else + yyparse_input (&nerrs); // Exit on failure if there were errors. return !!nerrs; }