[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bison 3.7.90 (beta): example/c/lexcalc
From: |
Akim Demaille |
Subject: |
Re: Bison 3.7.90 (beta): example/c/lexcalc |
Date: |
Thu, 19 Aug 2021 09:22:26 +0200 |
> Le 18 août 2021 à 16:28, Dagobert Michelsen <dam@opencsw.org> a écrit :
>
> Hi Akim,
>
> Am 17.08.2021 um 08:59 schrieb Akim Demaille <akim@lrde.epita.fr>:
>>> Le 13 août 2021 à 09:50, Dagobert Michelsen <dam@opencsw.org> a écrit :
>>> and there are also errors on Solaris 10 Sparc:
>>> YACC examples/c/lexcalc/parse.c
>>> /home/dam/mgar/pkg/bison/trunk/work/solaris10-sparc/build-isa-sparcv8plus/bison-3.7.90/examples/c/lexcalc/parse.y:
>>> error: 1 nonterminal useless in grammar [-Werror=other]
>>> /home/dam/mgar/pkg/bison/trunk/work/solaris10-sparc/build-isa-sparcv8plus/bison-3.7.90/examples/c/lexcalc/parse.y:
>>> error: 1 rule useless in grammar [-Werror=other]
>>> /home/dam/mgar/pkg/bison/trunk/work/solaris10-sparc/build-isa-sparcv8plus/bison-3.7.90/examples/c/lexcalc/parse.y:79.25-27:
>>> error: start symbol NUM does not derive any sentence
>>> 79 | %start input expression NUM
>>> | ^~~
>>> gmake[3]: *** [Makefile:9538: examples/c/lexcalc/parse.c] Error 1
>>
>> That makes no sense to me: bison is emitting an incorrect
>> diagnostic. I absolutely do not understand how this is possible.
>> Except if we actually are not running the shipped bison, but another
>> one.
>>
>> Could you please run `make check-examples V=1`?
>
> Sure:
>
> dam@unstable10s
> [unstable10s]:/home/dam/mgar/pkg/bison/trunk/work/solaris10-sparc/build-isa-sparcv8plus/bison-3.7.90
> > gmake check-examples V=1
> /bin/bash ./build-aux/ylwrap examples/c/lexcalc/parse.y y.tab.c
> examples/c/lexcalc/parse.c y.tab.h `echo examples/c/lexcalc/parse.c | sed -e
> s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output
> examples/c/lexcalc/parse.output -- ./tests/bison -o y.tab.c --defines -Werror
> -Wall,dangling-alias --report=all --no-lines
> /home/dam/mgar/pkg/bison/trunk/work/solaris10-sparc/build-isa-sparcv8plus/bison-3.7.90/examples/c/lexcalc/parse.y:
> error: 1 nonterminal useless in grammar [-Werror=other]
> /home/dam/mgar/pkg/bison/trunk/work/solaris10-sparc/build-isa-sparcv8plus/bison-3.7.90/examples/c/lexcalc/parse.y:
> error: 1 rule useless in grammar [-Werror=other]
> /home/dam/mgar/pkg/bison/trunk/work/solaris10-sparc/build-isa-sparcv8plus/bison-3.7.90/examples/c/lexcalc/parse.y:79.25-27:
> error: start symbol NUM does not derive any sentence
> 79 | %start input expression NUM
> | ^~~
> gmake: *** [Makefile:9538: examples/c/lexcalc/parse.c] Error 1
This still does not make sense to me. But let's postpone this issue, since
it's about an unfinished feature that I don't want to demonstrate in 3.8. So I
have installed the following "fix". But in the future we will have to dig
deeper.
Thanks a lot for the feedback!
commit a70e75b8a41755ab96ab211a0ea111ac68a4aadd
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Thu Aug 19 09:16:00 2021 +0200
examples: don't demonstrate multistart, which is not part of 3.8
Besides, for mysterious reasons, this fails on some environment.
Reported by Dagobert Michelsen.
<https://lists.gnu.org/archive/html/bug-bison/2021-08/msg00008.html>
* examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/parse.y,
* examples/c/lexcalc/scan.l: Revert to a single-start example.
diff --git a/TODO b/TODO
index 2e6e7d5a..4ef16d8d 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,3 @@
-* 3.8
-Don't showcase multi start.
-
* Soon
** scan-code
The default case is scanning char-per-char.
diff --git a/examples/c/lexcalc/lexcalc.test b/examples/c/lexcalc/lexcalc.test
index df8da33b..7559a21e 100644
--- a/examples/c/lexcalc/lexcalc.test
+++ b/examples/c/lexcalc/lexcalc.test
@@ -38,26 +38,9 @@ run -noerr 0 9 -p
cat >input <<EOF
(1+2) *
EOF
-run 1 'err: 1.8-2.0: syntax error, unexpected end of line, expecting ( or
number
-err: errors: 1'
+run 1 'err: 1.8-2.0: syntax error, unexpected end of line, expecting ( or
number'
cat >input <<EOF
1 / (2 - 2)
EOF
-run 1 'err: 1.1-11: error: division by zero
-err: errors: 1'
-
-
-# Multistart: parse "expression" instead of "input".
-cat >input <<EOF
-1+2*3
-EOF
-run 0 'expression: 7' -e
-
-cat >input <<EOF
-1
-2
-EOF
-run 1 'expression: failure
-err: 2.1: syntax error, unexpected number, expecting end of file
-err: errors: 1' -e
+run 1 'err: 1.1-11: error: division by zero'
diff --git a/examples/c/lexcalc/parse.y b/examples/c/lexcalc/parse.y
index aa72a410..ee559887 100644
--- a/examples/c/lexcalc/parse.y
+++ b/examples/c/lexcalc/parse.y
@@ -25,10 +25,10 @@
{
// Tell Flex the expected prototype of yylex.
#define YY_DECL \
- yytoken_kind_t yylex (YYSTYPE* yylval, YYLTYPE *yylloc)
+ yytoken_kind_t yylex (YYSTYPE* yylval, YYLTYPE *yylloc, int *nerrs)
YY_DECL;
- void yyerror (const YYLTYPE *loc, const char *msg);
+ void yyerror (const YYLTYPE *loc, int *nerrs, const char *msg);
}
// Emitted on top of the implementation file.
@@ -62,6 +62,9 @@
// Enable debug traces (see yydebug in main).
%define parse.trace
+// Error count, exchanged between main, yyparse and yylex.
+%param {int *nerrs}
+
%token
PLUS "+"
MINUS "-"
@@ -73,11 +76,9 @@
;
%token <int> NUM "number"
-%type <int> exp expression line
+%type <int> exp
%printer { fprintf (yyo, "%d", $$); } <int>
-%start input expression NUM
-
// Precedence (from lowest to highest) and associativity.
%left "+" "-"
%left "*" "/"
@@ -90,12 +91,8 @@ input:
;
line:
- exp EOL { $$ = $exp; printf ("%d\n", $$); }
-| error EOL { $$ = 0; yyerrok; }
-;
-
-expression:
- exp EOL { $$ = $exp; }
+ exp EOL { printf ("%d\n", $exp); }
+| error EOL { yyerrok; }
;
exp:
@@ -106,7 +103,7 @@ exp:
{
if ($3 == 0)
{
- yyerror (&@$, "error: division by zero");
+ yyerror (&@$, nerrs, "error: division by zero");
YYERROR;
}
else
@@ -118,41 +115,24 @@ exp:
%%
// Epilogue (C code).
-void yyerror (const YYLTYPE *loc, const char *msg)
+void yyerror (const YYLTYPE *loc, int *nerrs, const char *msg)
{
YYLOCATION_PRINT (stderr, loc);
fprintf (stderr, ": %s\n", msg);
+ ++*nerrs;
}
int main (int argc, const char *argv[])
{
// Possibly enable parser runtime debugging.
yydebug = !!getenv ("YYDEBUG");
- int parse_expression_p = 0;
- int nerrs = 0;
-
// Enable parse traces on option -p.
for (int i = 1; i < argc; ++i)
- if (strcmp (argv[i], "-e") == 0)
- parse_expression_p = 1;
- else if (strcmp (argv[i], "-p") == 0)
+ if (strcmp (argv[i], "-p") == 0)
yydebug = 1;
- if (parse_expression_p)
- {
- yyparse_expression_t res = yyparse_expression ();
- nerrs = res.yynerrs;
- if (res.yystatus == 0)
- printf ("expression: %d\n", res.yyvalue);
- else
- printf ("expression: failure\n");
- }
- else
- nerrs = yyparse_input ().yynerrs;
-
- if (nerrs)
- fprintf (stderr, "errors: %d\n", nerrs);
-
+ int nerrs = 0;
+ yyparse (&nerrs);
// Exit on failure if there were errors.
return !!nerrs;
}
diff --git a/examples/c/lexcalc/scan.l b/examples/c/lexcalc/scan.l
index 51129a56..983fbdaf 100644
--- a/examples/c/lexcalc/scan.l
+++ b/examples/c/lexcalc/scan.l
@@ -61,7 +61,7 @@
errno = 0;
long n = strtol (yytext, NULL, 10);
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
- yyerror (yylloc, "integer is out of range");
+ yyerror (yylloc, nerrs, "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, "syntax error, invalid character"); continue;
+. yyerror (yylloc, nerrs, "syntax error, invalid character"); continue;
<<EOF>> return TOK_YYEOF;
%%
- Re: Bison 3.7.90 (beta): test 4, (continued)
- Re: Bison 3.7.90 (beta): test 4, Akim Demaille, 2021/08/19
- Re: Bison 3.7.90 (beta): test 4, Dagobert Michelsen, 2021/08/19
- Re: Bison 3.7.90 (beta): test 4, Akim Demaille, 2021/08/19
- Re: Bison 3.7.90 (beta): test 4, Dagobert Michelsen, 2021/08/19
- Re: Bison 3.7.90 (beta): test 4, Akim Demaille, 2021/08/19
- Re: Bison 3.7.90 (beta): test 4, Dagobert Michelsen, 2021/08/19
- Re: Bison 3.7.90 (beta): test 4, Akim Demaille, 2021/08/20
- Re: Bison 3.7.90 (beta): test 4, Dagobert Michelsen, 2021/08/23
- Re: Bison 3.7.90 (beta): test 4, Akim Demaille, 2021/08/29
- Re: Bison 3.7.90 (beta): test 4, Dagobert Michelsen, 2021/08/29
- Re: Bison 3.7.90 (beta): example/c/lexcalc,
Akim Demaille <=
Re: Bison 3.7.90 (beta), Akim Demaille, 2021/08/19