static void
prepare_rules (void)
{
- int r;
+ rule_number_t r;
unsigned int i = 0;
item_number_t *rhs = XMALLOC (item_number_t, nritems);
unsigned int *prhs = XMALLOC (unsigned int, nrules + 1);
for (r = 1; r < nrules + 1; ++r)
{
- item_number_t *rhsp;
+ item_number_t *rhsp = NULL;
/* Index of rule R in RHS. */
prhs[r] = i;
/* RHS of the rule R. */
action_row (state_t *state)
{
int i;
- int default_rule = 0;
- reductions *redp = state->reductions;
- shifts *shiftp = state->shifts;
- errs *errp = state->errs;
+ rule_number_t default_rule = 0;
+ reductions_t *redp = state->reductions;
+ shifts_t *shiftp = state->shifts;
+ errs_t *errp = state->errs;
/* set nonzero to inhibit having any default reduction */
int nodefault = 0;
int conflicted = 0;
for (i = state->nlookaheads - 1; i >= 0; --i)
/* and find each token which the rule finds acceptable
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
token follows. */
- if (bitset_test (state->lookaheads[i], j))
- {
- if (actrow[j] != 0)
- conflicted = conflrow[j] = 1;
- actrow[j] = -state->lookaheads_rule[i]->number;
- }
+ if (actrow[j] != 0)
+ conflicted = conflrow[j] = 1;
+ actrow[j] = -state->lookaheads_rule[i]->number;
+ });
}
/* 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
to reduce. */
- for (i = 0; i < shiftp->nshifts; i++)
- {
- symbol_number_t symbol;
- state_number_t shift_state = shiftp->shifts[i];
- if (!shift_state)
- continue;
-
- symbol = states[shift_state]->accessing_symbol;
-
- if (ISVAR (symbol))
- break;
+ for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
+ if (!SHIFT_IS_DISABLED (shiftp, i))
+ {
+ symbol_number_t symbol = SHIFT_SYMBOL (shiftp, i);
+ state_number_t shift_state = shiftp->shifts[i];
- if (actrow[symbol] != 0)
- conflicted = conflrow[symbol] = 1;
- actrow[symbol] = state_number_as_int (shift_state);
+ if (actrow[symbol] != 0)
+ 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;
- }
+ /* 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
%nonassoc). For them, record SHRT_MIN as the action. */
for (i = 0; i < state->nlookaheads; i++)
{
int count = 0;
- int rule = -state->lookaheads_rule[i]->number;
- int j;
+ rule_number_t rule = state->lookaheads_rule[i]->number;
+ symbol_number_t j;
for (j = 0; j < ntokens; j++)
- if (actrow[j] == rule)
+ if (actrow[j] == -rule)
count++;
if (count > max)
{
int j;
for (j = 0; j < ntokens; j++)
- if (actrow[j] == default_rule && ! (glr_parser && conflrow[j]))
+ if (actrow[j] == -default_rule
+ && ! (glr_parser && conflrow[j]))
actrow[j] = 0;
}
- default_rule = -default_rule;
}
}
void
actions_output (FILE *out)
{
- int rule;
+ rule_number_t r;
fputs ("m4_define([b4_actions], \n[[", out);
- for (rule = 1; rule < nrules + 1; ++rule)
- if (rules[rule].action)
+ for (r = 1; r < nrules + 1; ++r)
+ if (rules[r].action)
{
- fprintf (out, " case %d:\n", rule);
+ fprintf (out, " case %d:\n", r);
if (!no_lines_flag)
fprintf (out, muscle_find ("linef"),
- rules[rule].action_location.first_line,
+ rules[r].action_location.first_line,
quotearg_style (c_quoting_style,
muscle_find ("filename")));
fprintf (out, " %s\n break;\n\n",
- rules[rule].action);
+ rules[r].action);
}
fputs ("]])\n\n", out);
}
static void
output_actions (void)
{
- state_number_t i;
-
/* That's a poor way to make sure the sizes are properly corelated,
in particular the signedness is not taking into account, but it's
not useless. */
output_conflicts ();
output_check ();
-
- for (i = 0; i < nstates; ++i)
- {
- free (states[i]->shifts);
- XFREE (states[i]->reductions);
- free (states[i]->errs);
- free (states[i]);
- }
- XFREE (states);
}
\f