* 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.
This commit is contained in:
Akim Demaille
2001-12-29 14:20:47 +00:00
parent b9f71f19cc
commit 29e8831621
9 changed files with 53 additions and 46 deletions

View File

@@ -1,3 +1,10 @@
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'.

View File

@@ -365,14 +365,14 @@ save_reductions (void)
/*--------------------.
| 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)
{
@@ -386,7 +386,7 @@ set_state_table (void)
if (!sp->reductions)
sp->reductions = reductions_new (0);
state_table[sp->number] = sp;
states[sp->number] = sp;
}
}
@@ -432,6 +432,6 @@ generate_states (void)
free_closure ();
free_storage ();
/* Set up STATE_TABLE. */
set_state_table ();
/* Set up STATES. */
set_states ();
}

View File

@@ -204,7 +204,7 @@ solve_conflicts (void)
lookaheadset = XCALLOC (unsigned, tokensetsize);
for (i = 0; i < nstates; i++)
set_conflicts (state_table[i]);
set_conflicts (states[i]);
}
@@ -327,8 +327,8 @@ conflicts_output (FILE *out)
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)
@@ -357,8 +357,8 @@ conflicts_print (void)
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);

View File

@@ -36,7 +36,7 @@
#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;
@@ -150,9 +150,9 @@ initialize_LA (void)
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];
}
@@ -168,7 +168,7 @@ set_goto_map (void)
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)
@@ -199,7 +199,7 @@ set_goto_map (void)
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)]++;
@@ -260,7 +260,7 @@ initialize_F (void)
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++)
@@ -409,7 +409,7 @@ build_relations (void)
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++)
@@ -417,7 +417,7 @@ build_relations (void)
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++)
@@ -426,7 +426,7 @@ build_relations (void)
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;
}
@@ -522,8 +522,8 @@ initialize_lookaheads (void)
{
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
@@ -533,17 +533,17 @@ initialize_lookaheads (void)
|| (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;
}
}
@@ -561,14 +561,14 @@ lookaheads_print (FILE *out)
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");
}

View File

@@ -70,7 +70,7 @@ extern unsigned *LA;
/* All the states, indexed by the state number. */
extern state_t **state_table;
extern state_t **states;
extern int tokensetsize;

View File

@@ -222,7 +222,7 @@ output_stos (void)
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));
@@ -362,7 +362,7 @@ action_row (state_t *state)
if (!shift_state)
continue;
symbol = state_table[shift_state]->accessing_symbol;
symbol = states[shift_state]->accessing_symbol;
if (ISVAR (symbol))
break;
@@ -486,7 +486,7 @@ token_actions (void)
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);
}
@@ -904,12 +904,12 @@ output_actions (void)
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);
}

View File

@@ -122,7 +122,7 @@ print_shifts (FILE *out, state_t *state)
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);
@@ -164,7 +164,7 @@ print_gotos (FILE *out, state_t *state)
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);
}
@@ -501,7 +501,7 @@ print_results (void)
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)

View File

@@ -114,7 +114,7 @@ print_actions (state_t *state, const char *node_name)
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);
@@ -202,7 +202,7 @@ print_graph (void)
/* 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. */

View File

@@ -107,7 +107,7 @@ shifts *shifts_new PARAMS ((int n));
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.) */