mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
* src/state.h (state_t): Replace the `lookaheadsp' member, a
short, with `lookaheads' (bitsetv), `lookaheads_rule' (rule_t**). Adjust all dependencies. * src/lalr.c (initialize_lookaheads): Split into... (states_lookaheads_count, states_lookaheads_initialize): these. (lalr): Adjust.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2002-06-15 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/state.h (state_t): Replace the `lookaheadsp' member, a
|
||||
short, with `lookaheads' (bitsetv), `lookaheads_rule' (rule_t**).
|
||||
Adjust all dependencies.
|
||||
* src/lalr.c (initialize_lookaheads): Split into...
|
||||
(states_lookaheads_count, states_lookaheads_initialize): these.
|
||||
(lalr): Adjust.
|
||||
|
||||
|
||||
2002-06-15 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/gram.h, src/gram.c (grammar_rules_partial_print): New, eved
|
||||
|
||||
@@ -256,11 +256,11 @@ set_conflicts (state_t *state)
|
||||
check for shift-reduce conflict, and try to resolve using
|
||||
precedence */
|
||||
for (i = 0; i < state->nlookaheads; ++i)
|
||||
if (LArule[state->lookaheadsp + i]->prec
|
||||
&& LArule[state->lookaheadsp + i]->prec->prec
|
||||
&& !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
|
||||
if (state->lookaheads_rule[i]->prec
|
||||
&& state->lookaheads_rule[i]->prec->prec
|
||||
&& !bitset_disjoint_p (state->lookaheads[i], lookaheadset))
|
||||
{
|
||||
resolve_sr_conflict (state, state->lookaheadsp + i);
|
||||
resolve_sr_conflict (state, (state->lookaheads - LA) + i);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -268,10 +268,10 @@ set_conflicts (state_t *state)
|
||||
for conflicts not resolved above. */
|
||||
for (i = 0; i < state->nlookaheads; ++i)
|
||||
{
|
||||
if (!bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
|
||||
if (!bitset_disjoint_p (state->lookaheads[i], lookaheadset))
|
||||
conflicts[state->number] = 1;
|
||||
|
||||
bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
|
||||
bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ count_sr_conflicts (state_t *state)
|
||||
bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
|
||||
|
||||
for (i = 0; i < state->nlookaheads; ++i)
|
||||
bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
|
||||
bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]);
|
||||
|
||||
bitset_and (lookaheadset, lookaheadset, shiftset);
|
||||
|
||||
@@ -340,7 +340,7 @@ count_rr_conflicts (state_t *state)
|
||||
int count = 0;
|
||||
int j;
|
||||
for (j = 0; j < state->nlookaheads; ++j)
|
||||
if (bitset_test (LA[state->lookaheadsp + j], i))
|
||||
if (bitset_test (state->lookaheads[j], i))
|
||||
count++;
|
||||
|
||||
if (count >= 2)
|
||||
|
||||
50
src/lalr.c
50
src/lalr.c
@@ -298,15 +298,15 @@ add_lookback_edge (state_t *state, int ruleno, int gotono)
|
||||
shorts *sp;
|
||||
|
||||
for (i = 0; i < state->nlookaheads; ++i)
|
||||
if (LArule[state->lookaheadsp + i]->number == ruleno)
|
||||
if (state->lookaheads_rule[i]->number == ruleno)
|
||||
break;
|
||||
|
||||
assert (LArule[state->lookaheadsp + i]->number == ruleno);
|
||||
assert (state->lookaheads_rule[i]->number == ruleno);
|
||||
|
||||
sp = XCALLOC (shorts, 1);
|
||||
sp->next = lookback[state->lookaheadsp + i];
|
||||
sp->next = lookback[(state->lookaheads - LA) + i];
|
||||
sp->value = gotono;
|
||||
lookback[state->lookaheadsp + i] = sp;
|
||||
lookback[(state->lookaheads - LA) + i] = sp;
|
||||
}
|
||||
|
||||
|
||||
@@ -506,15 +506,18 @@ compute_lookaheads (void)
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------.
|
||||
| Initializing the lookaheads members. |
|
||||
`--------------------------------------*/
|
||||
/*-------------------------------------------------------------.
|
||||
| Count the number of lookaheads required for each state |
|
||||
| (NLOOKAHEADS member). Compute the total number of LA, NLA. |
|
||||
`-------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
initialize_lookaheads (void)
|
||||
states_lookaheads_count (void)
|
||||
{
|
||||
size_t i;
|
||||
nLA = 0;
|
||||
|
||||
/* Count */
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
int k;
|
||||
@@ -540,12 +543,34 @@ initialize_lookaheads (void)
|
||||
}
|
||||
|
||||
states[i]->nlookaheads = nlookaheads;
|
||||
states[i]->lookaheadsp = nLA;
|
||||
nLA += nlookaheads;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------.
|
||||
| Initializing the lookaheads members. |
|
||||
`--------------------------------------*/
|
||||
|
||||
static void
|
||||
states_lookaheads_initialize (void)
|
||||
{
|
||||
size_t i;
|
||||
bitsetv pLA = LA;
|
||||
rule_t **pLArule = LArule;
|
||||
|
||||
/* Count the number of lookaheads required for each state
|
||||
(NLOOKAHEADS member). */
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
states[i]->lookaheads = pLA;
|
||||
states[i]->lookaheads_rule = pLArule;
|
||||
pLA += states[i]->nlookaheads;
|
||||
pLArule += states[i]->nlookaheads;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------.
|
||||
| Output the lookaheads for each state. |
|
||||
`---------------------------------------*/
|
||||
@@ -563,10 +588,10 @@ lookaheads_print (FILE *out)
|
||||
|
||||
for (j = 0; j < states[i]->nlookaheads; ++j)
|
||||
for (k = 0; k < ntokens; ++k)
|
||||
if (bitset_test (LA[states[i]->lookaheadsp + j], k))
|
||||
if (bitset_test (states[i]->lookaheads[j], k))
|
||||
fprintf (out, " on %d (%s) -> rule %d\n",
|
||||
k, symbol_tag_get (symbols[k]),
|
||||
LArule[states[i]->lookaheadsp + j]->number - 1);
|
||||
states[i]->lookaheads_rule[j]->number - 1);
|
||||
}
|
||||
fprintf (out, "Lookaheads: END\n");
|
||||
}
|
||||
@@ -574,8 +599,9 @@ lookaheads_print (FILE *out)
|
||||
void
|
||||
lalr (void)
|
||||
{
|
||||
initialize_lookaheads ();
|
||||
states_lookaheads_count ();
|
||||
initialize_LA ();
|
||||
states_lookaheads_initialize ();
|
||||
set_goto_map ();
|
||||
initialize_F ();
|
||||
build_relations ();
|
||||
|
||||
@@ -380,8 +380,8 @@ action_row (state_t *state)
|
||||
for (j = 0; j < ntokens; j++)
|
||||
/* and record this rule as the rule to use if that
|
||||
token follows. */
|
||||
if (bitset_test (LA[state->lookaheadsp + i], j))
|
||||
actrow[j] = -LArule[state->lookaheadsp + i]->number;
|
||||
if (bitset_test (state->lookaheads[i], j))
|
||||
actrow[j] = -state->lookaheads_rule[i]->number;
|
||||
}
|
||||
|
||||
/* Now see which tokens are allowed for shifts in this state. For
|
||||
@@ -428,7 +428,7 @@ action_row (state_t *state)
|
||||
for (i = 0; i < state->nlookaheads; i++)
|
||||
{
|
||||
int count = 0;
|
||||
int rule = -LArule[state->lookaheadsp + i]->number;
|
||||
int rule = -state->lookaheads_rule[i]->number;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < ntokens; j++)
|
||||
|
||||
34
src/print.c
34
src/print.c
@@ -99,16 +99,16 @@ print_core (FILE *out, state_t *state)
|
||||
/* Look for lookaheads corresponding to this rule. */
|
||||
for (j = 0; j < state->nlookaheads; ++j)
|
||||
for (k = 0; k < ntokens; ++k)
|
||||
if (bitset_test (LA[state->lookaheadsp + j], k)
|
||||
&& LArule[state->lookaheadsp + j]->number == rule)
|
||||
if (bitset_test (state->lookaheads[j], k)
|
||||
&& state->lookaheads_rule[j]->number == rule)
|
||||
nlookaheads++;
|
||||
if (nlookaheads)
|
||||
{
|
||||
fprintf (out, " [");
|
||||
for (j = 0; j < state->nlookaheads; ++j)
|
||||
for (k = 0; k < ntokens; ++k)
|
||||
if (bitset_test (LA[state->lookaheadsp + j], k)
|
||||
&& LArule[state->lookaheadsp + j]->number == rule)
|
||||
if (bitset_test (state->lookaheads[j], k)
|
||||
&& state->lookaheads_rule[j]->number == rule)
|
||||
fprintf (out, "%s%s",
|
||||
symbol_tag_get (symbols[k]),
|
||||
--nlookaheads ? ", " : "");
|
||||
@@ -225,9 +225,9 @@ print_reductions (FILE *out, state_t *state)
|
||||
|
||||
if (state->nlookaheads == 1 && !nodefault)
|
||||
{
|
||||
rule_t *default_rule = LArule[state->lookaheadsp];
|
||||
rule_t *default_rule = state->lookaheads_rule[0];
|
||||
|
||||
bitset_and (lookaheadset, LA[state->lookaheadsp], shiftset);
|
||||
bitset_and (lookaheadset, state->lookaheads[0], shiftset);
|
||||
|
||||
for (i = 0; i < ntokens; i++)
|
||||
if (bitset_test (lookaheadset, i))
|
||||
@@ -252,7 +252,7 @@ print_reductions (FILE *out, state_t *state)
|
||||
int count = 0;
|
||||
int j;
|
||||
|
||||
bitset_andn (lookaheadset, LA[state->lookaheadsp + i], shiftset);
|
||||
bitset_andn (lookaheadset, state->lookaheads[i], shiftset);
|
||||
|
||||
for (j = 0; j < ntokens; j++)
|
||||
if (bitset_test (lookaheadset, j))
|
||||
@@ -261,8 +261,8 @@ print_reductions (FILE *out, state_t *state)
|
||||
if (count > cmax)
|
||||
{
|
||||
cmax = count;
|
||||
default_LA = state->lookaheadsp + i;
|
||||
default_rule = LArule[state->lookaheadsp + i];
|
||||
default_LA = i;
|
||||
default_rule = state->lookaheads_rule[i];
|
||||
}
|
||||
|
||||
bitset_or (shiftset, shiftset, lookaheadset);
|
||||
@@ -281,16 +281,16 @@ print_reductions (FILE *out, state_t *state)
|
||||
int count = bitset_test (shiftset, i);
|
||||
|
||||
for (j = 0; j < state->nlookaheads; ++j)
|
||||
if (bitset_test (LA[state->lookaheadsp + j], i))
|
||||
if (bitset_test (state->lookaheads[j], i))
|
||||
{
|
||||
if (count == 0)
|
||||
{
|
||||
if (state->lookaheadsp + j != default_LA)
|
||||
if (j != default_LA)
|
||||
fprintf (out,
|
||||
_(" %-4s\treduce using rule %d (%s)\n"),
|
||||
symbol_tag_get (symbols[i]),
|
||||
LArule[state->lookaheadsp + j]->number - 1,
|
||||
symbol_tag_get_n (LArule[state->lookaheadsp + j]->lhs, 1));
|
||||
state->lookaheads_rule[j]->number - 1,
|
||||
symbol_tag_get_n (state->lookaheads_rule[j]->lhs, 1));
|
||||
else
|
||||
defaulted = 1;
|
||||
|
||||
@@ -302,14 +302,14 @@ print_reductions (FILE *out, state_t *state)
|
||||
fprintf (out,
|
||||
_(" %-4s\treduce using rule %d (%s)\n"),
|
||||
symbol_tag_get (symbols[i]),
|
||||
LArule[default_LA]->number - 1,
|
||||
symbol_tag_get_n (LArule[default_LA]->lhs, 1));
|
||||
state->lookaheads_rule[default_LA]->number - 1,
|
||||
symbol_tag_get_n (state->lookaheads_rule[default_LA]->lhs, 1));
|
||||
defaulted = 0;
|
||||
fprintf (out,
|
||||
_(" %-4s\t[reduce using rule %d (%s)]\n"),
|
||||
symbol_tag_get (symbols[i]),
|
||||
LArule[state->lookaheadsp + j]->number - 1,
|
||||
symbol_tag_get_n (LArule[state->lookaheadsp + j]->lhs, 1));
|
||||
state->lookaheads_rule[j]->number - 1,
|
||||
symbol_tag_get_n (state->lookaheads_rule[j]->lhs, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,16 +93,16 @@ print_core (struct obstack *oout, state_t *state)
|
||||
/* Look for lookaheads corresponding to this rule. */
|
||||
for (j = 0; j < state->nlookaheads; ++j)
|
||||
for (k = 0; k < ntokens; ++k)
|
||||
if (bitset_test (LA[state->lookaheadsp + j], k)
|
||||
&& LArule[state->lookaheadsp + j]->number == rule)
|
||||
if (bitset_test (state->lookaheads[j], k)
|
||||
&& state->lookaheads_rule[j]->number == rule)
|
||||
nlookaheads++;
|
||||
if (nlookaheads)
|
||||
{
|
||||
obstack_sgrow (oout, " [");
|
||||
for (j = 0; j < state->nlookaheads; ++j)
|
||||
for (k = 0; k < ntokens; ++k)
|
||||
if (bitset_test (LA[state->lookaheadsp + j], k)
|
||||
&& LArule[state->lookaheadsp + j]->number == rule)
|
||||
if (bitset_test (state->lookaheads[j], k)
|
||||
&& state->lookaheads_rule[j]->number == rule)
|
||||
obstack_fgrow2 (oout, "%s%s",
|
||||
symbol_tag_get (symbols[k]),
|
||||
--nlookaheads ? ", " : "");
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
#ifndef STATE_H_
|
||||
# define STATE_H_
|
||||
|
||||
# include "bitsetv.h"
|
||||
|
||||
/*---------.
|
||||
| Shifts. |
|
||||
@@ -180,9 +181,9 @@ typedef struct state_s
|
||||
char consistent;
|
||||
|
||||
/* Used in LALR, not LR(0). */
|
||||
/* Pseudo pointer into LA. */
|
||||
short lookaheadsp;
|
||||
int nlookaheads;
|
||||
bitsetv lookaheads;
|
||||
rule_t **lookaheads_rule;
|
||||
|
||||
/* If some conflicts were solved thanks to precedence/associativity,
|
||||
a human readable description of the resolution. */
|
||||
|
||||
Reference in New Issue
Block a user