X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/30171f79ab0aaad06b88a66653789691c4ed4f2c..091e20bbee87fc6e5b1e9e2938767c6e89b19035:/src/LR0.c diff --git a/src/LR0.c b/src/LR0.c index c1a0a8c1..e914c6ef 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -23,6 +23,7 @@ The entry point is generate_states. */ #include "system.h" +#include "symtab.h" #include "getargs.h" #include "reader.h" #include "gram.h" @@ -34,7 +35,14 @@ #include "reduce.h" int nstates; -int final_state; +/* Initialize the final state to -1, otherwise, it might be set to 0 + by default, and since we don't compute the reductions of the final + state, we end up not computing the reductions of the initial state, + which is of course needed. + + FINAL_STATE is properly set by new_state when it recognizes the + accessing symbol: EOF. */ +int final_state = -1; static state_t *first_state = NULL; static state_t *this_state = NULL; @@ -105,6 +113,7 @@ allocate_storage (void) shiftset = XCALLOC (short, nsyms); redset = XCALLOC (short, nrules + 1); state_hash = XCALLOC (state_t *, STATE_HASH_SIZE); + shift_symbol = XCALLOC (short, nsyms); } @@ -146,7 +155,6 @@ new_itemsets (void) for (i = 0; i < nsyms; i++) kernel_size[i] = 0; - shift_symbol = XCALLOC (short, nsyms); nshifts = 0; for (i = 0; i < nitemset; ++i) @@ -180,7 +188,7 @@ new_state (int symbol) if (trace_flag) fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n", - this_state->number, symbol, tags[symbol]); + this_state->number, symbol, symbols[symbol]->tag); if (nstates >= MAXSHORT) fatal (_("too many states (max %d)"), MAXSHORT); @@ -219,7 +227,7 @@ get_state (int symbol) if (trace_flag) fprintf (stderr, "Entering get_state, state = %d, symbol = %d (%s)\n", - this_state->number, symbol, tags[symbol]); + this_state->number, symbol, symbols[symbol]->tag); /* Add up the target state's active item numbers to get a hash key. */ @@ -357,14 +365,14 @@ save_reductions (void) /*--------------------. -| Build STATE_TABLE. | +| Build STATES. | `--------------------*/ static void -set_state_table (void) +set_states (void) { state_t *sp; - state_table = XCALLOC (state_t *, nstates); + states = XCALLOC (state_t *, nstates); for (sp = first_state; sp; sp = sp->next) { @@ -378,7 +386,7 @@ set_state_table (void) if (!sp->reductions) sp->reductions = reductions_new (0); - state_table[sp->number] = sp; + states[sp->number] = sp; } } @@ -391,14 +399,15 @@ void generate_states (void) { allocate_storage (); - new_closure (nitems); + new_closure (nritems); new_states (); while (this_state) { if (trace_flag) fprintf (stderr, "Processing state %d (reached by %s)\n", - this_state->number, tags[this_state->accessing_symbol]); + this_state->number, + symbols[this_state->accessing_symbol]->tag); /* Set up ruleset and itemset for the transitions out of this state. ruleset gets a 1 bit for each rule that could reduce now. itemset gets a vector of all the items that could be @@ -423,6 +432,6 @@ generate_states (void) free_closure (); free_storage (); - /* Set up STATE_TABLE. */ - set_state_table (); + /* Set up STATES. */ + set_states (); }