X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/57339f04218c038243c84b33938c362f29b83f07..e89a22bfab22e4d2ee73be49dcb66b51f8d0e892:/src/LR0.c diff --git a/src/LR0.c b/src/LR0.c index 94a2ed84..3fa5ba5b 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -141,7 +141,6 @@ static void new_itemsets (void) { int i; - int shiftcount; if (trace_flag) fprintf (stderr, "Entering new_itemsets, state = %d\n", @@ -151,25 +150,23 @@ new_itemsets (void) kernel_size[i] = 0; shift_symbol = XCALLOC (short, nsyms); - shiftcount = 0; + nshifts = 0; - for (i = 0; i < itemsetsize; ++i) + for (i = 0; i < nitemset; ++i) { int symbol = ritem[itemset[i]]; if (symbol > 0) { if (!kernel_size[symbol]) { - shift_symbol[shiftcount] = symbol; - shiftcount++; + shift_symbol[nshifts] = symbol; + nshifts++; } kernel_base[symbol][kernel_size[symbol]] = itemset[i] + 1; kernel_size[symbol]++; } } - - nshifts = shiftcount; } @@ -314,19 +311,6 @@ new_states (void) } -/*---------------------------------. -| Create a new array of N shitfs. | -`---------------------------------*/ - -static shifts * -shifts_new (int n) -{ - shifts *res = SHIFTS_ALLOC (n); - res->nshifts = n; - return res; -} - - /*------------------------------------------------------------. | Save the NSHIFTS of SHIFTSET into the current linked list. | `------------------------------------------------------------*/ @@ -393,7 +377,7 @@ augment_automaton (void) sp = first_shift; - if (!sp) + if (!sp->nshifts) { /* There are no shifts for any state. Make one shift, from the initial state to the next-to-final state. */ @@ -555,7 +539,7 @@ save_reductions (void) /* Find and count the active items that represent ends of rules. */ count = 0; - for (i = 0; i < itemsetsize; ++i) + for (i = 0; i < nitemset; ++i) { int item = ritem[itemset[i]]; if (item < 0) @@ -596,6 +580,9 @@ generate_states (void) while (this_state) { + if (trace_flag) + fprintf (stderr, "Processing state %d (reached by %s)\n", + this_state->number, tags[this_state->accessing_symbol]); /* 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 @@ -610,8 +597,7 @@ generate_states (void) /* create the shifts structures for the shifts to those states, now that the state numbers transitioning to are known */ - if (nshifts > 0) - save_shifts (); + save_shifts (); /* states are queued when they are created; process them all */ this_state = this_state->next;