mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
* src/closure.c (print_firsts, print_fderives, closure):
Use BITSET_EXECUTE. * src/lalr.c (lookaheads_print): Likewise. * src/state.c (state_rule_lookaheads_print): Likewise. * src/print_graph.c (print_core): Likewise. * src/print.c (print_reductions): Likewise. * src/output.c (action_row): Likewise. Use SHIFT_IS_DISABLED, SHIFT_IS_SHIFT and SHIFT_SYMBOL.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
2002-06-30 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/closure.c (print_firsts, print_fderives, closure):
|
||||||
|
Use BITSET_EXECUTE.
|
||||||
|
* src/lalr.c (lookaheads_print): Likewise.
|
||||||
|
* src/state.c (state_rule_lookaheads_print): Likewise.
|
||||||
|
* src/print_graph.c (print_core): Likewise.
|
||||||
|
* src/print.c (print_reductions): Likewise.
|
||||||
|
* src/output.c (action_row): Likewise.
|
||||||
|
Use SHIFT_IS_DISABLED, SHIFT_IS_SHIFT and SHIFT_SYMBOL.
|
||||||
|
|
||||||
|
|
||||||
2002-06-30 Akim Demaille <akim@epita.fr>
|
2002-06-30 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/print_graph.c: Use report_flag.
|
* src/print_graph.c: Use report_flag.
|
||||||
|
|||||||
@@ -69,16 +69,17 @@ print_closure (const char *title, item_number_t *array, size_t size)
|
|||||||
static void
|
static void
|
||||||
print_firsts (void)
|
print_firsts (void)
|
||||||
{
|
{
|
||||||
int i, j;
|
symbol_number_t i, j;
|
||||||
|
|
||||||
fprintf (stderr, "FIRSTS\n");
|
fprintf (stderr, "FIRSTS\n");
|
||||||
for (i = ntokens; i < nsyms; i++)
|
for (i = ntokens; i < nsyms; i++)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "\t%s firsts\n", symbol_tag_get (symbols[i]));
|
fprintf (stderr, "\t%s firsts\n", symbol_tag_get (symbols[i]));
|
||||||
for (j = 0; j < nvars; j++)
|
BITSET_EXECUTE (FIRSTS (i), 0, j,
|
||||||
if (bitset_test (FIRSTS (i), j))
|
{
|
||||||
fprintf (stderr, "\t\t%s\n",
|
fprintf (stderr, "\t\t%s\n",
|
||||||
symbol_tag_get (symbols[j + ntokens]));
|
symbol_tag_get (symbols[j + ntokens]));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
fprintf (stderr, "\n\n");
|
fprintf (stderr, "\n\n");
|
||||||
}
|
}
|
||||||
@@ -94,15 +95,14 @@ print_fderives (void)
|
|||||||
for (i = ntokens; i < nsyms; i++)
|
for (i = ntokens; i < nsyms; i++)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "\t%s derives\n", symbol_tag_get (symbols[i]));
|
fprintf (stderr, "\t%s derives\n", symbol_tag_get (symbols[i]));
|
||||||
for (r = 0; r < nrules + 1; r++)
|
BITSET_EXECUTE (FDERIVES (i), 0, r,
|
||||||
if (bitset_test (FDERIVES (i), r))
|
{
|
||||||
{
|
item_number_t *rhsp = NULL;
|
||||||
item_number_t *rhsp = NULL;
|
fprintf (stderr, "\t\t%d:", r - 1);
|
||||||
fprintf (stderr, "\t\t%d:", r - 1);
|
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
|
||||||
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
|
fprintf (stderr, " %s", symbol_tag_get (symbols[*rhsp]));
|
||||||
fprintf (stderr, " %s", symbol_tag_get (symbols[*rhsp]));
|
fputc ('\n', stderr);
|
||||||
fputc ('\n', stderr);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fprintf (stderr, "\n\n");
|
fprintf (stderr, "\n\n");
|
||||||
}
|
}
|
||||||
@@ -209,19 +209,18 @@ closure (item_number_t *core, int n)
|
|||||||
|
|
||||||
nritemset = 0;
|
nritemset = 0;
|
||||||
c = 0;
|
c = 0;
|
||||||
for (ruleno = 0; ruleno < nrules + 1; ++ruleno)
|
BITSET_EXECUTE (ruleset, 0, ruleno,
|
||||||
if (bitset_test (ruleset, ruleno))
|
{
|
||||||
|
item_number_t itemno = rules[ruleno].rhs - ritem;
|
||||||
|
while (c < n && core[c] < itemno)
|
||||||
{
|
{
|
||||||
item_number_t itemno = rules[ruleno].rhs - ritem;
|
itemset[nritemset] = core[c];
|
||||||
while (c < n && core[c] < itemno)
|
|
||||||
{
|
|
||||||
itemset[nritemset] = core[c];
|
|
||||||
nritemset++;
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
itemset[nritemset] = itemno;
|
|
||||||
nritemset++;
|
nritemset++;
|
||||||
|
c++;
|
||||||
}
|
}
|
||||||
|
itemset[nritemset] = itemno;
|
||||||
|
nritemset++;
|
||||||
|
});
|
||||||
|
|
||||||
while (c < n)
|
while (c < n)
|
||||||
{
|
{
|
||||||
|
|||||||
11
src/lalr.c
11
src/lalr.c
@@ -424,11 +424,12 @@ lookaheads_print (FILE *out)
|
|||||||
i, states[i]->nlookaheads);
|
i, states[i]->nlookaheads);
|
||||||
|
|
||||||
for (j = 0; j < states[i]->nlookaheads; ++j)
|
for (j = 0; j < states[i]->nlookaheads; ++j)
|
||||||
for (k = 0; k < ntokens; ++k)
|
BITSET_EXECUTE (states[i]->lookaheads[j], 0, k,
|
||||||
if (bitset_test (states[i]->lookaheads[j], k))
|
{
|
||||||
fprintf (out, " on %d (%s) -> rule %d\n",
|
fprintf (out, " on %d (%s) -> rule %d\n",
|
||||||
k, symbol_tag_get (symbols[k]),
|
k, symbol_tag_get (symbols[k]),
|
||||||
states[i]->lookaheads_rule[j]->number - 1);
|
states[i]->lookaheads_rule[j]->number - 1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
fprintf (out, "Lookaheads: END\n");
|
fprintf (out, "Lookaheads: END\n");
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/output.c
45
src/output.c
@@ -447,41 +447,34 @@ action_row (state_t *state)
|
|||||||
for (i = state->nlookaheads - 1; i >= 0; --i)
|
for (i = state->nlookaheads - 1; i >= 0; --i)
|
||||||
/* and find each token which the rule finds acceptable
|
/* and find each token which the rule finds acceptable
|
||||||
to come next */
|
to come next */
|
||||||
for (j = 0; j < ntokens; j++)
|
BITSET_EXECUTE (state->lookaheads[i], 0, j,
|
||||||
|
{
|
||||||
/* and record this rule as the rule to use if that
|
/* and record this rule as the rule to use if that
|
||||||
token follows. */
|
token follows. */
|
||||||
if (bitset_test (state->lookaheads[i], j))
|
if (actrow[j] != 0)
|
||||||
{
|
conflicted = conflrow[j] = 1;
|
||||||
if (actrow[j] != 0)
|
actrow[j] = -state->lookaheads_rule[i]->number;
|
||||||
conflicted = conflrow[j] = 1;
|
});
|
||||||
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
|
||||||
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; i++)
|
for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
|
||||||
{
|
if (!SHIFT_IS_DISABLED (shiftp, i))
|
||||||
symbol_number_t symbol;
|
{
|
||||||
state_number_t shift_state = shiftp->shifts[i];
|
symbol_number_t symbol = SHIFT_SYMBOL (shiftp, i);
|
||||||
if (!shift_state)
|
state_number_t shift_state = shiftp->shifts[i];
|
||||||
continue;
|
|
||||||
|
|
||||||
symbol = states[shift_state]->accessing_symbol;
|
if (actrow[symbol] != 0)
|
||||||
|
conflicted = conflrow[symbol] = 1;
|
||||||
|
actrow[symbol] = state_number_as_int (shift_state);
|
||||||
|
|
||||||
if (ISVAR (symbol))
|
/* Do not use any default reduction if there is a shift for
|
||||||
break;
|
error */
|
||||||
|
if (symbol == errtoken->number)
|
||||||
if (actrow[symbol] != 0)
|
nodefault = 1;
|
||||||
conflicted = conflrow[symbol] = 1;
|
}
|
||||||
actrow[symbol] = state_number_as_int (shift_state);
|
|
||||||
|
|
||||||
/* Do not use any default reduction if there is a shift for
|
|
||||||
error */
|
|
||||||
if (symbol == errtoken->number)
|
|
||||||
nodefault = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See which tokens are an explicit error in this state (due to
|
/* See which tokens are an explicit error in this state (due to
|
||||||
%nonassoc). For them, record SHRT_MIN as the action. */
|
%nonassoc). For them, record SHRT_MIN as the action. */
|
||||||
|
|||||||
20
src/print.c
20
src/print.c
@@ -208,13 +208,13 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
|
|
||||||
bitset_and (lookaheadset, state->lookaheads[0], shiftset);
|
bitset_and (lookaheadset, state->lookaheads[0], shiftset);
|
||||||
|
|
||||||
for (i = 0; i < ntokens; i++)
|
BITSET_EXECUTE (lookaheadset, 0, i,
|
||||||
if (bitset_test (lookaheadset, i))
|
{
|
||||||
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
|
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
|
||||||
symbol_tag_get (symbols[i]),
|
symbol_tag_get (symbols[i]),
|
||||||
default_rule->number - 1,
|
default_rule->number - 1,
|
||||||
symbol_tag_get_n (default_rule->lhs, 1));
|
symbol_tag_get_n (default_rule->lhs, 1));
|
||||||
|
});
|
||||||
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
||||||
default_rule->number - 1,
|
default_rule->number - 1,
|
||||||
symbol_tag_get (default_rule->lhs));
|
symbol_tag_get (default_rule->lhs));
|
||||||
@@ -229,13 +229,9 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
for (i = 0; i < state->nlookaheads; ++i)
|
for (i = 0; i < state->nlookaheads; ++i)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int j;
|
|
||||||
|
|
||||||
bitset_andn (lookaheadset, state->lookaheads[i], shiftset);
|
bitset_andn (lookaheadset, state->lookaheads[i], shiftset);
|
||||||
|
count = bitset_count (lookaheadset);
|
||||||
for (j = 0; j < ntokens; j++)
|
|
||||||
if (bitset_test (lookaheadset, j))
|
|
||||||
count++;
|
|
||||||
|
|
||||||
if (count > cmax)
|
if (count > cmax)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -93,20 +93,23 @@ print_core (struct obstack *oout, state_t *state)
|
|||||||
int nlookaheads = 0;
|
int nlookaheads = 0;
|
||||||
/* Look for lookaheads corresponding to this rule. */
|
/* Look for lookaheads corresponding to this rule. */
|
||||||
for (j = 0; j < state->nlookaheads; ++j)
|
for (j = 0; j < state->nlookaheads; ++j)
|
||||||
for (k = 0; k < ntokens; ++k)
|
BITSET_EXECUTE (state->lookaheads[j], 0, k,
|
||||||
if (bitset_test (state->lookaheads[j], k)
|
{
|
||||||
&& state->lookaheads_rule[j]->number == rule)
|
if (state->lookaheads_rule[j]->number == rule)
|
||||||
nlookaheads++;
|
nlookaheads++;
|
||||||
|
});
|
||||||
|
|
||||||
if (nlookaheads)
|
if (nlookaheads)
|
||||||
{
|
{
|
||||||
obstack_sgrow (oout, " [");
|
obstack_sgrow (oout, " [");
|
||||||
for (j = 0; j < state->nlookaheads; ++j)
|
for (j = 0; j < state->nlookaheads; ++j)
|
||||||
for (k = 0; k < ntokens; ++k)
|
BITSET_EXECUTE (state->lookaheads[j], 0, k,
|
||||||
if (bitset_test (state->lookaheads[j], k)
|
{
|
||||||
&& state->lookaheads_rule[j]->number == rule)
|
if (state->lookaheads_rule[j]->number == rule)
|
||||||
obstack_fgrow2 (oout, "%s%s",
|
obstack_fgrow2 (oout, "%s%s",
|
||||||
symbol_tag_get (symbols[k]),
|
symbol_tag_get (symbols[k]),
|
||||||
--nlookaheads ? ", " : "");
|
--nlookaheads ? ", " : "");
|
||||||
|
});
|
||||||
obstack_sgrow (oout, "]");
|
obstack_sgrow (oout, "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/state.c
14
src/state.c
@@ -198,22 +198,24 @@ state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out)
|
|||||||
int nlookaheads = 0;
|
int nlookaheads = 0;
|
||||||
/* Count the number of lookaheads corresponding to this rule. */
|
/* Count the number of lookaheads corresponding to this rule. */
|
||||||
for (j = 0; j < state->nlookaheads; ++j)
|
for (j = 0; j < state->nlookaheads; ++j)
|
||||||
for (k = 0; k < ntokens; ++k)
|
BITSET_EXECUTE (state->lookaheads[j], 0, k,
|
||||||
if (bitset_test (state->lookaheads[j], k)
|
{
|
||||||
&& state->lookaheads_rule[j]->number == rule->number)
|
if (state->lookaheads_rule[j]->number == rule->number)
|
||||||
nlookaheads++;
|
nlookaheads++;
|
||||||
|
});
|
||||||
|
|
||||||
/* Print them if there are. */
|
/* Print them if there are. */
|
||||||
if (nlookaheads)
|
if (nlookaheads)
|
||||||
{
|
{
|
||||||
fprintf (out, " [");
|
fprintf (out, " [");
|
||||||
for (j = 0; j < state->nlookaheads; ++j)
|
for (j = 0; j < state->nlookaheads; ++j)
|
||||||
for (k = 0; k < ntokens; ++k)
|
BITSET_EXECUTE (state->lookaheads[j], 0, k,
|
||||||
if (bitset_test (state->lookaheads[j], k)
|
{
|
||||||
&& state->lookaheads_rule[j]->number == rule->number)
|
if (state->lookaheads_rule[j]->number == rule->number)
|
||||||
fprintf (out, "%s%s",
|
fprintf (out, "%s%s",
|
||||||
symbol_tag_get (symbols[k]),
|
symbol_tag_get (symbols[k]),
|
||||||
--nlookaheads ? ", " : "");
|
--nlookaheads ? ", " : "");
|
||||||
|
});
|
||||||
fprintf (out, "]");
|
fprintf (out, "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user