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/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
2002-06-15 Akim Demaille <akim@epita.fr>
* src/gram.h, src/gram.c (grammar_rules_partial_print): New, eved
check for shift-reduce conflict, and try to resolve using
precedence */
for (i = 0; i < state->nlookaheads; ++i)
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);
for conflicts not resolved above. */
for (i = 0; i < state->nlookaheads; ++i)
{
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;
conflicts[state->number] = 1;
- bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
+ bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]);
bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
for (i = 0; i < state->nlookaheads; ++i)
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);
bitset_and (lookaheadset, lookaheadset, shiftset);
int count = 0;
int j;
for (j = 0; j < state->nlookaheads; ++j)
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))
shorts *sp;
for (i = 0; i < state->nlookaheads; ++i)
shorts *sp;
for (i = 0; i < state->nlookaheads; ++i)
- if (LArule[state->lookaheadsp + i]->number == ruleno)
+ if (state->lookaheads_rule[i]->number == ruleno)
- assert (LArule[state->lookaheadsp + i]->number == ruleno);
+ assert (state->lookaheads_rule[i]->number == ruleno);
sp = XCALLOC (shorts, 1);
sp = XCALLOC (shorts, 1);
- sp->next = lookback[state->lookaheadsp + i];
+ sp->next = lookback[(state->lookaheads - LA) + i];
- lookback[state->lookaheadsp + i] = sp;
+ lookback[(state->lookaheads - LA) + i] = sp;
-/*--------------------------------------.
-| Initializing the lookaheads members. |
-`--------------------------------------*/
+/*-------------------------------------------------------------.
+| Count the number of lookaheads required for each state |
+| (NLOOKAHEADS member). Compute the total number of LA, NLA. |
+`-------------------------------------------------------------*/
-initialize_lookaheads (void)
+states_lookaheads_count (void)
for (i = 0; i < nstates; i++)
{
int k;
for (i = 0; i < nstates; i++)
{
int k;
}
states[i]->nlookaheads = nlookaheads;
}
states[i]->nlookaheads = nlookaheads;
- states[i]->lookaheadsp = nLA;
+/*--------------------------------------.
+| 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. |
`---------------------------------------*/
/*---------------------------------------.
| Output the lookaheads for each state. |
`---------------------------------------*/
for (j = 0; j < states[i]->nlookaheads; ++j)
for (k = 0; k < ntokens; ++k)
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]),
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");
}
}
fprintf (out, "Lookaheads: END\n");
}
- initialize_lookaheads ();
+ states_lookaheads_count ();
+ states_lookaheads_initialize ();
set_goto_map ();
initialize_F ();
build_relations ();
set_goto_map ();
initialize_F ();
build_relations ();
for (j = 0; j < ntokens; j++)
/* and record this rule as the rule to use if that
token follows. */
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
}
/* Now see which tokens are allowed for shifts in this state. For
for (i = 0; i < state->nlookaheads; i++)
{
int count = 0;
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++)
int j;
for (j = 0; j < ntokens; j++)
/* Look for lookaheads corresponding to this rule. */
for (j = 0; j < state->nlookaheads; ++j)
for (k = 0; k < ntokens; ++k)
/* 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)
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 ? ", " : "");
fprintf (out, "%s%s",
symbol_tag_get (symbols[k]),
--nlookaheads ? ", " : "");
if (state->nlookaheads == 1 && !nodefault)
{
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))
for (i = 0; i < ntokens; i++)
if (bitset_test (lookaheadset, i))
- 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))
for (j = 0; j < ntokens; j++)
if (bitset_test (lookaheadset, j))
if (count > cmax)
{
cmax = count;
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);
}
bitset_or (shiftset, shiftset, lookaheadset);
int count = bitset_test (shiftset, i);
for (j = 0; j < state->nlookaheads; ++j)
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 (state->lookaheadsp + j != default_LA)
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
symbol_tag_get (symbols[i]),
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));
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
symbol_tag_get (symbols[i]),
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]),
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));
/* Look for lookaheads corresponding to this rule. */
for (j = 0; j < state->nlookaheads; ++j)
for (k = 0; k < ntokens; ++k)
/* 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)
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 ? ", " : "");
obstack_fgrow2 (oout, "%s%s",
symbol_tag_get (symbols[k]),
--nlookaheads ? ", " : "");
#ifndef STATE_H_
# define STATE_H_
#ifndef STATE_H_
# define STATE_H_
char consistent;
/* Used in LALR, not LR(0). */
char consistent;
/* Used in LALR, not LR(0). */
- /* Pseudo pointer into LA. */
- short lookaheadsp;
+ bitsetv lookaheads;
+ rule_t **lookaheads_rule;
/* If some conflicts were solved thanks to precedence/associativity,
a human readable description of the resolution. */
/* If some conflicts were solved thanks to precedence/associativity,
a human readable description of the resolution. */