* src/state.h (state_t): Rename lookaheads as lookaheadsp.

nlookaheads is a new member.
Adjust all users.
* src/lalr.h (nlookaheads): Remove this orphan declaration.
* src/lalr.c (initialize_lookaheads): Set nlookaheads for each
state.
This commit is contained in:
Akim Demaille
2001-12-17 17:32:59 +00:00
parent 331dbc1bb7
commit 3877f72ba2
6 changed files with 37 additions and 24 deletions

View File

@@ -1,3 +1,13 @@
2001-12-17 Akim Demaille <akim@epita.fr>
* src/state.h (state_t): Rename lookaheads as lookaheadsp.
nlookaheads is a new member.
Adjust all users.
* src/lalr.h (nlookaheads): Remove this orphan declaration.
* src/lalr.c (initialize_lookaheads): Set nlookaheads for each
state.
2001-12-17 Akim Demaille <akim@epita.fr>
* src/files.h, src/files.c (open_files, close_files): Remove.

View File

@@ -172,8 +172,8 @@ set_conflicts (int state)
/* Loop over all rules which require lookahead in this state. First
check for shift-reduce conflict, and try to resolve using
precedence */
for (i = state_table[state]->lookaheads;
i < state_table[state + 1]->lookaheads;
for (i = state_table[state]->lookaheadsp;
i < state_table[state + 1]->lookaheadsp;
++i)
if (rule_table[LAruleno[i]].prec)
for (j = 0; j < tokensetsize; ++j)
@@ -186,8 +186,8 @@ set_conflicts (int state)
/* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. */
for (i = state_table[state]->lookaheads;
i < state_table[state + 1]->lookaheads;
for (i = state_table[state]->lookaheadsp;
i < state_table[state + 1]->lookaheadsp;
++i)
{
for (j = 0; j < tokensetsize; ++j)
@@ -237,8 +237,8 @@ count_sr_conflicts (int state)
if (!SHIFT_IS_DISABLED (shiftp, i))
SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i));
for (i = state_table[state]->lookaheads;
i < state_table[state + 1]->lookaheads;
for (i = state_table[state]->lookaheadsp;
i < state_table[state + 1]->lookaheadsp;
++i)
for (k = 0; k < tokensetsize; ++k)
lookaheadset[k] |= LA (i)[k];
@@ -264,8 +264,8 @@ count_rr_conflicts (int state)
int i;
int rrc_count = 0;
int m = state_table[state]->lookaheads;
int n = state_table[state + 1]->lookaheads;
int m = state_table[state]->lookaheadsp;
int n = state_table[state + 1]->lookaheadsp;
if (n - m < 2)
return 0;
@@ -414,8 +414,8 @@ print_reductions (FILE *out, int state)
{
int i;
int j;
int m = state_table[state]->lookaheads;
int n = state_table[state + 1]->lookaheads;
int m = state_table[state]->lookaheadsp;
int n = state_table[state + 1]->lookaheadsp;
shifts *shiftp = state_table[state]->shifts;
errs *errp = state_table[state]->errs;
int nodefault = 0;

View File

@@ -140,7 +140,7 @@ initialize_LA (void)
short *np;
reductions *rp;
size_t nLA = state_table[nstates]->lookaheads;
size_t nLA = state_table[nstates]->lookaheadsp;
if (!nLA)
nLA = 1;
@@ -314,8 +314,8 @@ add_lookback_edge (int stateno, int ruleno, int gotono)
int found;
shorts *sp;
i = state_table[stateno]->lookaheads;
k = state_table[stateno + 1]->lookaheads;
i = state_table[stateno]->lookaheadsp;
k = state_table[stateno + 1]->lookaheadsp;
found = 0;
while (!found && i < k)
{
@@ -516,7 +516,7 @@ compute_lookaheads (void)
int i;
shorts *sp;
for (i = 0; i < state_table[nstates]->lookaheads; i++)
for (i = 0; i < state_table[nstates]->lookaheadsp; i++)
for (sp = lookback[i]; sp; sp = sp->next)
{
int size = LA (i + 1) - LA (i);
@@ -526,7 +526,7 @@ compute_lookaheads (void)
}
/* Free LOOKBACK. */
for (i = 0; i < state_table[nstates]->lookaheads; i++)
for (i = 0; i < state_table[nstates]->lookaheadsp; i++)
LIST_FREE (shorts, lookback[i]);
XFREE (lookback);
@@ -546,14 +546,13 @@ initialize_lookaheads (void)
for (i = 0; i < nstates; i++)
{
int k;
int nlookaheads = 0;
reductions *rp = state_table[i]->reductions;
shifts *sp = state_table[i]->shifts;
state_table[i]->lookaheads = count;
if (rp
&& (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0))))
count += rp->nreds;
nlookaheads += rp->nreds;
else
state_table[i]->consistent = 1;
@@ -563,11 +562,15 @@ initialize_lookaheads (void)
state_table[i]->consistent = 0;
break;
}
state_table[i]->nlookaheads = nlookaheads;
state_table[i]->lookaheadsp = count;
count += nlookaheads;
}
/* Seems to be needed by conflicts.c. */
state_table[nstates] = STATE_ALLOC (0);
state_table[nstates]->lookaheads = count;
state_table[nstates]->lookaheadsp = count;
}
void

View File

@@ -74,6 +74,4 @@ extern state_t **state_table;
extern int tokensetsize;
/* The number of lookaheads. */
extern size_t nlookaheads;
#endif /* !LALR_H_ */

View File

@@ -344,8 +344,8 @@ action_row (int state)
int j;
/* loop over all the rules available here which require
lookahead */
m = state_table[state]->lookaheads;
n = state_table[state + 1]->lookaheads;
m = state_table[state]->lookaheadsp;
n = state_table[state + 1]->lookaheadsp;
for (i = n - 1; i >= m; i--)
/* and find each token which the rule finds acceptable

View File

@@ -189,7 +189,9 @@ typedef struct state_s
char consistent;
/* Used in LALR, not LR(0). */
short lookaheads;
/* Pseudo pointer into LA. */
short lookaheadsp;
int nlookaheads;
/* Its items. */
short nitems;