Handle string aliases for character tokens correctly.

* src/symtab.c (symbol_user_token_number_set): If the token has an
alias, check and set its alias's user token number instead of its own,
which is set to indicate the alias.  Previously, every occurrence of
the character token in the grammar overwrote that alias indicator with
the character code.
* tests/input.at (String aliases for character tokens): New test.
This commit is contained in:
Joel E. Denny
2006-08-14 00:34:17 +00:00
parent 219741d873
commit 1f6b3679b2
3 changed files with 40 additions and 3 deletions

View File

@@ -1,3 +1,13 @@
2006-08-13 Joel E. Denny <jdenny@ces.clemson.edu>
Handle string aliases for character tokens correctly.
* src/symtab.c (symbol_user_token_number_set): If the token has an
alias, check and set its alias's user token number instead of its own,
which is set to indicate the alias. Previously, every occurrence of
the character token in the grammar overwrote that alias indicator with
the character code.
* tests/input.at (String aliases for character tokens): New test.
2006-08-12 Joel E. Denny <jdenny@ces.clemson.edu>
* src/parse-gram.y: Add `%expect 0' so we don't overlook conflicts.

View File

@@ -287,13 +287,19 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
void
symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
{
int *user_token_numberp;
assert (sym->class == token_sym);
if (sym->user_token_number != USER_NUMBER_UNDEFINED
&& sym->user_token_number != user_token_number)
if (sym->user_token_number != USER_NUMBER_ALIAS)
user_token_numberp = &sym->user_token_number;
else
user_token_numberp = &sym->alias->user_token_number;
if (*user_token_numberp != USER_NUMBER_UNDEFINED
&& *user_token_numberp != user_token_number)
complain_at (loc, _("redefining user token number of %s"), sym->tag);
sym->user_token_number = user_token_number;
*user_token_numberp = user_token_number;
/* User defined $end token? */
if (user_token_number == 0)
{

View File

@@ -471,3 +471,24 @@ AT_CHECK_REQUIRE(1.0, 0)
AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
## FIXME: Some day augment this version number.
AT_CHECK_REQUIRE(100.0, 63)
## ------------------------------------- ##
## String aliases for character tokens. ##
## ------------------------------------- ##
AT_SETUP([String aliases for character tokens])
# Bison once thought a character token and its alias were different symbols
# with the same user token number.
AT_DATA_GRAMMAR([input.y],
[[%token 'a' "a"
%%
start: 'a';
%%
]])
AT_CHECK([bison -o input.c input.y])
AT_CLEANUP