summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2022-09-10 14:04:11 +0200
committerAkim Demaille <akim.demaille@gmail.com>2022-09-10 14:09:02 +0200
commitdd6ca199276506c4902a993b863fa10414a90178 (patch)
treed57cccc0f14f53d733bfbd5c1d04fa65e33940cc
parent3661ebbb2c7b8ef45e4f5df38d57ece098251be6 (diff)
downloadbison-dd6ca199276506c4902a993b863fa10414a90178.tar.gz
reader: reject rules on YYEOF
We crashed when rules were given on YYEOF. Reported by Han Zheng. Fixes https://github.com/akimd/bison/issues/92. * src/reader.c (check_and_convert_grammar): Make sure YYEOF is not an nterm. * tests/input.at (Rule for YYEOF): New.
-rw-r--r--src/reader.c4
-rw-r--r--tests/input.at32
2 files changed, 36 insertions, 0 deletions
diff --git a/src/reader.c b/src/reader.c
index baa5d803..3d60ab36 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -954,6 +954,10 @@ check_and_convert_grammar (void)
if (!eoftoken)
{
eoftoken = symbol_get ("YYEOF", empty_loc);
+ if (eoftoken->content->class == nterm_sym)
+ complain (&eoftoken->location, complaint,
+ _("rule given for %s, which is a token"),
+ eoftoken->tag);
eoftoken->content->class = token_sym;
eoftoken->content->number = 0;
/* Value specified by POSIX. */
diff --git a/tests/input.at b/tests/input.at
index f76000be..5cacb066 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1888,6 +1888,38 @@ input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wothe
AT_CLEANUP
+## ---------------- ##
+## Rule for YYEOF. ##
+## ---------------- ##
+
+AT_SETUP([Rule for YYEOF])
+
+# We crashed when rules were given on YYEOF.
+# https://github.com/akimd/bison/issues/92.
+
+AT_DATA([input1.y],
+[[%%
+start: YYEOF;
+YYEOF: 'x';
+]])
+
+AT_BISON_CHECK([input1.y], [1], [],
+[[input1.y:3.1-5: error: rule given for YYEOF, which is a token
+]])
+
+# This is ok, YYEOF is not special.
+AT_DATA([input2.y],
+[[%token MYEOF 0
+%%
+start: YYEOF;
+YYEOF: 'x';
+]])
+
+AT_BISON_CHECK([input2.y])
+
+AT_CLEANUP
+
+
## --------------------- ##
## %prec takes a token. ##
## --------------------- ##