/* Input parser for bison
- Copyright 1984, 1986, 1989, 1992, 1998, 2000, 2001
+ Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
} symbol_list;
int lineno;
-short *user_toknums;
static symbol_list *grammar;
static int start_flag;
static bucket *startval;
complain (_("symbol %s redefined"), symbol->tag);
symbol->class = what_is;
if (what_is == nterm_sym && oldclass != nterm_sym)
- symbol->value = nvars++;
+ symbol->number = nvars++;
if (typename)
{
typed = 1;
+ MUSCLE_INSERT_INT ("stype_line", lineno);
obstack_init (&union_obstack);
obstack_sgrow (&union_obstack, "union");
/* Above loop exits when C is '}'. */
if (--count)
- {
- obstack_1grow (&action_obstack, c);
- c = getc (finput);
- }
+ obstack_1grow (&action_obstack, c);
}
obstack_1grow (&action_obstack, '\0');
token_buffer = buf;
sym = getsym (token_buffer);
sym->class = nterm_sym;
- sym->value = nvars++;
+ sym->number = nvars++;
return sym;
}
\f
if (lhs->class == unknown_sym)
{
lhs->class = nterm_sym;
- lhs->value = nvars;
+ lhs->number = nvars;
nvars++;
}
else if (lhs->class == token_sym)
unlex (t1);
symval = ssave;
if (t1 == tok_colon)
- break;
+ {
+ warn (_("previous rule lacks an ending `;'"));
+ break;
+ }
if (!first_rhs) /* JF */
first_rhs = symval;
p = symbol_list_new (sdummy);
/* Attach its lineno to that of the host rule. */
p->line = crule->line;
+ /* Move the action from the host rule to this one. */
+ p->action = crule->action;
+ p->action_line = crule->action_line;
+ crule->action = NULL;
+
if (crule1)
crule1->next = p;
else
/* Warn if there is no default for $$ but we need one. */
else if (!xactions && !first_rhs && lhs->type_name != 0)
complain (_("empty rule for typed nonterminal, and no action"));
+ if (t == tok_two_percents || t == tok_eof)
+ warn (_("previous rule lacks an ending `;'"));
if (t == tok_semicolon)
t = lex ();
}
("symbol %s is used, but is not defined as a token and has no rules"),
bp->tag);
bp->class = nterm_sym;
- bp->value = nvars++;
+ bp->number = nvars++;
}
/* Insert the initial rule, which line is that of the first rule
static void
read_additionnal_code (void)
{
- char c;
+ int c;
struct obstack el_obstack;
obstack_init (&el_obstack);
/* Initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
inputs. */
- for (i = 0; i <= max_user_token_number; i++)
+ for (i = 0; i < max_user_token_number + 1; i++)
token_translations[i] = 2;
for (bp = firstsymbol; bp; bp = bp->next)
{
/* Non-terminal? */
- if (bp->value >= ntokens)
+ if (bp->number >= ntokens)
continue;
/* A token string alias? */
if (bp->user_token_number == SALIAS)
complain (_("tokens %s and %s both assigned number %d"),
symbols[token_translations[bp->user_token_number]]->tag,
bp->tag, bp->user_token_number);
- token_translations[bp->user_token_number] = bp->value;
+ token_translations[bp->user_token_number] = bp->number;
}
}
int tokno = 1;
int last_user_token_number;
- user_toknums = XCALLOC (short, nsyms + 1);
symbols = XCALLOC (bucket *, nsyms);
- sassoc = XCALLOC (short, nsyms);
-
max_user_token_number = 256;
last_user_token_number = 256;
{
if (bp->class == nterm_sym)
{
- bp->value += ntokens;
+ bp->number += ntokens;
}
else if (bp->alias)
{
/* This symbol and its alias are a single token defn.
Allocate a tokno, and assign to both check agreement of
prec and assoc fields and make both the same */
- if (bp->value == -1)
+ if (bp->number == -1)
{
if (bp == eoftoken || bp->alias == eoftoken)
- bp->value = bp->alias->value = 0;
+ bp->number = bp->alias->number = 0;
else
{
- bp->value = bp->alias->value = tokno++;
+ bp->number = bp->alias->number = tokno++;
}
}
else /* bp->class == token_sym */
{
if (bp == eoftoken)
- bp->value = 0;
+ bp->number = 0;
else
- bp->value = tokno++;
+ bp->number = tokno++;
}
if (bp->class == token_sym)
max_user_token_number = bp->user_token_number;
}
- symbols[bp->value] = bp;
- user_toknums[bp->value] = bp->user_token_number;
- sassoc[bp->value] = bp->assoc;
+ symbols[bp->number] = bp;
}
token_translations_init ();
- error_token_number = errtoken->value;
+ error_token_number = errtoken->number;
if (startval->class == unknown_sym)
fatal (_("the start symbol %s is undefined"), startval->tag);
else if (startval->class == token_sym)
fatal (_("the start symbol %s is a token"), startval->tag);
- start_symbol = startval->value;
-}
-
-
-/*---------------------------------------------------------------.
-| Save the definition of token names in the `TOKENDEFS' muscle. |
-`---------------------------------------------------------------*/
-
-static void
-symbols_save (void)
-{
- struct obstack tokendefs;
- bucket *bp;
- obstack_init (&tokendefs);
-
- for (bp = firstsymbol; bp; bp = bp->next)
- {
- char *symbol = bp->tag; /* get symbol */
-
- if (bp->value >= ntokens)
- continue;
- if (bp->user_token_number == SALIAS)
- continue;
- if ('\'' == *symbol)
- continue; /* skip literal character */
- if (bp == errtoken)
- continue; /* skip error token */
- if ('\"' == *symbol)
- {
- /* use literal string only if given a symbol with an alias */
- if (bp->alias)
- symbol = bp->alias->tag;
- else
- continue;
- }
-
- /* Don't #define nonliteral tokens whose names contain periods. */
- if (strchr (symbol, '.'))
- continue;
-
- obstack_fgrow2 (&tokendefs, "# define %s\t%d\n",
- symbol, bp->user_token_number);
- if (semantic_parser)
- /* FIXME: This is probably wrong, and should be just as
- above. --akim. */
- obstack_fgrow2 (&tokendefs, "# define T%s\t%d\n", symbol, bp->value);
- }
-
- obstack_1grow (&tokendefs, 0);
- muscle_insert ("tokendef", xstrdup (obstack_finish (&tokendefs)));
- obstack_free (&tokendefs, NULL);
+ start_symbol = startval->number;
}
/*---------------------------------------------------------------.
| Convert the rules into the representation using RRHS, RLHS and |
-| RITEMS. |
+| RITEM. |
`---------------------------------------------------------------*/
static void
fatal (_("too many items (max %d)"), MAXSHORT);
ritem = XCALLOC (short, nitems + 1);
- rule_table = XCALLOC (rule_t, nrules) - 1;
+ rules = XCALLOC (rule_t, nrules) - 1;
itemno = 0;
ruleno = 1;
while (p)
{
bucket *ruleprec = p->ruleprec;
- rule_table[ruleno].lhs = p->sym->value;
- rule_table[ruleno].rhs = itemno;
- rule_table[ruleno].line = p->line;
- rule_table[ruleno].useful = TRUE;
- rule_table[ruleno].action = p->action;
- rule_table[ruleno].action_line = p->action_line;
- rule_table[ruleno].guard = p->guard;
- rule_table[ruleno].guard_line = p->guard_line;
+ rules[ruleno].user_number = ruleno;
+ rules[ruleno].number = ruleno;
+ rules[ruleno].lhs = p->sym;
+ rules[ruleno].rhs = ritem + itemno;
+ rules[ruleno].line = p->line;
+ rules[ruleno].useful = TRUE;
+ rules[ruleno].action = p->action;
+ rules[ruleno].action_line = p->action_line;
+ rules[ruleno].guard = p->guard;
+ rules[ruleno].guard_line = p->guard_line;
p = p->next;
while (p && p->sym)
{
- ritem[itemno++] = p->sym->value;
+ ritem[itemno++] = p->sym->number;
/* A rule gets by default the precedence and associativity
of the last token in it. */
if (p->sym->class == token_sym)
{
- rule_table[ruleno].prec = p->sym->prec;
- rule_table[ruleno].assoc = p->sym->assoc;
+ rules[ruleno].prec = p->sym->prec;
+ rules[ruleno].assoc = p->sym->assoc;
}
if (p)
p = p->next;
the specified symbol's precedence replaces the default. */
if (ruleprec)
{
- rule_table[ruleno].prec = ruleprec->prec;
- rule_table[ruleno].assoc = ruleprec->assoc;
- rule_table[ruleno].precsym = ruleprec->value;
+ rules[ruleno].prec = ruleprec->prec;
+ rules[ruleno].assoc = ruleprec->assoc;
+ rules[ruleno].precsym = ruleprec->number;
}
ritem[itemno++] = -ruleno;
/* Construct the axiom symbol. */
axiom = getsym ("$axiom");
axiom->class = nterm_sym;
- axiom->value = nvars++;
+ axiom->number = nvars++;
/* Construct the error token */
errtoken = getsym ("error");
/* Assign the symbols their symbol numbers. Write #defines for the
token symbols into FDEFINES if requested. */
packsymbols ();
- /* Save them. */
- symbols_save ();
/* Convert the grammar into the format described in gram.h. */
packgram ();
+
+ /* The grammar as a symbol_list is no longer needed. */
+ LIST_FREE (symbol_list, grammar);
+}
+
+void
+grammar_free (void)
+{
+ XFREE (ritem);
+ free (rules + 1);
+ /* Free the symbol table data structure. */
+ free_symtab ();
}