[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
14-fyi-more-set-state-table.patch
From: |
Akim Demaille |
Subject: |
14-fyi-more-set-state-table.patch |
Date: |
Mon, 19 Nov 2001 10:02:47 +0100 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* src/lalr.c (initialize_LA): Only initialize LA. Let...
(set_state_table): handle the `lookaheads' members.
Index: src/lalr.c
--- src/lalr.c Thu, 15 Nov 2001 23:25:10 +0100 akim
+++ src/lalr.c Thu, 15 Nov 2001 23:32:27 +0100 akim
@@ -169,6 +169,39 @@
for (rp = first_reduction; rp; rp = rp->next)
state_table[rp->number].reduction_table = rp;
}
+
+ /* Initializing the lookaheads members. Please note that it must be
+ performed after having set some of the other members which are
+ used below. Change with extreme caution. */
+ {
+ int i;
+ int count = 0;
+ for (i = 0; i < nstates; i++)
+ {
+ int k;
+ reductions *rp = state_table[i].reduction_table;
+ shifts *sp = state_table[i].shift_table;
+
+ state_table[i].lookaheads = count;
+
+ if (rp
+ && (rp->nreds > 1
+ || (sp && !ISVAR
(state_table[sp->shifts[0]].accessing_symbol))))
+ count += rp->nreds;
+ else
+ state_table[i].consistent = 1;
+
+ if (sp)
+ for (k = 0; k < sp->nshifts; k++)
+ if (state_table[sp->shifts[k]].accessing_symbol
+ == error_token_number)
+ {
+ state_table[i].consistent = 0;
+ break;
+ }
+ }
+ state_table[nstates].lookaheads = count;
+ }
}
@@ -204,61 +237,23 @@
{
int i;
int j;
- int count = 0;
- reductions *rp;
- shifts *sp;
short *np;
+ reductions *rp;
- for (i = 0; i < nstates; i++)
- {
- int k;
-
- state_table[i].lookaheads = count;
-
- rp = state_table[i].reduction_table;
- sp = state_table[i].shift_table;
- if (rp
- && (rp->nreds > 1
- || (sp && !ISVAR (state_table[sp->shifts[0]].accessing_symbol))))
- count += rp->nreds;
- else
- state_table[i].consistent = 1;
-
- if (sp)
- for (k = 0; k < sp->nshifts; k++)
- if (state_table[sp->shifts[k]].accessing_symbol
- == error_token_number)
- {
- state_table[i].consistent = 0;
- break;
- }
- }
-
- state_table[nstates].lookaheads = count;
-
- if (count == 0)
- {
- LA = XCALLOC (unsigned, 1 * tokensetsize);
- LAruleno = XCALLOC (short, 1);
- lookback = XCALLOC (shorts *, 1);
- }
- else
- {
- LA = XCALLOC (unsigned, count * tokensetsize);
- LAruleno = XCALLOC (short, count);
- lookback = XCALLOC (shorts *, count);
- }
+ size_t nLA = state_table[nstates].lookaheads;
+ if (!nLA)
+ nLA = 1;
+
+ LA = XCALLOC (unsigned, nLA * tokensetsize);
+ LAruleno = XCALLOC (short, nLA);
+ lookback = XCALLOC (shorts *, nLA);
np = LAruleno;
for (i = 0; i < nstates; i++)
- {
- if (!state_table[i].consistent)
- {
- if ((rp = state_table[i].reduction_table))
- for (j = 0; j < rp->nreds; j++)
- *np++ = rp->rules[j];
- }
- }
+ if (!state_table[i].consistent)
+ if ((rp = state_table[i].reduction_table))
+ for (j = 0; j < rp->nreds; j++)
+ *np++ = rp->rules[j];
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 14-fyi-more-set-state-table.patch,
Akim Demaille <=