The entry point is generate_states. */
#include "system.h"
+#include "symtab.h"
#include "getargs.h"
#include "reader.h"
#include "gram.h"
#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;
shiftset = XCALLOC (short, nsyms);
redset = XCALLOC (short, nrules + 1);
state_hash = XCALLOC (state_t *, STATE_HASH_SIZE);
+ shift_symbol = XCALLOC (short, nsyms);
}
for (i = 0; i < nsyms; i++)
kernel_size[i] = 0;
- shift_symbol = XCALLOC (short, nsyms);
nshifts = 0;
for (i = 0; i < nitemset; ++i)
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);
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.
*/
\f
/*--------------------.
-| 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)
{
if (!sp->reductions)
sp->reductions = reductions_new (0);
- state_table[sp->number] = sp;
+ states[sp->number] = sp;
}
}
{
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
free_closure ();
free_storage ();
- /* Set up STATE_TABLE. */
- set_state_table ();
+ /* Set up STATES. */
+ set_states ();
}