mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 14:23:04 +00:00
Don't allow an undeclared string literal, but allow a string literal to
be used before its declaration. * src/reader.c (check_and_convert_grammar): Don't invoke packgram if symbols_pack complained. * src/symtab.c (symbol_new): Don't count a string literal as a new symbol. (symbol_class_set): Don't count a string literal as a new token, and don't assign it a symbol number since symbol_make_alias does that. (symbol_make_alias): It's not necessary to decrement the symbol and token counts anymore. Don't assume that an alias declaration occurs before any uses of the identifier or string, and thus don't assert that one of them has the highest symbol number so far. (symbol_check_alias_consistency): Complain if there's a string literal that wasn't declared as an alias. (symbols_pack): Bail if symbol_check_alias_consistency failed since symbol_pack asserts that every token has been assigned a symbol number although undeclared string literals have not. * tests/regression.at (String alias declared after use, Undeclared string literal): New test case. (Characters Escapes, Web2c Actions): Declare string literals as aliases. * tests/sets.at (Firsts): Likewise.
This commit is contained in:
@@ -489,7 +489,9 @@ AT_DATA_GRAMMAR([input.y],
|
||||
void yyerror (const char *s);
|
||||
int yylex (void);
|
||||
%}
|
||||
[%%
|
||||
[%token QUOTES "\""
|
||||
%token TICK "'"
|
||||
%%
|
||||
exp:
|
||||
'\'' "\'"
|
||||
| '\"' "\""
|
||||
@@ -700,6 +702,10 @@ statement: struct_stat;
|
||||
struct_stat: /* empty. */ | if else;
|
||||
if: "if" "const" "then" statement;
|
||||
else: "else" statement;
|
||||
%token IF "if";
|
||||
%token CONST "const";
|
||||
%token THEN "then";
|
||||
%token ELSE "else";
|
||||
%%
|
||||
]])
|
||||
|
||||
@@ -1108,3 +1114,48 @@ Stack now 0
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
|
||||
## --------------------------------- ##
|
||||
## String alias declared after use. ##
|
||||
## --------------------------------- ##
|
||||
|
||||
AT_SETUP([String alias declared after use])
|
||||
|
||||
# Bison once incorrectly asserted that the symbol number for either a token or
|
||||
# its alias was the highest symbol number so far at the point of the alias
|
||||
# declaration. That was true unless the declaration appeared after their first
|
||||
# uses.
|
||||
|
||||
AT_DATA([input.y],
|
||||
[[%%
|
||||
start: 'a' "A" 'b';
|
||||
%token 'a' "A";
|
||||
]])
|
||||
|
||||
AT_CHECK([bison -t -o input.c input.y])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
|
||||
## --------------------------- ##
|
||||
## Undeclared string literal. ##
|
||||
## --------------------------- ##
|
||||
|
||||
AT_SETUP([Undeclared string literal])
|
||||
|
||||
# Bison once allowed a string literal to be used in the grammar without any
|
||||
# declaration assigning it as an alias of another token.
|
||||
|
||||
AT_DATA([input.y],
|
||||
[[%%
|
||||
start: "abc";
|
||||
]])
|
||||
|
||||
AT_CHECK([bison -t -o input.c input.y], [1], [],
|
||||
[[input.y:2.8-12: "abc" undeclared
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -196,6 +196,7 @@ AT_DATA([input.y],
|
||||
[[%nonassoc '<' '>'
|
||||
%left '+' '-'
|
||||
%right '^' '='
|
||||
%token EXP "exp"
|
||||
%%
|
||||
exp:
|
||||
exp '<' exp
|
||||
|
||||
Reference in New Issue
Block a user