+2001-12-27 Akim Demaille <akim@epita.fr>
+
+ * src/state.h, src/state.c (reductions_new): New.
+ * src/LR0.c (set_state_table): Let all the states have a
+ `reductions', even if reduced to 0.
+ (save_reductions): Adjust.
+ * src/lalr.c (initialize_LA, initialize_lookaheads): Adjust.
+ * src/print.c (print_reductions, print_actions): Adjust.
+ * src/output.c (action_row): Adjust.
+
+
2001-12-27 Akim Demaille <akim@epita.fr>
* src/state.h, src/state.c (errs_new, errs_dup): New.
}
/* Make a reductions structure and copy the data into it. */
-
- if (count)
- {
- reductions *p = REDUCTIONS_ALLOC (count);
- p->nreds = count;
- shortcpy (p->rules, redset, count);
-
- this_state->reductions = p;
- }
+ this_state->reductions = reductions_new (count);
+ shortcpy (this_state->reductions->rules, redset, count);
}
\f
for (sp = first_state; sp; sp = sp->next)
{
/* Pessimization, but simplification of the code: make sure all
- the states have a shifts and errs, even if reduced to 0. */
+ the states have a shifts, errs, and reductions, even if
+ reduced to 0. */
if (!sp->shifts)
sp->shifts = shifts_new (0);
if (!sp->errs)
sp->errs = errs_new (0);
+ if (!sp->reductions)
+ sp->reductions = reductions_new (0);
state_table[sp->number] = sp;
}
int i;
int j;
short *np;
- reductions *rp;
/* Avoid having to special case 0. */
if (!nLA)
np = LAruleno;
for (i = 0; i < nstates; i++)
if (!state_table[i]->consistent)
- if ((rp = state_table[i]->reductions))
- for (j = 0; j < rp->nreds; j++)
- *np++ = rp->rules[j];
+ for (j = 0; j < state_table[i]->reductions->nreds; j++)
+ *np++ = state_table[i]->reductions->rules[j];
}
reductions *rp = state_table[i]->reductions;
shifts *sp = state_table[i]->shifts;
- if (rp
- && (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0))))
+ /* We need a lookahead either to distinguish different
+ reductions (i.e., there are two or more), or to distinguish a
+ reduction from a shift. Otherwise, it is straightforward,
+ and the state is `consistent'. */
+ if (rp->nreds > 1
+ || (rp->nreds == 1 && sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))
nlookaheads += rp->nreds;
else
state_table[i]->consistent = 1;
int i;
int default_rule = 0;
reductions *redp = state->reductions;
- int nreds = redp ? redp->nreds : 0;
shifts *shiftp = state->shifts;
errs *errp = state->errs;
/* set nonzero to inhibit having any default reduction */
for (i = 0; i < ntokens; i++)
actrow[i] = 0;
- if (nreds >= 1)
+ if (redp->nreds >= 1)
{
int j;
/* loop over all the rules available here which require
/* Now find the most common reduction and make it the default action
for this state. */
- if (nreds >= 1 && !nodefault)
+ if (redp->nreds >= 1 && !nodefault)
{
if (state->consistent)
default_rule = redp->rules[0];
errs *errp = state->errs;
int nodefault = 0;
+ if (redp->nreds == 0)
+ return;
+
if (state->consistent)
{
int rule = redp->rules[0];
reductions *redp = state->reductions;
shifts *shiftp = state->shifts;
- if (!shiftp->nshifts && !redp)
+ if (shiftp->nshifts == 0 && redp->nreds == 0)
{
if (final_state == state->number)
fprintf (out, _(" $default\taccept\n"));
print_shifts (out, state);
print_errs (out, state);
- if (redp)
- print_reductions (out, state);
+ print_reductions (out, state);
print_gotos (out, state);
}
memcpy (res->errs, src->errs, src->nerrs);
return res;
}
+
+/*-------------------------------------.
+| Create a new array of N reductions. |
+`-------------------------------------*/
+
+#define REDUCTIONS_ALLOC(Nreductions) \
+ (reductions *) xcalloc ((unsigned) (sizeof (reductions) \
+ + (Nreductions - 1) * sizeof (short)), 1)
+
+reductions *
+reductions_new (int n)
+{
+ reductions *res = REDUCTIONS_ALLOC (n);
+ res->nreds = n;
+ return res;
+}
short rules[1];
} reductions;
-#define REDUCTIONS_ALLOC(Nreductions) \
- (reductions *) xcalloc ((unsigned) (sizeof (reductions) \
- + (Nreductions - 1) * sizeof (short)), 1)
-
+reductions *reductions_new PARAMS ((int n));
/*----------.