* src/LR0.c (new_state): Display `nstates' as the name of the

newly created state.
Adjust to initialize first_state and last_state if needed.
Be sure to distinguish the initial from the final state.
(new_states): Create the itemset of the initial state, and use
new_state.
* src/closure.c (closure): Now that the initial state has its
items properly set, there is no need for a special case when
creating `ruleset'.
As a result, now the rule 0, reducing to $axiom, is visible in the
outputs.  Adjust the test suite.
* tests/conflicts.at (Solved SR Conflicts)
(Unresolved SR Conflicts): Adjust.
* tests/regression.at (Web2c Report, Rule Line Numbers): Idem.
* tests/conflicts.at (S/R in initial): New.
This commit is contained in:
Akim Demaille
2002-04-07 17:40:16 +00:00
parent b4c4ccc2b3
commit 643a599471
7 changed files with 81 additions and 23 deletions

View File

@@ -35,7 +35,7 @@
#include "lalr.h"
#include "reduce.h"
unsigned int nstates;
unsigned int nstates = 0;
/* 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,
@@ -190,7 +190,7 @@ new_state (int symbol)
if (trace_flag)
fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n",
this_state->number, symbol, symbols[symbol]->tag);
nstates, symbol, symbols[symbol]->tag);
if (nstates >= MAXSHORT)
fatal (_("too many states (max %d)"), MAXSHORT);
@@ -202,14 +202,19 @@ new_state (int symbol)
shortcpy (p->items, kernel_base[symbol], kernel_size[symbol]);
last_state->next = p;
last_state = p;
nstates++;
/* If this is the eoftoken, then this is the final state. */
if (symbol == 0)
/* If this is the eoftoken, and this is not the initial state, then
this is the final state. */
if (symbol == 0 && first_state)
final_state = p->number;
if (!first_state)
first_state = p;
if (last_state)
last_state->next = p;
last_state = p;
nstates++;
return p;
}
@@ -317,8 +322,10 @@ append_states (void)
static void
new_states (void)
{
first_state = last_state = this_state = STATE_ALLOC (0);
nstates = 1;
/* The 0 at the lhs is the index of the item of this initial rule. */
kernel_base[0][0] = 0;
kernel_size[0] = 1;
this_state = new_state (0);
}

View File

@@ -244,18 +244,11 @@ closure (short *core, int n)
if (trace_flag)
print_closure ("input", core, n);
if (n == 0)
{
bitset_copy (ruleset, FDERIVES (start_symbol));
}
else
{
bitset_zero (ruleset);
bitset_zero (ruleset);
for (c = 0; c < n; ++c)
if (ISVAR (ritem[core[c]]))
bitset_or (ruleset, ruleset, FDERIVES (ritem[core[c]]));
}
for (c = 0; c < n; ++c)
if (ISVAR (ritem[core[c]]))
bitset_or (ruleset, ruleset, FDERIVES (ritem[core[c]]));
nitemset = 0;
c = 0;