[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/17] multistart: toy with it in lexcalc
From: |
Akim Demaille |
Subject: |
[PATCH 11/17] multistart: toy with it in lexcalc |
Date: |
Sun, 20 Sep 2020 10:37:43 +0200 |
* 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 <<EOF
EOF
run 0 7
+cat >input <<EOF
+1
+2
+3
+EOF
+run 0 '1
+2
+3'
+
cat >input <<EOF
(1+2) * 3
EOF
@@ -35,3 +44,17 @@ cat >input <<EOF
1 / (2 - 2)
EOF
run 1 'err: 1.1-11: error: division by zero'
+
+
+# Multistart: parse "line" instead of "input".
+cat >input <<EOF
+1+2*3
+EOF
+run 0 7 -l
+
+cat >input <<EOF
+1
+2
+EOF
+run 1 '1
+err: 2.1: syntax error, unexpected number, expecting end of file' -l
diff --git a/examples/c/lexcalc/parse.y b/examples/c/lexcalc/parse.y
index d06a2036..dfbf4349 100644
--- a/examples/c/lexcalc/parse.y
+++ b/examples/c/lexcalc/parse.y
@@ -36,6 +36,7 @@
{
#include <stdio.h> // printf.
#include <stdlib.h> // getenv.
+#include <string.h> // strcmp.
}
// Include the header in the implementation rather than duplicating it.
@@ -78,6 +79,8 @@
%type <int> exp
%printer { fprintf (yyo, "%d", $$); } <int>
+%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;
}
--
2.28.0
- [PATCH 01/17] gram: more debugging information, (continued)
- [PATCH 01/17] gram: more debugging information, Akim Demaille, 2020/09/20
- [PATCH 02/17] reader: get ready to create several initial rules, Akim Demaille, 2020/09/20
- [PATCH 03/17] parser: expose a list of symbols, Akim Demaille, 2020/09/20
- [PATCH 04/17] regen, Akim Demaille, 2020/09/20
- [PATCH 05/17] multistart: turn start symbols into rules on $accept, Akim Demaille, 2020/09/20
- [PATCH 06/17] regen, Akim Demaille, 2020/09/20
- [PATCH 07/17] multistart: adjust computation of initial core and adjust reports, Akim Demaille, 2020/09/20
- [PATCH 08/17] multistart: also check the HTML report, Akim Demaille, 2020/09/20
- [PATCH 09/17] multistart: pass the list of start symbols to the backend, Akim Demaille, 2020/09/20
- [PATCH 10/17] multistart: equip yacc.c, Akim Demaille, 2020/09/20
- [PATCH 11/17] multistart: toy with it in lexcalc,
Akim Demaille <=
- [PATCH 12/17] todo: more, Akim Demaille, 2020/09/20
- [PATCH 13/17] multistart: adjust reader checks for generated rules, Akim Demaille, 2020/09/20
- [PATCH 14/17] multistart: use b4_accept instead of action post-processing, Akim Demaille, 2020/09/20
- [PATCH 15/17] multistart: allow tokens as start symbols, Akim Demaille, 2020/09/20
- [PATCH 16/17] yacc.c: also count calls to YYERROR in yynerrs, Akim Demaille, 2020/09/20
- [PATCH 17/17] multistart: also give access to yynerrs, Akim Demaille, 2020/09/20
- Re: [PATCH 00/17] RFC: multiple start symbols, Paul Eggert, 2020/09/20