mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 00:03:03 +00:00
* src/state.h, src/state.c (shift_t, SHIFT_SYMBOL, SHIFT_IS_SHIFT)
(SHIFT_IS_GOTO, SHIFT_IS_ERROR, SHIFT_DISABLE, SHIFT_IS_DISABLED) (shifts_to): Rename as... (transition_t, TRANSITION_SYMBOL, TRANSITION_IS_TRANSITION) (TRANSITION_IS_GOTO, TRANSITION_IS_ERROR, TRANSITION_DISABLE) (TRANSITION_IS_DISABLED, transitions_to): these.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
|||||||
|
2002-06-30 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/state.h, src/state.c (shift_t, SHIFT_SYMBOL, SHIFT_IS_SHIFT)
|
||||||
|
(SHIFT_IS_GOTO, SHIFT_IS_ERROR, SHIFT_DISABLE, SHIFT_IS_DISABLED)
|
||||||
|
(shifts_to): Rename as...
|
||||||
|
(transition_t, TRANSITION_SYMBOL, TRANSITION_IS_TRANSITION)
|
||||||
|
(TRANSITION_IS_GOTO, TRANSITION_IS_ERROR, TRANSITION_DISABLE)
|
||||||
|
(TRANSITION_IS_DISABLED, transitions_to): these.
|
||||||
|
|
||||||
|
|
||||||
2002-06-30 Akim Demaille <akim@epita.fr>
|
2002-06-30 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/print.c (print_shifts, print_gotos): Merge into...
|
* src/print.c (print_shifts, print_gotos): Merge into...
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ get_state (symbol_number_t symbol, size_t core_size, item_number_t *core)
|
|||||||
| Use the information computed by new_itemsets to find the state |
|
| Use the information computed by new_itemsets to find the state |
|
||||||
| numbers reached by each shift transition from STATE. |
|
| numbers reached by each shift transition from STATE. |
|
||||||
| |
|
| |
|
||||||
| SHIFTSET is set up as a vector of state numbers of those states. |
|
| TRANSITIONSET is set up as a vector of state numbers of those states. |
|
||||||
`------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -336,7 +336,7 @@ set_states (void)
|
|||||||
reduced to 0. */
|
reduced to 0. */
|
||||||
state_t *state = this->state;
|
state_t *state = this->state;
|
||||||
if (!state->shifts)
|
if (!state->shifts)
|
||||||
state_shifts_set (state, 0, 0);
|
state_transitions_set (state, 0, 0);
|
||||||
if (!state->errs)
|
if (!state->errs)
|
||||||
state->errs = errs_new (0);
|
state->errs = errs_new (0);
|
||||||
if (!state->reductions)
|
if (!state->reductions)
|
||||||
@@ -387,7 +387,7 @@ generate_states (void)
|
|||||||
|
|
||||||
/* Create the shifts structures for the shifts to those states,
|
/* Create the shifts structures for the shifts to those states,
|
||||||
now that the state numbers transitioning to are known. */
|
now that the state numbers transitioning to are known. */
|
||||||
state_shifts_set (state, nshifts, shiftset);
|
state_transitions_set (state, nshifts, shiftset);
|
||||||
|
|
||||||
/* States are queued when they are created; process them all.
|
/* States are queued when they are created; process them all.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -139,13 +139,13 @@ log_resolution (rule_t *rule, int token,
|
|||||||
static void
|
static void
|
||||||
flush_shift (state_t *state, int token)
|
flush_shift (state_t *state, int token)
|
||||||
{
|
{
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
bitset_reset (lookaheadset, token);
|
bitset_reset (lookaheadset, token);
|
||||||
for (i = 0; i < shiftp->nshifts; i++)
|
for (i = 0; i < transitions->num; i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i) && SHIFT_SYMBOL (shiftp, i) == token)
|
if (!TRANSITION_IS_DISABLED (transitions, i) && TRANSITION_SYMBOL (transitions, i) == token)
|
||||||
SHIFT_DISABLE (shiftp, i);
|
TRANSITION_DISABLE (transitions, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,17 +249,17 @@ static void
|
|||||||
set_conflicts (state_t *state)
|
set_conflicts (state_t *state)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
shifts_t *shiftp;
|
transitions_t *transitions;
|
||||||
|
|
||||||
if (state->consistent)
|
if (state->consistent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bitset_zero (lookaheadset);
|
bitset_zero (lookaheadset);
|
||||||
|
|
||||||
shiftp = state->shifts;
|
transitions = state->shifts;
|
||||||
for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
|
for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!TRANSITION_IS_DISABLED (transitions, i))
|
||||||
bitset_set (lookaheadset, SHIFT_SYMBOL (shiftp, i));
|
bitset_set (lookaheadset, TRANSITION_SYMBOL (transitions, i));
|
||||||
|
|
||||||
/* Loop over all rules which require lookahead in this state. First
|
/* Loop over all rules which require lookahead in this state. First
|
||||||
check for shift-reduce conflict, and try to resolve using
|
check for shift-reduce conflict, and try to resolve using
|
||||||
@@ -308,17 +308,17 @@ count_sr_conflicts (state_t *state)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int src_count = 0;
|
int src_count = 0;
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
|
|
||||||
if (!shiftp)
|
if (!transitions)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bitset_zero (lookaheadset);
|
bitset_zero (lookaheadset);
|
||||||
bitset_zero (shiftset);
|
bitset_zero (shiftset);
|
||||||
|
|
||||||
for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
|
for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!TRANSITION_IS_DISABLED (transitions, i))
|
||||||
bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
|
bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i));
|
||||||
|
|
||||||
for (i = 0; i < state->nlookaheads; ++i)
|
for (i = 0; i < state->nlookaheads; ++i)
|
||||||
bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]);
|
bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]);
|
||||||
|
|||||||
34
src/lalr.c
34
src/lalr.c
@@ -94,15 +94,15 @@ set_goto_map (void)
|
|||||||
ngotos = 0;
|
ngotos = 0;
|
||||||
for (state = 0; state < nstates; ++state)
|
for (state = 0; state < nstates; ++state)
|
||||||
{
|
{
|
||||||
shifts_t *sp = states[state]->shifts;
|
transitions_t *sp = states[state]->shifts;
|
||||||
int i;
|
int i;
|
||||||
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)
|
for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
|
||||||
{
|
{
|
||||||
if (ngotos == SHRT_MAX)
|
if (ngotos == SHRT_MAX)
|
||||||
fatal (_("too many gotos (max %d)"), SHRT_MAX);
|
fatal (_("too many gotos (max %d)"), SHRT_MAX);
|
||||||
|
|
||||||
ngotos++;
|
ngotos++;
|
||||||
goto_map[SHIFT_SYMBOL (sp, i)]++;
|
goto_map[TRANSITION_SYMBOL (sp, i)]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,13 +127,13 @@ set_goto_map (void)
|
|||||||
|
|
||||||
for (state = 0; state < nstates; ++state)
|
for (state = 0; state < nstates; ++state)
|
||||||
{
|
{
|
||||||
shifts_t *sp = states[state]->shifts;
|
transitions_t *sp = states[state]->shifts;
|
||||||
int i;
|
int i;
|
||||||
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)
|
for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
|
||||||
{
|
{
|
||||||
int k = temp_map[SHIFT_SYMBOL (sp, i)]++;
|
int k = temp_map[TRANSITION_SYMBOL (sp, i)]++;
|
||||||
from_state[k] = state;
|
from_state[k] = state;
|
||||||
to_state[k] = sp->shifts[i];
|
to_state[k] = sp->states[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,15 +189,15 @@ initialize_F (void)
|
|||||||
for (i = 0; i < ngotos; i++)
|
for (i = 0; i < ngotos; i++)
|
||||||
{
|
{
|
||||||
state_number_t stateno = to_state[i];
|
state_number_t stateno = to_state[i];
|
||||||
shifts_t *sp = states[stateno]->shifts;
|
transitions_t *sp = states[stateno]->shifts;
|
||||||
|
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < sp->nshifts && SHIFT_IS_SHIFT (sp, j); j++)
|
for (j = 0; j < sp->num && TRANSITION_IS_SHIFT (sp, j); j++)
|
||||||
bitset_set (F[i], SHIFT_SYMBOL (sp, j));
|
bitset_set (F[i], TRANSITION_SYMBOL (sp, j));
|
||||||
|
|
||||||
for (; j < sp->nshifts; j++)
|
for (; j < sp->num; j++)
|
||||||
{
|
{
|
||||||
symbol_number_t symbol = SHIFT_SYMBOL (sp, j);
|
symbol_number_t symbol = TRANSITION_SYMBOL (sp, j);
|
||||||
if (nullable[symbol])
|
if (nullable[symbol])
|
||||||
edge[nedges++] = map_goto (stateno, symbol);
|
edge[nedges++] = map_goto (stateno, symbol);
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ build_relations (void)
|
|||||||
|
|
||||||
for (rp = rules[*rulep].rhs; *rp >= 0; rp++)
|
for (rp = rules[*rulep].rhs; *rp >= 0; rp++)
|
||||||
{
|
{
|
||||||
state = shifts_to (state->shifts,
|
state = transitions_to (state->shifts,
|
||||||
item_number_as_symbol_number (*rp));
|
item_number_as_symbol_number (*rp));
|
||||||
states1[length++] = state->number;
|
states1[length++] = state->number;
|
||||||
}
|
}
|
||||||
@@ -360,20 +360,20 @@ states_lookaheads_count (void)
|
|||||||
int k;
|
int k;
|
||||||
int nlookaheads = 0;
|
int nlookaheads = 0;
|
||||||
reductions_t *rp = states[i]->reductions;
|
reductions_t *rp = states[i]->reductions;
|
||||||
shifts_t *sp = states[i]->shifts;
|
transitions_t *sp = states[i]->shifts;
|
||||||
|
|
||||||
/* We need a lookahead either to distinguish different
|
/* We need a lookahead either to distinguish different
|
||||||
reductions (i.e., there are two or more), or to distinguish a
|
reductions (i.e., there are two or more), or to distinguish a
|
||||||
reduction from a shift. Otherwise, it is straightforward,
|
reduction from a shift. Otherwise, it is straightforward,
|
||||||
and the state is `consistent'. */
|
and the state is `consistent'. */
|
||||||
if (rp->nreds > 1
|
if (rp->nreds > 1
|
||||||
|| (rp->nreds == 1 && sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))
|
|| (rp->nreds == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0)))
|
||||||
nlookaheads += rp->nreds;
|
nlookaheads += rp->nreds;
|
||||||
else
|
else
|
||||||
states[i]->consistent = 1;
|
states[i]->consistent = 1;
|
||||||
|
|
||||||
for (k = 0; k < sp->nshifts; k++)
|
for (k = 0; k < sp->num; k++)
|
||||||
if (SHIFT_IS_ERROR (sp, k))
|
if (TRANSITION_IS_ERROR (sp, k))
|
||||||
{
|
{
|
||||||
states[i]->consistent = 0;
|
states[i]->consistent = 0;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include "bitset.h"
|
#include "bitset.h"
|
||||||
#include "bitsetv.h"
|
#include "bitsetv.h"
|
||||||
|
|
||||||
/* Import the definition of CORE, SHIFTS and REDUCTIONS. */
|
/* Import the definition of CORE, TRANSITIONS and REDUCTIONS. */
|
||||||
# include "state.h"
|
# include "state.h"
|
||||||
|
|
||||||
/* Import the definition of RULE_T. */
|
/* Import the definition of RULE_T. */
|
||||||
|
|||||||
10
src/output.c
10
src/output.c
@@ -430,7 +430,7 @@ action_row (state_t *state)
|
|||||||
int i;
|
int i;
|
||||||
rule_number_t default_rule = 0;
|
rule_number_t default_rule = 0;
|
||||||
reductions_t *redp = state->reductions;
|
reductions_t *redp = state->reductions;
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
errs_t *errp = state->errs;
|
errs_t *errp = state->errs;
|
||||||
/* set nonzero to inhibit having any default reduction */
|
/* set nonzero to inhibit having any default reduction */
|
||||||
int nodefault = 0;
|
int nodefault = 0;
|
||||||
@@ -460,11 +460,11 @@ action_row (state_t *state)
|
|||||||
/* Now see which tokens are allowed for shifts in this state. For
|
/* Now see which tokens are allowed for shifts in this state. For
|
||||||
them, record the shift as the thing to do. So shift is preferred
|
them, record the shift as the thing to do. So shift is preferred
|
||||||
to reduce. */
|
to reduce. */
|
||||||
for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
|
for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!TRANSITION_IS_DISABLED (transitions, i))
|
||||||
{
|
{
|
||||||
symbol_number_t symbol = SHIFT_SYMBOL (shiftp, i);
|
symbol_number_t symbol = TRANSITION_SYMBOL (transitions, i);
|
||||||
state_number_t shift_state = shiftp->shifts[i];
|
state_number_t shift_state = transitions->states[i];
|
||||||
|
|
||||||
if (actrow[symbol] != 0)
|
if (actrow[symbol] != 0)
|
||||||
conflicted = conflrow[symbol] = 1;
|
conflicted = conflrow[symbol] = 1;
|
||||||
|
|||||||
46
src/print.c
46
src/print.c
@@ -123,18 +123,18 @@ print_core (FILE *out, state_t *state)
|
|||||||
`----------------------------------------------------------------*/
|
`----------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_transitions (state_t *state, FILE *out, bool display_shifts_p)
|
print_transitions (state_t *state, FILE *out, bool display_transitions_p)
|
||||||
{
|
{
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
size_t width = 0;
|
size_t width = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Compute the width of the lookaheads column. */
|
/* Compute the width of the lookaheads column. */
|
||||||
for (i = 0; i < shiftp->nshifts; i++)
|
for (i = 0; i < transitions->num; i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i)
|
if (!TRANSITION_IS_DISABLED (transitions, i)
|
||||||
&& SHIFT_IS_SHIFT (shiftp, i) == display_shifts_p)
|
&& TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p)
|
||||||
{
|
{
|
||||||
symbol_t *symbol = symbols[SHIFT_SYMBOL (shiftp, i)];
|
symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)];
|
||||||
max_length (&width, symbol_tag_get (symbol));
|
max_length (&width, symbol_tag_get (symbol));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,19 +146,19 @@ print_transitions (state_t *state, FILE *out, bool display_shifts_p)
|
|||||||
width += 2;
|
width += 2;
|
||||||
|
|
||||||
/* Report lookaheads and shifts. */
|
/* Report lookaheads and shifts. */
|
||||||
for (i = 0; i < shiftp->nshifts; i++)
|
for (i = 0; i < transitions->num; i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i)
|
if (!TRANSITION_IS_DISABLED (transitions, i)
|
||||||
&& SHIFT_IS_SHIFT (shiftp, i) == display_shifts_p)
|
&& TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p)
|
||||||
{
|
{
|
||||||
symbol_t *symbol = symbols[SHIFT_SYMBOL (shiftp, i)];
|
symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)];
|
||||||
const char *tag = symbol_tag_get (symbol);
|
const char *tag = symbol_tag_get (symbol);
|
||||||
state_number_t state1 = shiftp->shifts[i];
|
state_number_t state1 = transitions->states[i];
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
fprintf (out, " %s", tag);
|
fprintf (out, " %s", tag);
|
||||||
for (j = width - strlen (tag); j > 0; --j)
|
for (j = width - strlen (tag); j > 0; --j)
|
||||||
fputc (' ', out);
|
fputc (' ', out);
|
||||||
if (display_shifts_p)
|
if (display_transitions_p)
|
||||||
fprintf (out, _("shift, and go to state %d\n"), state1);
|
fprintf (out, _("shift, and go to state %d\n"), state1);
|
||||||
else
|
else
|
||||||
fprintf (out, _("go to state %d\n"), state1);
|
fprintf (out, _("go to state %d\n"), state1);
|
||||||
@@ -224,15 +224,15 @@ state_default_rule (state_t *state)
|
|||||||
we shift (S/R conflicts)... */
|
we shift (S/R conflicts)... */
|
||||||
bitset_zero (shiftset);
|
bitset_zero (shiftset);
|
||||||
{
|
{
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
|
for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!TRANSITION_IS_DISABLED (transitions, i))
|
||||||
{
|
{
|
||||||
/* If this state has a shift for the error token, don't use a
|
/* If this state has a shift for the error token, don't use a
|
||||||
default rule. */
|
default rule. */
|
||||||
if (SHIFT_IS_ERROR (shiftp, i))
|
if (TRANSITION_IS_ERROR (transitions, i))
|
||||||
return NULL;
|
return NULL;
|
||||||
bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
|
bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +302,7 @@ print_reduction (FILE *out, size_t width,
|
|||||||
static void
|
static void
|
||||||
print_reductions (FILE *out, state_t *state)
|
print_reductions (FILE *out, state_t *state)
|
||||||
{
|
{
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
reductions_t *redp = state->reductions;
|
reductions_t *redp = state->reductions;
|
||||||
rule_t *default_rule = NULL;
|
rule_t *default_rule = NULL;
|
||||||
size_t width = 0;
|
size_t width = 0;
|
||||||
@@ -314,9 +314,9 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
default_rule = state_default_rule (state);
|
default_rule = state_default_rule (state);
|
||||||
|
|
||||||
bitset_zero (shiftset);
|
bitset_zero (shiftset);
|
||||||
for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
|
for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!TRANSITION_IS_DISABLED (transitions, i))
|
||||||
bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
|
bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i));
|
||||||
|
|
||||||
/* Compute the width of the lookaheads column. */
|
/* Compute the width of the lookaheads column. */
|
||||||
if (default_rule)
|
if (default_rule)
|
||||||
@@ -396,9 +396,9 @@ static void
|
|||||||
print_actions (FILE *out, state_t *state)
|
print_actions (FILE *out, state_t *state)
|
||||||
{
|
{
|
||||||
reductions_t *redp = state->reductions;
|
reductions_t *redp = state->reductions;
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
|
|
||||||
if (shiftp->nshifts == 0 && redp->nreds == 0)
|
if (transitions->num == 0 && redp->nreds == 0)
|
||||||
{
|
{
|
||||||
fputc ('\n', out);
|
fputc ('\n', out);
|
||||||
if (state->number == final_state->number)
|
if (state->number == final_state->number)
|
||||||
|
|||||||
@@ -127,19 +127,19 @@ print_actions (state_t *state, const char *node_name)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
shifts_t *shiftp = state->shifts;
|
transitions_t *transitions = state->shifts;
|
||||||
reductions_t *redp = state->reductions;
|
reductions_t *redp = state->reductions;
|
||||||
|
|
||||||
static char buff[10];
|
static char buff[10];
|
||||||
edge_t edge;
|
edge_t edge;
|
||||||
|
|
||||||
if (!shiftp->nshifts && !redp)
|
if (!transitions->num && !redp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < shiftp->nshifts; i++)
|
for (i = 0; i < transitions->num; i++)
|
||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!TRANSITION_IS_DISABLED (transitions, i))
|
||||||
{
|
{
|
||||||
state_number_t state1 = shiftp->shifts[i];
|
state_number_t state1 = transitions->states[i];
|
||||||
symbol_number_t symbol = states[state1]->accessing_symbol;
|
symbol_number_t symbol = states[state1]->accessing_symbol;
|
||||||
|
|
||||||
new_edge (&edge);
|
new_edge (&edge);
|
||||||
@@ -152,10 +152,10 @@ print_actions (state_t *state, const char *node_name)
|
|||||||
sprintf (buff, "%d", state1);
|
sprintf (buff, "%d", state1);
|
||||||
edge.targetname = buff;
|
edge.targetname = buff;
|
||||||
/* Shifts are blue, gotos are green, and error is red. */
|
/* Shifts are blue, gotos are green, and error is red. */
|
||||||
if (SHIFT_IS_ERROR (shiftp, i))
|
if (TRANSITION_IS_ERROR (transitions, i))
|
||||||
edge.color = red;
|
edge.color = red;
|
||||||
else
|
else
|
||||||
edge.color = SHIFT_IS_SHIFT(shiftp, i) ? blue : green;
|
edge.color = TRANSITION_IS_SHIFT(transitions, i) ? blue : green;
|
||||||
edge.label = symbol_tag_get (symbols[symbol]);
|
edge.label = symbol_tag_get (symbols[symbol]);
|
||||||
output_edge (&edge, fgraph);
|
output_edge (&edge, fgraph);
|
||||||
close_edge (fgraph);
|
close_edge (fgraph);
|
||||||
|
|||||||
34
src/state.c
34
src/state.c
@@ -35,32 +35,32 @@
|
|||||||
| Create a new array of N shifts/gotos. |
|
| Create a new array of N shifts/gotos. |
|
||||||
`---------------------------------------*/
|
`---------------------------------------*/
|
||||||
|
|
||||||
#define SHIFTS_ALLOC(Nshifts) \
|
#define TRANSITIONS_ALLOC(Nshifts) \
|
||||||
(shifts_t *) xcalloc ((unsigned) (sizeof (shifts_t) \
|
(transitions_t *) xcalloc ((unsigned) (sizeof (transitions_t) \
|
||||||
+ (Nshifts - 1) * sizeof (state_number_t)), 1)
|
+ (Nshifts - 1) * sizeof (state_number_t)), 1)
|
||||||
|
|
||||||
static shifts_t *
|
static transitions_t *
|
||||||
shifts_new (int nshifts, state_number_t *shifts)
|
transitions_new (int num, state_number_t *the_states)
|
||||||
{
|
{
|
||||||
shifts_t *res = SHIFTS_ALLOC (nshifts);
|
transitions_t *res = TRANSITIONS_ALLOC (num);
|
||||||
res->nshifts = nshifts;
|
res->num = num;
|
||||||
memcpy (res->shifts, shifts, nshifts * sizeof (shifts[0]));
|
memcpy (res->states, the_states, num * sizeof (the_states[0]));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------.
|
/*-------------------------------------------------------------------.
|
||||||
| Return the state such these SHIFTS contain a shift/goto to it on |
|
| Return the state such these TRANSITIONS contain a shift/goto to it |
|
||||||
| SYMBOL. Aborts if none found. |
|
| on SYMBOL. Aborts if none found. |
|
||||||
`-----------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
state_t *
|
state_t *
|
||||||
shifts_to (shifts_t *shifts, symbol_number_t s)
|
transitions_to (transitions_t *shifts, symbol_number_t s)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < shifts->nshifts; j++)
|
for (j = 0; j < shifts->num; j++)
|
||||||
if (SHIFT_SYMBOL (shifts, j) == s)
|
if (TRANSITION_SYMBOL (shifts, j) == s)
|
||||||
return states[shifts->shifts[j]];
|
return states[shifts->states[j]];
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,9 +168,9 @@ state_new (symbol_number_t accessing_symbol,
|
|||||||
`--------------------------*/
|
`--------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
state_shifts_set (state_t *state, int nshifts, state_number_t *shifts)
|
state_transitions_set (state_t *state, int nshifts, state_number_t *shifts)
|
||||||
{
|
{
|
||||||
state->shifts = shifts_new (nshifts, shifts);
|
state->shifts = transitions_new (nshifts, shifts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
56
src/state.h
56
src/state.h
@@ -97,52 +97,54 @@ typedef short state_number_t;
|
|||||||
/* Be ready to map a state_number_t to an int. */
|
/* Be ready to map a state_number_t to an int. */
|
||||||
# define state_number_as_int(Tok) ((int) (Tok))
|
# define state_number_as_int(Tok) ((int) (Tok))
|
||||||
|
|
||||||
/*---------.
|
/*--------------.
|
||||||
| Shifts. |
|
| Transitions. |
|
||||||
`---------*/
|
`--------------*/
|
||||||
|
|
||||||
typedef struct shifts_s
|
typedef struct transtion_s
|
||||||
{
|
{
|
||||||
short nshifts;
|
short num;
|
||||||
state_number_t shifts[1];
|
state_number_t states[1];
|
||||||
} shifts_t;
|
} transitions_t;
|
||||||
|
|
||||||
|
|
||||||
/* What is the symbol which is shifted by SHIFTS->shifts[Shift]? Can
|
/* What is the symbol which is shifted by TRANSITIONS->states[Shift]? Can
|
||||||
be a token (amongst which the error token), or non terminals in
|
be a token (amongst which the error token), or non terminals in
|
||||||
case of gotos. */
|
case of gotos. */
|
||||||
|
|
||||||
#define SHIFT_SYMBOL(Shifts, Shift) \
|
#define TRANSITION_SYMBOL(Transitions, Shift) \
|
||||||
(states[Shifts->shifts[Shift]]->accessing_symbol)
|
(states[Transitions->states[Shift]]->accessing_symbol)
|
||||||
|
|
||||||
/* Is the SHIFTS->shifts[Shift] a real shift? (as opposed to gotos.) */
|
/* Is the TRANSITIONS->states[Shift] a real shift? (as opposed to gotos.) */
|
||||||
|
|
||||||
#define SHIFT_IS_SHIFT(Shifts, Shift) \
|
#define TRANSITION_IS_SHIFT(Transitions, Shift) \
|
||||||
(ISTOKEN (SHIFT_SYMBOL (Shifts, Shift)))
|
(ISTOKEN (TRANSITION_SYMBOL (Transitions, Shift)))
|
||||||
|
|
||||||
/* Is the SHIFTS->shifts[Shift] a goto?. */
|
/* Is the TRANSITIONS->states[Shift] a goto?. */
|
||||||
|
|
||||||
#define SHIFT_IS_GOTO(Shifts, Shift) \
|
#define TRANSITION_IS_GOTO(Transitions, Shift) \
|
||||||
(!SHIFT_IS_SHIFT (Shifts, Shift))
|
(!TRANSITION_IS_SHIFT (Transitions, Shift))
|
||||||
|
|
||||||
/* Is the SHIFTS->shifts[Shift] then handling of the error token?. */
|
/* Is the TRANSITIONS->states[Shift] then handling of the error token?. */
|
||||||
|
|
||||||
#define SHIFT_IS_ERROR(Shifts, Shift) \
|
#define TRANSITION_IS_ERROR(Transitions, Shift) \
|
||||||
(SHIFT_SYMBOL (Shifts, Shift) == errtoken->number)
|
(TRANSITION_SYMBOL (Transitions, Shift) == errtoken->number)
|
||||||
|
|
||||||
/* When resolving a SR conflicts, if the reduction wins, the shift is
|
/* When resolving a SR conflicts, if the reduction wins, the shift is
|
||||||
disabled. */
|
disabled. */
|
||||||
|
|
||||||
#define SHIFT_DISABLE(Shifts, Shift) \
|
#define TRANSITION_DISABLE(Transitions, Shift) \
|
||||||
(Shifts->shifts[Shift] = 0)
|
(Transitions->states[Shift] = 0)
|
||||||
|
|
||||||
#define SHIFT_IS_DISABLED(Shifts, Shift) \
|
#define TRANSITION_IS_DISABLED(Transitions, Shift) \
|
||||||
(Shifts->shifts[Shift] == 0)
|
(Transitions->states[Shift] == 0)
|
||||||
|
|
||||||
/* Return the state such these SHIFTS contain a shift/goto to it on
|
/* Return the state such these TRANSITIONS contain a shift/goto to it on
|
||||||
SYMBOL. Aborts if none found. */
|
SYMBOL. Aborts if none found. */
|
||||||
struct state_s;
|
struct state_s;
|
||||||
struct state_s *shifts_to PARAMS ((shifts_t *shifts, symbol_number_t s));
|
struct state_s *transitions_to PARAMS ((transitions_t *state,
|
||||||
|
symbol_number_t s));
|
||||||
|
|
||||||
|
|
||||||
/*-------.
|
/*-------.
|
||||||
| Errs. |
|
| Errs. |
|
||||||
@@ -178,7 +180,7 @@ typedef struct state_s
|
|||||||
{
|
{
|
||||||
state_number_t number;
|
state_number_t number;
|
||||||
symbol_number_t accessing_symbol;
|
symbol_number_t accessing_symbol;
|
||||||
shifts_t *shifts;
|
transitions_t *shifts;
|
||||||
reductions_t *reductions;
|
reductions_t *reductions;
|
||||||
errs_t *errs;
|
errs_t *errs;
|
||||||
|
|
||||||
@@ -214,7 +216,7 @@ state_t *state_new PARAMS ((symbol_number_t accessing_symbol,
|
|||||||
size_t core_size, item_number_t *core));
|
size_t core_size, item_number_t *core));
|
||||||
|
|
||||||
/* Set the shifts of STATE. */
|
/* Set the shifts of STATE. */
|
||||||
void state_shifts_set PARAMS ((state_t *state,
|
void state_transitions_set PARAMS ((state_t *state,
|
||||||
int nshifts, state_number_t *shifts));
|
int nshifts, state_number_t *shifts));
|
||||||
|
|
||||||
/* Set the reductions of STATE. */
|
/* Set the reductions of STATE. */
|
||||||
|
|||||||
Reference in New Issue
Block a user