X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/ff44279401d71c061f2dc315a381ce2aeeb33a61..29e8831621af57c5056380b68a96337e7647b850:/src/reader.c diff --git a/src/reader.c b/src/reader.c index fcfb2c94..d76bd6fe 100644 --- a/src/reader.c +++ b/src/reader.c @@ -52,8 +52,6 @@ typedef struct symbol_list } symbol_list; int lineno; -char **tags; -short *user_toknums; static symbol_list *grammar; static int start_flag; static bucket *startval; @@ -1451,6 +1449,23 @@ readgram (void) t = lex (); } + /* grammar has been read. Do some checking */ + + if (nrules == 0) + fatal (_("no rules in the input grammar")); + + /* Report any undefined symbols and consider them nonterminals. */ + + for (bp = firstsymbol; bp; bp = bp->next) + if (bp->class == unknown_sym) + { + complain (_ + ("symbol %s is used, but is not defined as a token and has no rules"), + bp->tag); + bp->class = nterm_sym; + bp->value = nvars++; + } + /* Insert the initial rule, which line is that of the first rule (not that of the start symbol): @@ -1466,25 +1481,9 @@ readgram (void) grammar = p; startval = axiom; - /* grammar has been read. Do some checking */ - if (nsyms > MAXSHORT) fatal (_("too many symbols (tokens plus nonterminals); maximum %d"), MAXSHORT); - if (nrules == 0) - fatal (_("no rules in the input grammar")); - - /* Report any undefined symbols and consider them nonterminals. */ - - for (bp = firstsymbol; bp; bp = bp->next) - if (bp->class == unknown_sym) - { - complain (_ - ("symbol %s is used, but is not defined as a token and has no rules"), - bp->tag); - bp->class = nterm_sym; - bp->value = nvars++; - } ntokens = nsyms - nvars; } @@ -1548,18 +1547,17 @@ token_translations_init (void) /* A token which translation has already been set? */ if (token_translations[bp->user_token_number] != 2) complain (_("tokens %s and %s both assigned number %d"), - tags[token_translations[bp->user_token_number]], + symbols[token_translations[bp->user_token_number]]->tag, bp->tag, bp->user_token_number); token_translations[bp->user_token_number] = bp->value; } } -/*------------------------------------------------------------------. -| Assign symbol numbers, and write definition of token names into | -| FDEFINES. Set up vectors TAGS and SPREC of names and precedences | -| of symbols. | -`------------------------------------------------------------------*/ +/*----------------------------------------------------------------. +| Assign symbol numbers, and write definition of token names into | +| FDEFINES. Set up vectors SYMBOL_TABLE, TAGS of symbols. | +`----------------------------------------------------------------*/ static void packsymbols (void) @@ -1568,11 +1566,7 @@ packsymbols (void) int tokno = 1; int last_user_token_number; - tags = XCALLOC (char *, nsyms + 1); - user_toknums = XCALLOC (short, nsyms + 1); - - sprec = XCALLOC (short, nsyms); - sassoc = XCALLOC (short, nsyms); + symbols = XCALLOC (bucket *, nsyms); max_user_token_number = 256; last_user_token_number = 256; @@ -1643,10 +1637,7 @@ packsymbols (void) max_user_token_number = bp->user_token_number; } - tags[bp->value] = bp->tag; - user_toknums[bp->value] = bp->user_token_number; - sprec[bp->value] = bp->prec; - sassoc[bp->value] = bp->assoc; + symbols[bp->value] = bp; } token_translations_init (); @@ -1729,7 +1720,7 @@ packgram (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; @@ -1738,14 +1729,14 @@ packgram (void) 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].lhs = p->sym->value; + rules[ruleno].rhs = 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) @@ -1755,8 +1746,8 @@ packgram (void) 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; @@ -1766,9 +1757,9 @@ packgram (void) 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->value; } ritem[itemno++] = -ruleno;