2002-06-10 Akim Demaille <akim@epita.fr>
+ * src/symtab.c, src/symtab.c (symbol_class_set)
+ (symbol_user_token_number_set): New.
+ * src/reader.c (parse_token_decl): Use them.
+ Use a switch instead of ifs.
+ Use a single argument.
+
+2002-06-10 Akim Demaille <akim@epita.fr>
+
Remove `%thong' support as it is undocumented, unused, duplicates
`%token's job, and creates useless e-mail traffic with people who
want to know what it is, why it is undocumented, unused, and
}
-/*-------------------------------------------------------------------.
-| Parse what comes after %token or %nterm. For %token, WHAT_IS is |
-| token_sym and WHAT_IS_NOT is nterm_sym. For %nterm, the arguments |
-| are reversed. |
-`-------------------------------------------------------------------*/
+/*------------------------------------------.
+| Parse what comes after %token or %nterm. |
+`------------------------------------------*/
static void
-parse_token_decl (symbol_class what_is, symbol_class what_is_not)
+parse_token_decl (symbol_class class)
{
token_t token = tok_undef;
char *typename = NULL;
fatal (_("Premature EOF after %s"), token_buffer);
token = lex ();
- if (token == tok_comma)
+ switch (token)
{
+ case tok_comma:
symbol = NULL;
- continue;
- }
- if (token == tok_typename)
- {
+ break;
+
+ case tok_typename:
typename = xstrdup (token_buffer);
symbol = NULL;
- }
- else if (token == tok_identifier && *symval->tag == '\"' && symbol)
- {
- symbol_make_alias (symbol, symval, typename);
- symbol = NULL;
- }
- else if (token == tok_identifier)
- {
- int oldclass = symval->class;
- symbol = symval;
-
- if (symbol->class == what_is_not)
- complain (_("symbol %s redefined"), symbol->tag);
- symbol->class = what_is;
- if (what_is == nterm_sym && oldclass != nterm_sym)
- symbol->number = nvars++;
- if (what_is == token_sym && symbol->number == NUMBER_UNDEFINED)
- symbol->number = ntokens++;
-
- if (typename)
+ break;
+
+ case tok_identifier:
+ if (*symval->tag == '\"' && symbol)
{
- if (symbol->type_name == NULL)
- symbol->type_name = typename;
- else if (strcmp (typename, symbol->type_name) != 0)
- complain (_("type redeclaration for %s"), symbol->tag);
+ symbol_make_alias (symbol, symval, typename);
+ symbol = NULL;
}
- }
- else if (symbol && token == tok_number)
- {
- symbol->user_token_number = numval;
- /* User defined EOF token? */
- if (numval == 0)
+ else
{
- eoftoken = symbol;
- eoftoken->number = 0;
- /* It is always mapped to 0, so it was already counted in
- NTOKENS. */
- --ntokens;
+ symbol = symval;
+ symbol_class_set (symbol, class);
+ if (typename)
+ symbol_type_set (symbol, typename);
}
- }
- else
- {
+ break;
+
+ case tok_number:
+ symbol_user_token_number_set (symbol, numval);
+ break;
+
+ default:
complain (_("`%s' is invalid in %s"),
token_buffer,
- (what_is == token_sym) ? "%token" : "%nterm");
+ (class == token_sym) ? "%token" : "%nterm");
skip_to_char ('%');
}
}
break;
case tok_token:
- parse_token_decl (token_sym, nterm_sym);
+ parse_token_decl (token_sym);
break;
case tok_nterm:
- parse_token_decl (nterm_sym, token_sym);
+ parse_token_decl (nterm_sym);
break;
case tok_type:
}
+/*-------------------------------------.
+| Set the CLASS associated to SYMBOL. |
+`-------------------------------------*/
+
+void
+symbol_class_set (symbol_t *symbol, symbol_class class)
+{
+ if (symbol->class != unknown_sym && symbol->class != class)
+ complain (_("symbol %s redefined"), symbol->tag);
+
+ 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)
+{
+ assert (symbol->class == token_sym);
+
+ if (symbol->user_token_number != USER_NUMBER_UNDEFINED)
+ complain (_("redefining user token number of %s"), symbol->tag);
+
+ 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. |
`------------*/
void symbol_precedence_set PARAMS ((symbol_t *symbol,
int prec, associativity assoc));
+/* Set the CLASS associated to SYMBOL. */
+void symbol_class_set PARAMS ((symbol_t *symbol, symbol_class class));
+
+/* Set the USER_TOKEN_NUMBER associated to SYMBOL. */
+void symbol_user_token_number_set PARAMS ((symbol_t *symbol, int user_number));
+
+
/* Distinguished symbols. AXIOM is the real start symbol, that used
by the automaton. STARTSYMBOL is the one specified by the user.
*/