[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
16-fyi-all-reds.patch
From: |
Akim Demaille |
Subject: |
16-fyi-all-reds.patch |
Date: |
Thu, 27 Dec 2001 19:02:05 +0100 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* 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.
Index: src/LR0.c
--- src/LR0.c Thu, 27 Dec 2001 10:53:35 +0100 akim
+++ src/LR0.c Thu, 27 Dec 2001 10:59:26 +0100 akim
@@ -522,15 +522,8 @@
}
/* 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);
}
@@ -547,11 +540,14 @@
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;
}
Index: src/lalr.c
--- src/lalr.c Thu, 27 Dec 2001 10:29:38 +0100 akim
+++ src/lalr.c Thu, 27 Dec 2001 11:08:54 +0100 akim
@@ -137,7 +137,6 @@
int i;
int j;
short *np;
- reductions *rp;
/* Avoid having to special case 0. */
if (!nLA)
@@ -150,9 +149,8 @@
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];
}
@@ -525,8 +523,12 @@
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;
Index: src/output.c
--- src/output.c Thu, 27 Dec 2001 10:53:35 +0100 akim
+++ src/output.c Thu, 27 Dec 2001 11:02:56 +0100 akim
@@ -326,7 +326,6 @@
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 */
@@ -335,7 +334,7 @@
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
@@ -384,7 +383,7 @@
/* 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];
Index: src/print.c
--- src/print.c Thu, 27 Dec 2001 10:53:35 +0100 akim
+++ src/print.c Thu, 27 Dec 2001 11:13:48 +0100 akim
@@ -167,6 +167,9 @@
errs *errp = state->errs;
int nodefault = 0;
+ if (redp->nreds == 0)
+ return;
+
if (state->consistent)
{
int rule = redp->rules[0];
@@ -303,7 +306,7 @@
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"));
@@ -314,8 +317,7 @@
print_shifts (out, state);
print_errs (out, state);
- if (redp)
- print_reductions (out, state);
+ print_reductions (out, state);
print_gotos (out, state);
}
Index: src/state.c
--- src/state.c Thu, 27 Dec 2001 10:53:35 +0100 akim
+++ src/state.c Thu, 27 Dec 2001 10:59:15 +0100 akim
@@ -64,3 +64,19 @@
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;
+}
Index: src/state.h
--- src/state.h Thu, 27 Dec 2001 10:53:35 +0100 akim
+++ src/state.h Thu, 27 Dec 2001 10:55:57 +0100 akim
@@ -158,10 +158,7 @@
short rules[1];
} reductions;
-#define REDUCTIONS_ALLOC(Nreductions) \
- (reductions *) xcalloc ((unsigned) (sizeof (reductions) \
- + (Nreductions - 1) * sizeof (short)), 1)
-
+reductions *reductions_new PARAMS ((int n));
/*----------.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 16-fyi-all-reds.patch,
Akim Demaille <=