mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 16:53:02 +00:00
* 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.
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
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>
|
2002-06-10 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
Remove `%thong' support as it is undocumented, unused, duplicates
|
Remove `%thong' support as it is undocumented, unused, duplicates
|
||||||
|
|||||||
86
src/reader.c
86
src/reader.c
@@ -483,14 +483,12 @@ copy_definition (struct obstack *oout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------.
|
/*------------------------------------------.
|
||||||
| Parse what comes after %token or %nterm. For %token, WHAT_IS is |
|
| Parse what comes after %token or %nterm. |
|
||||||
| token_sym and WHAT_IS_NOT is nterm_sym. For %nterm, the arguments |
|
`------------------------------------------*/
|
||||||
| are reversed. |
|
|
||||||
`-------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
static void
|
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;
|
token_t token = tok_undef;
|
||||||
char *typename = NULL;
|
char *typename = NULL;
|
||||||
@@ -512,60 +510,40 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
|
|||||||
fatal (_("Premature EOF after %s"), token_buffer);
|
fatal (_("Premature EOF after %s"), token_buffer);
|
||||||
|
|
||||||
token = lex ();
|
token = lex ();
|
||||||
if (token == tok_comma)
|
switch (token)
|
||||||
{
|
{
|
||||||
|
case tok_comma:
|
||||||
symbol = NULL;
|
symbol = NULL;
|
||||||
continue;
|
break;
|
||||||
}
|
|
||||||
if (token == tok_typename)
|
case tok_typename:
|
||||||
{
|
|
||||||
typename = xstrdup (token_buffer);
|
typename = xstrdup (token_buffer);
|
||||||
symbol = NULL;
|
symbol = NULL;
|
||||||
}
|
break;
|
||||||
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)
|
case tok_identifier:
|
||||||
complain (_("symbol %s redefined"), symbol->tag);
|
if (*symval->tag == '\"' && symbol)
|
||||||
symbol->class = what_is;
|
{
|
||||||
if (what_is == nterm_sym && oldclass != nterm_sym)
|
symbol_make_alias (symbol, symval, typename);
|
||||||
symbol->number = nvars++;
|
symbol = NULL;
|
||||||
if (what_is == token_sym && symbol->number == NUMBER_UNDEFINED)
|
}
|
||||||
symbol->number = ntokens++;
|
else
|
||||||
|
{
|
||||||
|
symbol = symval;
|
||||||
|
symbol_class_set (symbol, class);
|
||||||
|
if (typename)
|
||||||
|
symbol_type_set (symbol, typename);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
if (typename)
|
case tok_number:
|
||||||
{
|
symbol_user_token_number_set (symbol, numval);
|
||||||
if (symbol->type_name == NULL)
|
break;
|
||||||
symbol->type_name = typename;
|
|
||||||
else if (strcmp (typename, symbol->type_name) != 0)
|
default:
|
||||||
complain (_("type redeclaration for %s"), symbol->tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (symbol && token == tok_number)
|
|
||||||
{
|
|
||||||
symbol->user_token_number = numval;
|
|
||||||
/* User defined EOF token? */
|
|
||||||
if (numval == 0)
|
|
||||||
{
|
|
||||||
eoftoken = symbol;
|
|
||||||
eoftoken->number = 0;
|
|
||||||
/* It is always mapped to 0, so it was already counted in
|
|
||||||
NTOKENS. */
|
|
||||||
--ntokens;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
complain (_("`%s' is invalid in %s"),
|
complain (_("`%s' is invalid in %s"),
|
||||||
token_buffer,
|
token_buffer,
|
||||||
(what_is == token_sym) ? "%token" : "%nterm");
|
(class == token_sym) ? "%token" : "%nterm");
|
||||||
skip_to_char ('%');
|
skip_to_char ('%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -922,11 +900,11 @@ read_declarations (void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case tok_token:
|
case tok_token:
|
||||||
parse_token_decl (token_sym, nterm_sym);
|
parse_token_decl (token_sym);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tok_nterm:
|
case tok_nterm:
|
||||||
parse_token_decl (nterm_sym, token_sym);
|
parse_token_decl (nterm_sym);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tok_type:
|
case tok_type:
|
||||||
|
|||||||
44
src/symtab.c
44
src/symtab.c
@@ -87,6 +87,50 @@ symbol_precedence_set (symbol_t *symbol,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------.
|
||||||
|
| 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. |
|
| Free THIS. |
|
||||||
`------------*/
|
`------------*/
|
||||||
|
|||||||
@@ -96,6 +96,13 @@ void symbol_type_set PARAMS ((symbol_t *symbol, char *type_name));
|
|||||||
void symbol_precedence_set PARAMS ((symbol_t *symbol,
|
void symbol_precedence_set PARAMS ((symbol_t *symbol,
|
||||||
int prec, associativity assoc));
|
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
|
/* Distinguished symbols. AXIOM is the real start symbol, that used
|
||||||
by the automaton. STARTSYMBOL is the one specified by the user.
|
by the automaton. STARTSYMBOL is the one specified by the user.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user