diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-03-28 15:37:09 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-04-01 08:31:48 +0200 |
commit | f3c18c8e80a399e74751f0ebd7085c4c4593edf5 (patch) | |
tree | 1aac977cae90421e31e474f1eb25077d7e5e2936 /tests/regression.at | |
parent | 00c80bc96c6de69385daf78139a4a79764d9eb9a (diff) | |
download | bison-f3c18c8e80a399e74751f0ebd7085c4c4593edf5.tar.gz |
yacc.c: also define a symbol number for the empty token
This is not only cleaner, it also protects us from mixing signed
values (YYEMPTY is #defined as -2) with unsigned types (the
yysymbol_type_t enum is typically compiled as a small unsigned).
For instance GCC 9:
input.c: In function 'yyparse':
input.c:1107:7: error: conversion to 'unsigned int' from 'int'
may change the sign of the result
[-Werror=sign-conversion]
1107 | yyn += yytoken;
| ^~
input.c:1107:10: error: conversion to 'int' from 'unsigned int'
may change the sign of the result
[-Werror=sign-conversion]
1107 | yyn += yytoken;
| ^~~~~~~
input.c:1108:47: error: comparison of integer expressions of
different signedness:
'yytype_int8' {aka 'const signed char'} and
'yysymbol_type_t' {aka 'enum yysymbol_type_t'}
[-Werror=sign-compare]
1108 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
| ^~
input.c:702:25: error: operand of ?: changes signedness from 'int'
to 'unsigned int' due to unsignedness of
other operand [-Werror=sign-compare]
702 | #define YYEMPTY (-2)
| ^~~~
input.c:1220:33: note: in expansion of macro 'YYEMPTY'
1220 | yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
| ^~~~~~~
input.c:1220:41: error: unsigned conversion from 'int' to
'unsigned int' changes value
from '-2' to '4294967294'
[-Werror=sign-conversion]
1220 | yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
| ^
Eventually, it might be interesting to move away from -2 (which is the
only possible negative symbol number) and use the next available
number, to save bits. We could actually even simply use "0" and shift
the rest, which would allow to write "!yytoken" to mean really
"yytoken != YYEMPTY".
* data/skeletons/c.m4 (b4_declare_symbol_enum): Define YYSYMBOL_YYEMPTY.
* data/skeletons/yacc.c: Use it.
* src/parse-gram.y (yyreport_syntax_error): Use YYSYMBOL_YYEMPTY, not
YYEMPTY, when dealing with a symbol.
* tests/regression.at: Adjust.
Diffstat (limited to 'tests/regression.at')
-rw-r--r-- | tests/regression.at | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/regression.at b/tests/regression.at index cd79b507..fa059248 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -665,7 +665,7 @@ AT_BISON_CHECK([-v -o input.c input.y]) [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] AT_CHECK([[cat tables.c]], 0, -[[static const yytype_int8 yytranslate[] = +[[static const yysymbol_type_t yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |