mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 01:03:04 +00:00
Redo some of the previous commit: add back the ability to use
non-aliased/undeclared string literals since it might be useful to those declaring %token-table. * src/reader.c (check_and_convert_grammar): Undo changes in previous commit: don't worry about complaints from symbols_pack. * src/symtab.c (symbol_new, symbol_class_set, symbol_check_alias_consistency): Undo changes in previous commit: count each string literal as a new symbol and token, assign it a symbol number, and don't complain about non-aliased string literals. (symbols_pack): Since symbol_make_alias still does not decrement symbol and token counts but does still set aliased tokens to the same number, symbol_pack_processor now leaves empty slots in the symbols array. Remove those slots. * tests/regression.at (Undeclared string literal): Remove test case added in previous commit since non-aliased string literals are allowed again. (Characters Escapes, Web2c Actions): Undo changes in previous commit: remove unnecessary string literal declarations. * tests/sets.at (Firsts): Likewise.
This commit is contained in:
24
ChangeLog
24
ChangeLog
@@ -1,3 +1,25 @@
|
|||||||
|
2006-08-18 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
|
Redo some of the previous commit: add back the ability to use
|
||||||
|
non-aliased/undeclared string literals since it might be useful to
|
||||||
|
those declaring %token-table.
|
||||||
|
* src/reader.c (check_and_convert_grammar): Undo changes in previous
|
||||||
|
commit: don't worry about complaints from symbols_pack.
|
||||||
|
* src/symtab.c (symbol_new, symbol_class_set,
|
||||||
|
symbol_check_alias_consistency): Undo changes in previous commit: count
|
||||||
|
each string literal as a new symbol and token, assign it a symbol
|
||||||
|
number, and don't complain about non-aliased string literals.
|
||||||
|
(symbols_pack): Since symbol_make_alias still does not decrement symbol
|
||||||
|
and token counts but does still set aliased tokens to the same number,
|
||||||
|
symbol_pack_processor now leaves empty slots in the symbols array.
|
||||||
|
Remove those slots.
|
||||||
|
* tests/regression.at (Undeclared string literal): Remove test case
|
||||||
|
added in previous commit since non-aliased string literals are allowed
|
||||||
|
again.
|
||||||
|
(Characters Escapes, Web2c Actions): Undo changes in previous commit:
|
||||||
|
remove unnecessary string literal declarations.
|
||||||
|
* tests/sets.at (Firsts): Likewise.
|
||||||
|
|
||||||
2006-08-18 Joel E. Denny <jdenny@ces.clemson.edu>
|
2006-08-18 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
Don't allow an undeclared string literal, but allow a string literal to
|
Don't allow an undeclared string literal, but allow a string literal to
|
||||||
@@ -18,7 +40,7 @@
|
|||||||
symbol_pack asserts that every token has been assigned a symbol number
|
symbol_pack asserts that every token has been assigned a symbol number
|
||||||
although undeclared string literals have not.
|
although undeclared string literals have not.
|
||||||
* tests/regression.at (String alias declared after use, Undeclared
|
* tests/regression.at (String alias declared after use, Undeclared
|
||||||
string literal): New test case.
|
string literal): New test cases.
|
||||||
(Characters Escapes, Web2c Actions): Declare string literals as
|
(Characters Escapes, Web2c Actions): Declare string literals as
|
||||||
aliases.
|
aliases.
|
||||||
* tests/sets.at (Firsts): Likewise.
|
* tests/sets.at (Firsts): Likewise.
|
||||||
|
|||||||
@@ -630,8 +630,7 @@ check_and_convert_grammar (void)
|
|||||||
symbols_pack ();
|
symbols_pack ();
|
||||||
|
|
||||||
/* Convert the grammar into the format described in gram.h. */
|
/* Convert the grammar into the format described in gram.h. */
|
||||||
if (!complaint_issued)
|
packgram ();
|
||||||
packgram ();
|
|
||||||
|
|
||||||
/* The grammar as a symbol_list is no longer needed. */
|
/* The grammar as a symbol_list is no longer needed. */
|
||||||
LIST_FREE (symbol_list, grammar);
|
LIST_FREE (symbol_list, grammar);
|
||||||
|
|||||||
39
src/symtab.c
39
src/symtab.c
@@ -79,8 +79,7 @@ symbol_new (uniqstr tag, location loc)
|
|||||||
if (nsyms == SYMBOL_NUMBER_MAXIMUM)
|
if (nsyms == SYMBOL_NUMBER_MAXIMUM)
|
||||||
fatal (_("too many symbols in input grammar (limit is %d)"),
|
fatal (_("too many symbols in input grammar (limit is %d)"),
|
||||||
SYMBOL_NUMBER_MAXIMUM);
|
SYMBOL_NUMBER_MAXIMUM);
|
||||||
if (tag[0] != '"')
|
nsyms++;
|
||||||
nsyms++;
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,8 +266,7 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
|||||||
|
|
||||||
if (class == nterm_sym && sym->class != nterm_sym)
|
if (class == nterm_sym && sym->class != nterm_sym)
|
||||||
sym->number = nvars++;
|
sym->number = nvars++;
|
||||||
else if (class == token_sym && sym->number == NUMBER_UNDEFINED
|
else if (class == token_sym && sym->number == NUMBER_UNDEFINED)
|
||||||
&& sym->tag[0] != '"')
|
|
||||||
sym->number = ntokens++;
|
sym->number = ntokens++;
|
||||||
|
|
||||||
sym->class = class;
|
sym->class = class;
|
||||||
@@ -380,9 +378,6 @@ symbol_check_alias_consistency (symbol *this)
|
|||||||
symbol *alias = this;
|
symbol *alias = this;
|
||||||
symbol *orig = this->alias;
|
symbol *orig = this->alias;
|
||||||
|
|
||||||
if (this->tag[0] == '"' && !this->alias)
|
|
||||||
complain_at (this->location, _("%s undeclared"), this->tag);
|
|
||||||
|
|
||||||
/* Check only those that _are_ the aliases. */
|
/* Check only those that _are_ the aliases. */
|
||||||
if (!(this->alias && this->user_token_number == USER_NUMBER_ALIAS))
|
if (!(this->alias && this->user_token_number == USER_NUMBER_ALIAS))
|
||||||
return;
|
return;
|
||||||
@@ -720,13 +715,35 @@ symbols_token_translations_init (void)
|
|||||||
void
|
void
|
||||||
symbols_pack (void)
|
symbols_pack (void)
|
||||||
{
|
{
|
||||||
symbols = xcalloc (nsyms, sizeof *symbols);
|
|
||||||
|
|
||||||
symbols_do (symbol_check_alias_consistency_processor, NULL);
|
symbols_do (symbol_check_alias_consistency_processor, NULL);
|
||||||
if (complaint_issued)
|
|
||||||
return;
|
symbols = xcalloc (nsyms, sizeof *symbols);
|
||||||
symbols_do (symbol_pack_processor, NULL);
|
symbols_do (symbol_pack_processor, NULL);
|
||||||
|
|
||||||
|
/* Aliases leave empty slots in symbols, so remove them. */
|
||||||
|
{
|
||||||
|
int writei;
|
||||||
|
int readi;
|
||||||
|
int nsyms_old = nsyms;
|
||||||
|
for (writei = 0, readi = 0; readi < nsyms_old; readi += 1)
|
||||||
|
{
|
||||||
|
if (symbols[readi] == NULL)
|
||||||
|
{
|
||||||
|
nsyms -= 1;
|
||||||
|
ntokens -= 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
symbols[writei] = symbols[readi];
|
||||||
|
symbols[writei]->number = writei;
|
||||||
|
if (symbols[writei]->alias)
|
||||||
|
symbols[writei]->alias->number = writei;
|
||||||
|
writei += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
symbols = xnrealloc (symbols, nsyms, sizeof *symbols);
|
||||||
|
|
||||||
symbols_token_translations_init ();
|
symbols_token_translations_init ();
|
||||||
|
|
||||||
if (startsymbol->class == unknown_sym)
|
if (startsymbol->class == unknown_sym)
|
||||||
|
|||||||
@@ -489,9 +489,7 @@ AT_DATA_GRAMMAR([input.y],
|
|||||||
void yyerror (const char *s);
|
void yyerror (const char *s);
|
||||||
int yylex (void);
|
int yylex (void);
|
||||||
%}
|
%}
|
||||||
[%token QUOTES "\""
|
[%%
|
||||||
%token TICK "'"
|
|
||||||
%%
|
|
||||||
exp:
|
exp:
|
||||||
'\'' "\'"
|
'\'' "\'"
|
||||||
| '\"' "\""
|
| '\"' "\""
|
||||||
@@ -702,10 +700,6 @@ statement: struct_stat;
|
|||||||
struct_stat: /* empty. */ | if else;
|
struct_stat: /* empty. */ | if else;
|
||||||
if: "if" "const" "then" statement;
|
if: "if" "const" "then" statement;
|
||||||
else: "else" statement;
|
else: "else" statement;
|
||||||
%token IF "if";
|
|
||||||
%token CONST "const";
|
|
||||||
%token THEN "then";
|
|
||||||
%token ELSE "else";
|
|
||||||
%%
|
%%
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -1126,7 +1120,7 @@ AT_SETUP([String alias declared after use])
|
|||||||
# Bison once incorrectly asserted that the symbol number for either a token or
|
# 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
|
# 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
|
# declaration. That was true unless the declaration appeared after their first
|
||||||
# uses.
|
# uses and other tokens appeared in between.
|
||||||
|
|
||||||
AT_DATA([input.y],
|
AT_DATA([input.y],
|
||||||
[[%%
|
[[%%
|
||||||
@@ -1137,25 +1131,3 @@ start: 'a' "A" 'b';
|
|||||||
AT_CHECK([bison -t -o input.c input.y])
|
AT_CHECK([bison -t -o input.c input.y])
|
||||||
|
|
||||||
AT_CLEANUP
|
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,7 +196,6 @@ AT_DATA([input.y],
|
|||||||
[[%nonassoc '<' '>'
|
[[%nonassoc '<' '>'
|
||||||
%left '+' '-'
|
%left '+' '-'
|
||||||
%right '^' '='
|
%right '^' '='
|
||||||
%token EXP "exp"
|
|
||||||
%%
|
%%
|
||||||
exp:
|
exp:
|
||||||
exp '<' exp
|
exp '<' exp
|
||||||
|
|||||||
Reference in New Issue
Block a user