+ /* Only terminals have a precedence. */
+ symbol_class_set (symbol, token_sym, location);
+}
+
+
+/*-------------------------------------.
+| Set the CLASS associated to SYMBOL. |
+`-------------------------------------*/
+
+void
+symbol_class_set (symbol_t *symbol, symbol_class class, location_t location)
+{
+ if (symbol->class != unknown_sym && symbol->class != class)
+ complain_at (location, _("symbol %s redefined"), symbol_tag_get (symbol));
+
+ if (class == nterm_sym && symbol->class != nterm_sym)
+ symbol->number = nvars++;
+ else if (class == token_sym && symbol->number == NUMBER_UNDEFINED)
+ symbol->number = ntokens++;
+
+ symbol->class = class;
+}
+
+
+/*-------------------------------------------------.
+| Set the USER_TOKEN_NUMBER associated to SYMBOL. |
+`-------------------------------------------------*/
+
+void
+symbol_user_token_number_set (symbol_t *symbol,
+ int user_token_number, location_t location)
+{
+ assert (symbol->class == token_sym);
+
+ if (symbol->user_token_number != USER_NUMBER_UNDEFINED
+ && symbol->user_token_number != user_token_number)
+ complain_at (location, _("redefining user token number of %s"),
+ symbol_tag_get (symbol));
+
+ symbol->user_token_number = user_token_number;
+ /* User defined EOF token? */
+ if (user_token_number == 0)
+ {
+ eoftoken = symbol;
+ eoftoken->number = 0;
+ /* It is always mapped to 0, so it was already counted in
+ NTOKENS. */
+ --ntokens;
+ }
+}
+
+
+/*------------.
+| Free THIS. |
+`------------*/
+
+static void
+symbol_free (symbol_t *this)
+{
+#if 0
+ /* This causes crashes because one string can appear more
+ than once. */
+ XFREE (this->type_name);
+#endif
+ XFREE (this->tag);
+ XFREE (this);
+}
+
+
+/*-----------------------------------------------------------.
+| If THIS is not defined, report an error, and consider it a |
+| nonterminal. |
+`-----------------------------------------------------------*/
+
+static bool
+symbol_check_defined (symbol_t *this)
+{
+ if (this->class == unknown_sym)
+ {
+ complain_at
+ (this->location,
+ _("symbol %s is used, but is not defined as a token and has no rules"),
+ symbol_tag_get (this));
+ this->class = nterm_sym;
+ this->number = nvars++;
+ }
+
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------.
+| Declare the new SYMBOL. Make it an alias of SYMVAL, and type them |
+| with TYPENAME. |
+`-------------------------------------------------------------------*/
+
+void
+symbol_make_alias (symbol_t *symbol, symbol_t *symval)
+{
+ if (symval->alias)
+ warn (_("symbol `%s' used more than once as a literal string"),
+ symbol_tag_get (symval));
+ else if (symbol->alias)
+ warn (_("symbol `%s' given more than one literal string"),
+ symbol_tag_get (symbol));
+ else
+ {
+ symval->class = token_sym;
+ symval->user_token_number = symbol->user_token_number;
+ symbol->user_token_number = USER_NUMBER_ALIAS;
+ symval->alias = symbol;
+ symbol->alias = symval;
+ /* symbol and symval combined are only one symbol */
+ nsyms--;
+ ntokens--;
+ assert (ntokens == symbol->number || ntokens == symval->number);
+ symbol->number = symval->number =
+ (symval->number < symbol->number) ? symval->number : symbol->number;
+ }
+}
+
+
+/*---------------------------------------------------------.
+| Check that THIS, and its alias, have same precedence and |
+| associativity. |
+`---------------------------------------------------------*/
+
+static bool
+symbol_check_alias_consistence (symbol_t *this)
+{
+ /* Check only those who _are_ the aliases. */
+ if (this->alias && this->user_token_number == USER_NUMBER_ALIAS)