X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/88bce5a2ef15e5b508749e75ddad709aca85b019..8434f2222ee028206633ecee9d2336103414b53c:/src/LR0.c diff --git a/src/LR0.c b/src/LR0.c index fa33906e..d7134aab 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -59,7 +59,7 @@ state_list_append (symbol_number_t symbol, state_list_t *node = XMALLOC (state_list_t, 1); state_t *state = state_new (symbol, core_size, core); - if (trace_flag) + if (trace_flag & trace_automaton) fprintf (stderr, "state_list_append (state = %d, symbol = %d (%s))\n", nstates, symbol, symbols[symbol]->tag); @@ -83,8 +83,8 @@ state_list_append (symbol_number_t symbol, static int nshifts; static symbol_number_t *shift_symbol = NULL; -static short *redset = NULL; -static state_number_t *shiftset = NULL; +static rule_t **redset = NULL; +static state_t **shiftset = NULL; static item_number_t **kernel_base = NULL; static int *kernel_size = NULL; @@ -139,8 +139,8 @@ allocate_storage (void) { allocate_itemsets (); - shiftset = XCALLOC (state_number_t, nsyms); - redset = XCALLOC (short, nrules); + shiftset = XCALLOC (state_t *, nsyms); + redset = XCALLOC (rule_t *, nrules); state_hash_new (); shift_symbol = XCALLOC (symbol_number_t, nsyms); } @@ -177,7 +177,7 @@ new_itemsets (state_t *state) { int i; - if (trace_flag) + if (trace_flag & trace_automaton) fprintf (stderr, "Entering new_itemsets, state = %d\n", state->number); @@ -204,18 +204,18 @@ new_itemsets (state_t *state) -/*--------------------------------------------------------------. -| Find the state number for the state we would get to (from the | -| current state) by shifting symbol. Create a new state if no | -| equivalent one exists already. Used by append_states. | -`--------------------------------------------------------------*/ +/*-----------------------------------------------------------------. +| Find the state we would get to (from the current state) by | +| shifting SYMBOL. Create a new state if no equivalent one exists | +| already. Used by append_states. | +`-----------------------------------------------------------------*/ -static state_number_t +static state_t * get_state (symbol_number_t symbol, size_t core_size, item_number_t *core) { state_t *sp; - if (trace_flag) + if (trace_flag & trace_automaton) fprintf (stderr, "Entering get_state, symbol = %d (%s)\n", symbol, symbols[symbol]->tag); @@ -223,18 +223,18 @@ get_state (symbol_number_t symbol, size_t core_size, item_number_t *core) if (!sp) sp = state_list_append (symbol, core_size, core); - if (trace_flag) + if (trace_flag & trace_automaton) fprintf (stderr, "Exiting get_state => %d\n", sp->number); - return sp->number; + return sp; } -/*------------------------------------------------------------------. -| Use the information computed by new_itemsets to find the state | -| numbers reached by each shift transition from STATE. | -| | -| SHIFTSET is set up as a vector of state numbers of those states. | -`------------------------------------------------------------------*/ +/*---------------------------------------------------------------. +| Use the information computed by new_itemsets to find the state | +| numbers reached by each shift transition from STATE. | +| | +| SHIFTSET is set up as a vector of those states. | +`---------------------------------------------------------------*/ static void append_states (state_t *state) @@ -243,7 +243,7 @@ append_states (state_t *state) int j; symbol_number_t symbol; - if (trace_flag) + if (trace_flag & trace_automaton) fprintf (stderr, "Entering append_states, state = %d\n", state->number); @@ -282,17 +282,12 @@ save_reductions (state_t *state) int count = 0; int i; - /* If this is the final state, we want it to have no reductions at - all, although it has one for `START_SYMBOL $end .'. */ - if (final_state && state->number == final_state->number) - return; - /* Find and count the active items that represent ends of rules. */ for (i = 0; i < nritemset; ++i) { int item = ritem[itemset[i]]; if (item < 0) - redset[count++] = item_number_as_rule_number (item); + redset[count++] = &rules[item_number_as_rule_number (item)]; } /* Make a reductions structure and copy the data into it. */ @@ -356,7 +351,7 @@ generate_states (void) while (list) { state_t *state = list->state; - if (trace_flag) + if (trace_flag & trace_automaton) fprintf (stderr, "Processing state %d (reached by %s)\n", state->number, symbols[state->accessing_symbol]->tag);