diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2019-09-07 16:32:20 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2019-09-08 11:38:29 +0200 |
commit | f8db8fe4d7cb9db4cfbc414fca6f6ff9d74f0db6 (patch) | |
tree | 11be1e853365d6b2af3d31d9e669ec8c095cd609 | |
parent | 375eb714892c573e72d760d528c3e66a35689b46 (diff) | |
download | bison-f8db8fe4d7cb9db4cfbc414fca6f6ff9d74f0db6.tar.gz |
fix: don't die when EOF token is defined twice
With
%token EOF 0 EOF 0
we get
input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
3 | %token EOF 0 EOF 0
| ^~~
input.y:3.8-10: previous declaration
3 | %token EOF 0 EOF 0
| ^~~
Assertion failed: (nsyms == ntokens + nvars), function check_and_convert_grammar,
file /Users/akim/src/gnu/bison/src/reader.c, line 839.
Reported by Marc Schönefeld.
* src/symtab.c (symbol_user_token_number_set): Register only the
first definition of the end of input token.
* tests/input.at (Symbol redeclared): Check that case.
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | src/symtab.c | 2 | ||||
-rw-r--r-- | tests/input.at | 8 |
3 files changed, 9 insertions, 2 deletions
@@ -100,6 +100,7 @@ Lie Yan lie.yan@kaust.edu.sa Magnus Fromreide magfr@lysator.liu.se Marc Autret autret_m@epita.fr Marc Mendiola mmendiol@usc.edu +Marc Schönefeld marc.schoenefeld@gmx.org Mark Boyall wolfeinstein@gmail.com Martin Jacobs martin.jacobs@arcor.de Martin Mokrejs mmokrejs@natur.cuni.cz diff --git a/src/symtab.c b/src/symtab.c index 684fdf3d..7b0439ad 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -495,7 +495,7 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc) { *user_token_numberp = user_token_number; /* User defined $end token? */ - if (user_token_number == 0) + if (user_token_number == 0 && !endtoken) { endtoken = sym->content->symbol; /* It is always mapped to 0, so it was already counted in diff --git a/tests/input.at b/tests/input.at index 16f5aca6..df0f6939 100644 --- a/tests/input.at +++ b/tests/input.at @@ -624,7 +624,7 @@ AT_SETUP([Symbol redeclared]) AT_DATA([[input.y]], [[%token FOO FOO %token BAR 12 BAR 12 - +%token EOF 0 EOF 0 %% exp: FOO BAR ]]) @@ -642,6 +642,12 @@ input.y:2.15-17: warning: symbol BAR redeclared [-Wother] input.y:2.8-10: previous declaration 2 | %token BAR 12 BAR 12 | ^~~ +input.y:3.14-16: warning: symbol EOF redeclared [-Wother] + 3 | %token EOF 0 EOF 0 + | ^~~ +input.y:3.8-10: previous declaration + 3 | %token EOF 0 EOF 0 + | ^~~ ]]) AT_CLEANUP |