X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/091e20bbee87fc6e5b1e9e2938767c6e89b19035..d7e1f00c136e256e51f088ef6f1a11db11fcee72:/src/reader.c diff --git a/src/reader.c b/src/reader.c index 9816c61d..b09d9f6c 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1,5 +1,5 @@ /* 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. @@ -559,7 +559,7 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not) 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) { @@ -759,6 +759,7 @@ parse_union_decl (void) typed = 1; + MUSCLE_INSERT_INT ("stype_line", lineno); obstack_init (&union_obstack); obstack_sgrow (&union_obstack, "union"); @@ -1154,10 +1155,7 @@ parse_braces (symbol_list *rule, int stack_offset) /* 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'); @@ -1204,7 +1202,7 @@ gensym (void) token_buffer = buf; sym = getsym (token_buffer); sym->class = nterm_sym; - sym->value = nvars++; + sym->number = nvars++; return sym; } @@ -1296,7 +1294,7 @@ readgram (void) if (lhs->class == unknown_sym) { lhs->class = nterm_sym; - lhs->value = nvars; + lhs->number = nvars; nvars++; } else if (lhs->class == token_sym) @@ -1329,7 +1327,10 @@ readgram (void) unlex (t1); symval = ssave; if (t1 == tok_colon) - break; + { + warn (_("previous rule lacks an ending `;'")); + break; + } if (!first_rhs) /* JF */ first_rhs = symval; @@ -1445,6 +1446,8 @@ readgram (void) /* 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 (); } @@ -1468,7 +1471,7 @@ readgram (void) ("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 @@ -1499,7 +1502,7 @@ readgram (void) static void read_additionnal_code (void) { - char c; + int c; struct obstack el_obstack; obstack_init (&el_obstack); @@ -1535,13 +1538,13 @@ token_translations_init (void) /* 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) @@ -1554,7 +1557,7 @@ token_translations_init (void) 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; } } @@ -1580,20 +1583,20 @@ packsymbols (void) { 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++; } } @@ -1629,9 +1632,9 @@ packsymbols (void) 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) @@ -1642,25 +1645,25 @@ packsymbols (void) max_user_token_number = bp->user_token_number; } - symbols[bp->value] = bp; + 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; + start_symbol = startval->number; } /*---------------------------------------------------------------. | Convert the rules into the representation using RRHS, RLHS and | -| RITEMS. | +| RITEM. | `---------------------------------------------------------------*/ static void @@ -1684,8 +1687,10 @@ packgram (void) while (p) { bucket *ruleprec = p->ruleprec; - rules[ruleno].lhs = p->sym->value; - rules[ruleno].rhs = itemno; + 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; @@ -1696,7 +1701,7 @@ packgram (void) 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) @@ -1714,7 +1719,7 @@ packgram (void) { rules[ruleno].prec = ruleprec->prec; rules[ruleno].assoc = ruleprec->assoc; - rules[ruleno].precsym = ruleprec->value; + rules[ruleno].precsym = ruleprec->number; } ritem[itemno++] = -ruleno; @@ -1771,7 +1776,7 @@ reader (void) /* Construct the axiom symbol. */ axiom = getsym ("$axiom"); axiom->class = nterm_sym; - axiom->value = nvars++; + axiom->number = nvars++; /* Construct the error token */ errtoken = getsym ("error"); @@ -1824,3 +1829,12 @@ reader (void) /* 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 (); +}