X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/8b752b00fdaaa3802e4ab05a468f6cda4a9fa500..c0ad8bf3c2fb46f001bb24ac98a72b8bfb3a77ce:/src/LR0.c?ds=inline diff --git a/src/LR0.c b/src/LR0.c index a7a62e59..7dd7b441 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -1,5 +1,7 @@ /* Generate the nondeterministic finite state machine for bison, - Copyright 1984, 1986, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. + + Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 Free Software + Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -59,11 +61,11 @@ 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); - /* If this is the eoftoken, and this is not the initial state, then + /* If this is the endtoken, and this is not the initial state, then this is the final state. */ if (symbol == 0 && first_state) final_state = state; @@ -83,8 +85,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; @@ -105,7 +107,7 @@ allocate_itemsets (void) int count = 0; short *symbol_count = XCALLOC (short, nsyms + nuseless_nonterminals); - for (r = 1; r < nrules + 1; ++r) + for (r = 0; r < nrules; ++r) for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) { count++; @@ -139,8 +141,8 @@ allocate_storage (void) { allocate_itemsets (); - shiftset = XCALLOC (state_number_t, nsyms); - redset = XCALLOC (short, nrules + 1); + shiftset = XCALLOC (state_t *, nsyms); + redset = XCALLOC (rule_t *, nrules); state_hash_new (); shift_symbol = XCALLOC (symbol_number_t, nsyms); } @@ -177,7 +179,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 +206,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 +225,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. | -| | -| TRANSITIONSET 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 +245,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 +284,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 EOF .'. */ - 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; + redset[count++] = &rules[item_number_as_rule_number (item)]; } /* Make a reductions structure and copy the data into it. */ @@ -356,7 +353,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);