/* Symbol table manager for Bison.
- Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008
+ Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007,
+ 2008, 2009
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
symbol *res = xmalloc (sizeof *res);
uniqstr_assert (tag);
+
+ /* If the tag is not a string (starts with a double quote), check
+ that it is valid for Yacc. */
+ if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-'))
+ yacc_at (loc, _("POSIX Yacc forbids dashes in symbol names: %s"),
+ tag);
+
res->tag = tag;
res->location = loc;
}
+
/*-----------------------------------------------------------------.
| Set the TYPE_NAME associated with SYM. Does nothing if passed 0 |
| as TYPE_NAME. |
}
+static void
+user_token_number_redeclaration (int num, symbol *first, symbol *second)
+{
+ /* User token numbers are not assigned during the parsing, but in a
+ second step, via a (nondeterministic) traversal of the symbol
+ hash table.
+ Make errors deterministic: keep the first declaration first. */
+ if (location_cmp (first->location, second->location) > 0)
+ {
+ symbol* tmp = first;
+ first = second;
+ second = tmp;
+ }
+ complain_at (second->location,
+ _("user token number %d redeclaration for %s"),
+ num, second->tag);
+ complain_at (first->location, _("previous declaration for %s"),
+ first->tag);
+}
/*--------------------------------------------------.
| Put THIS in TOKEN_TRANSLATIONS if it is a token. |
{
/* A token which translation has already been set? */
if (token_translations[this->user_token_number] != undeftoken->number)
- complain_at (this->location,
- _("tokens %s and %s both assigned number %d"),
- symbols[token_translations[this->user_token_number]]->tag,
- this->tag, this->user_token_number);
+ user_token_number_redeclaration
+ (this->user_token_number,
+ symbols[token_translations[this->user_token_number]],
+ this);
token_translations[this->user_token_number] = this->number;
}
{
/* First insertion in the hash. */
entry = symbol_new (key, loc);
- hash_insert (symbol_table, entry);
+ if (!hash_insert (symbol_table, entry))
+ xalloc_die ();
}
return entry;
}
{
/* First insertion in the hash. */
entry = semantic_type_new (key);
- hash_insert (semantic_type_table, entry);
+ if (!hash_insert (semantic_type_table, entry))
+ xalloc_die ();
}
return entry;
}