+2001-12-29 Akim Demaille <akim@epita.fr>
+
+ * src/LR0.c, src/conflicts.c, src/lalr.c, src/lalr.h, src/output.c
+ * src/print.c, src/print_graph.c, src/state.h: Rename state_table
+ as states.
+
+
2001-12-29 Akim Demaille <akim@epita.fr>
* src/lalr.c (build_relations): Rename `states' as `states1'.
\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;
}
}
free_closure ();
free_storage ();
- /* Set up STATE_TABLE. */
- set_state_table ();
+ /* Set up STATES. */
+ set_states ();
}
lookaheadset = XCALLOC (unsigned, tokensetsize);
for (i = 0; i < nstates; i++)
- set_conflicts (state_table[i]);
+ set_conflicts (states[i]);
}
if (conflicts[i])
{
fprintf (out, _("State %d contains "), i);
- fputs (conflict_report (count_sr_conflicts (state_table[i]),
- count_rr_conflicts (state_table[i])), out);
+ fputs (conflict_report (count_sr_conflicts (states[i]),
+ count_rr_conflicts (states[i])), out);
printed_sth = TRUE;
}
if (printed_sth)
for (i = 0; i < nstates; i++)
if (conflicts[i])
{
- src_total += count_sr_conflicts (state_table[i]);
- rrc_total += count_rr_conflicts (state_table[i]);
+ src_total += count_sr_conflicts (states[i]);
+ rrc_total += count_rr_conflicts (states[i]);
}
src_ok = src_total == (expected_conflicts == -1 ? 0 : expected_conflicts);
#include "getargs.h"
/* All the decorated states, indexed by the state number. */
-state_t **state_table = NULL;
+state_t **states = NULL;
int tokensetsize;
short *LAruleno;
np = LAruleno;
for (i = 0; i < nstates; i++)
- if (!state_table[i]->consistent)
- for (j = 0; j < state_table[i]->reductions->nreds; j++)
- *np++ = state_table[i]->reductions->rules[j];
+ if (!states[i]->consistent)
+ for (j = 0; j < states[i]->reductions->nreds; j++)
+ *np++ = states[i]->reductions->rules[j];
}
ngotos = 0;
for (state = 0; state < nstates; ++state)
{
- shifts *sp = state_table[state]->shifts;
+ shifts *sp = states[state]->shifts;
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)
{
if (ngotos == MAXSHORT)
for (state = 0; state < nstates; ++state)
{
- shifts *sp = state_table[state]->shifts;
+ shifts *sp = states[state]->shifts;
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)
{
int k = temp_map[SHIFT_SYMBOL (sp, i)]++;
for (i = 0; i < ngotos; i++)
{
int stateno = to_state[i];
- shifts *sp = state_table[stateno]->shifts;
+ shifts *sp = states[stateno]->shifts;
int j;
for (j = 0; j < sp->nshifts && SHIFT_IS_SHIFT (sp, j); j++)
for (i = 0; i < ngotos; i++)
{
int nedges = 0;
- int symbol1 = state_table[to_state[i]]->accessing_symbol;
+ int symbol1 = states[to_state[i]]->accessing_symbol;
short *rulep;
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
int done;
int length = 1;
short *rp;
- state_t *state = state_table[from_state[i]];
+ state_t *state = states[from_state[i]];
states1[0] = state->number;
for (rp = &ritem[rules[*rulep].rhs]; *rp >= 0; rp++)
int j;
for (j = 0; j < sp->nshifts; j++)
{
- state = state_table[sp->shifts[j]];
+ state = states[sp->shifts[j]];
if (state->accessing_symbol == *rp)
break;
}
{
int k;
int nlookaheads = 0;
- reductions *rp = state_table[i]->reductions;
- shifts *sp = state_table[i]->shifts;
+ reductions *rp = states[i]->reductions;
+ shifts *sp = states[i]->shifts;
/* We need a lookahead either to distinguish different
reductions (i.e., there are two or more), or to distinguish a
|| (rp->nreds == 1 && sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))
nlookaheads += rp->nreds;
else
- state_table[i]->consistent = 1;
+ states[i]->consistent = 1;
for (k = 0; k < sp->nshifts; k++)
if (SHIFT_IS_ERROR (sp, k))
{
- state_table[i]->consistent = 0;
+ states[i]->consistent = 0;
break;
}
- state_table[i]->nlookaheads = nlookaheads;
- state_table[i]->lookaheadsp = nLA;
+ states[i]->nlookaheads = nlookaheads;
+ states[i]->lookaheadsp = nLA;
nLA += nlookaheads;
}
}
for (i = 0; i < nstates; ++i)
{
fprintf (out, "State %d: %d lookaheads\n",
- i, state_table[i]->nlookaheads);
+ i, states[i]->nlookaheads);
- for (j = 0; j < state_table[i]->nlookaheads; ++j)
+ for (j = 0; j < states[i]->nlookaheads; ++j)
for (k = 0; k < ntokens; ++k)
- if (BITISSET (LA (state_table[i]->lookaheadsp + j), j))
+ if (BITISSET (LA (states[i]->lookaheadsp + j), j))
fprintf (out, " on %d (%s) -> rule %d\n",
k, symbols[k]->tag,
- -LAruleno[state_table[i]->lookaheadsp + j] - 1);
+ -LAruleno[states[i]->lookaheadsp + j] - 1);
}
fprintf (out, "Lookaheads: END\n");
}
/* All the states, indexed by the state number. */
-extern state_t **state_table;
+extern state_t **states;
extern int tokensetsize;
int i;
short *values = (short *) alloca (sizeof (short) * nstates);
for (i = 0; i < nstates; ++i)
- values[i] = state_table[i]->accessing_symbol;
+ values[i] = states[i]->accessing_symbol;
output_table_data (&format_obstack, values,
0, 1, nstates);
muscle_insert ("stos", obstack_finish (&format_obstack));
if (!shift_state)
continue;
- symbol = state_table[shift_state]->accessing_symbol;
+ symbol = states[shift_state]->accessing_symbol;
if (ISVAR (symbol))
break;
actrow = XCALLOC (short, ntokens);
for (i = 0; i < nstates; ++i)
{
- yydefact[i] = action_row (state_table[i]);
+ yydefact[i] = action_row (states[i]);
save_row (i);
}
for (i = 0; i < nstates; ++i)
{
- free (state_table[i]->shifts);
- XFREE (state_table[i]->reductions);
- free (state_table[i]->errs);
- free (state_table[i]);
+ free (states[i]->shifts);
+ XFREE (states[i]->reductions);
+ free (states[i]->errs);
+ free (states[i]);
}
- XFREE (state_table);
+ XFREE (states);
}
\f
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- int symbol = state_table[state1]->accessing_symbol;
+ int symbol = states[state1]->accessing_symbol;
fprintf (out,
_(" %-4s\tshift, and go to state %d\n"),
escape (symbols[symbol]->tag), state1);
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- int symbol = state_table[state1]->accessing_symbol;
+ int symbol = states[state1]->accessing_symbol;
fprintf (out, _(" %-4s\tgo to state %d\n"),
escape (symbols[symbol]->tag), state1);
}
shiftset = XCALLOC (unsigned, tokensetsize);
lookaheadset = XCALLOC (unsigned, tokensetsize);
for (i = 0; i < nstates; i++)
- print_state (out, state_table[i]);
+ print_state (out, states[i]);
free (shiftset);
free (lookaheadset);
if (trace_flag)
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- int symbol = state_table[state1]->accessing_symbol;
+ int symbol = states[state1]->accessing_symbol;
new_edge (&edge);
/* Output nodes and edges. */
new_closure (nritems);
for (i = 0; i < nstates; i++)
- print_state (state_table[i]);
+ print_state (states[i]);
free_closure ();
/* Close graph. */
case of gotos. */
#define SHIFT_SYMBOL(Shifts, Shift) \
- (state_table[Shifts->shifts[Shift]]->accessing_symbol)
+ (states[Shifts->shifts[Shift]]->accessing_symbol)
/* Is the SHIFTS->shifts[Shift] a real shift? (as opposed to gotos.) */