X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/b7c49edf135cea5dc2bd0942b42d28e6c84cf71f..e7b8bef1b1fa6eae346c4a3ee00e897a4d6f9058:/src/reader.c diff --git a/src/reader.c b/src/reader.c index c5f3b11e..bebbc153 100644 --- a/src/reader.c +++ b/src/reader.c @@ -71,6 +71,7 @@ static int lastprec; static bucket *errtoken = NULL; static bucket *undeftoken = NULL; static bucket *eoftoken = NULL; +static bucket *axiom = NULL; static symbol_list * symbol_list_new (bucket *sym) @@ -1450,12 +1451,8 @@ readgram (void) t = lex (); } - /* 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")); @@ -1471,6 +1468,25 @@ readgram (void) bp->value = nvars++; } + /* Insert the initial rule, which line is that of the first rule + (not that of the start symbol): + + axiom: %start EOF. */ + p = symbol_list_new (axiom); + p->line = grammar->line; + p->next = symbol_list_new (startval); + p->next->next = symbol_list_new (eoftoken); + p->next->next->next = symbol_list_new (NULL); + p->next->next->next->next = grammar; + nrules += 1; + nitems += 3; + grammar = p; + startval = axiom; + + if (nsyms > MAXSHORT) + fatal (_("too many symbols (tokens plus nonterminals); maximum %d"), + MAXSHORT); + ntokens = nsyms - nvars; } @@ -1764,6 +1780,8 @@ packgram (void) } ritem[itemno] = 0; + nritems = itemno; + assert (nritems == nitems); if (trace_flag) ritem_print (stderr); @@ -1805,6 +1823,11 @@ reader (void) /* Initialize the symbol table. */ tabinit (); + /* Construct the axiom symbol. */ + axiom = getsym ("$axiom"); + axiom->class = nterm_sym; + axiom->value = nvars++; + /* Construct the error token */ errtoken = getsym ("error"); errtoken->class = token_sym;