mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 08:13:02 +00:00
* src/lalr.h (lookaheads): Removed array, which contents is now
member of... (state_t): this structure. * src/output.c, src/lalr.c, src/print_graph.c, src/conflicts.c: Adjust.
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
2001-11-19 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/lalr.h (lookaheads): Removed array, which contents is now
|
||||||
|
member of...
|
||||||
|
(state_t): this structure.
|
||||||
|
* src/output.c, src/lalr.c, src/print_graph.c, src/conflicts.c:
|
||||||
|
Adjust.
|
||||||
|
|
||||||
2001-11-19 Akim Demaille <akim@epita.fr>
|
2001-11-19 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/lalr.h (consistent): Removed array, which contents is now
|
* src/lalr.h (consistent): Removed array, which contents is now
|
||||||
|
|||||||
@@ -210,13 +210,13 @@ set_conflicts (int state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
k = lookaheads[state + 1];
|
k = state_table[state + 1].lookaheads;
|
||||||
fp4 = lookaheadset + tokensetsize;
|
fp4 = lookaheadset + tokensetsize;
|
||||||
|
|
||||||
/* Loop over all rules which require lookahead in this state. First
|
/* Loop over all rules which require lookahead in this state. First
|
||||||
check for shift-reduce conflict, and try to resolve using
|
check for shift-reduce conflict, and try to resolve using
|
||||||
precedence */
|
precedence */
|
||||||
for (i = lookaheads[state]; i < k; i++)
|
for (i = state_table[state].lookaheads; i < k; i++)
|
||||||
if (rprec[LAruleno[i]])
|
if (rprec[LAruleno[i]])
|
||||||
{
|
{
|
||||||
fp1 = LA + i * tokensetsize;
|
fp1 = LA + i * tokensetsize;
|
||||||
@@ -236,7 +236,7 @@ set_conflicts (int state)
|
|||||||
|
|
||||||
/* Loop over all rules which require lookahead in this state. Check
|
/* Loop over all rules which require lookahead in this state. Check
|
||||||
for conflicts not resolved above. */
|
for conflicts not resolved above. */
|
||||||
for (i = lookaheads[state]; i < k; i++)
|
for (i = state_table[state].lookaheads; i < k; i++)
|
||||||
{
|
{
|
||||||
fp1 = LA + i * tokensetsize;
|
fp1 = LA + i * tokensetsize;
|
||||||
fp2 = fp1;
|
fp2 = fp1;
|
||||||
@@ -309,10 +309,10 @@ count_sr_conflicts (int state)
|
|||||||
SETBIT (shiftset, symbol);
|
SETBIT (shiftset, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
k = lookaheads[state + 1];
|
k = state_table[state + 1].lookaheads;
|
||||||
fp3 = lookaheadset + tokensetsize;
|
fp3 = lookaheadset + tokensetsize;
|
||||||
|
|
||||||
for (i = lookaheads[state]; i < k; i++)
|
for (i = state_table[state].lookaheads; i < k; i++)
|
||||||
{
|
{
|
||||||
fp1 = LA + i * tokensetsize;
|
fp1 = LA + i * tokensetsize;
|
||||||
fp2 = lookaheadset;
|
fp2 = lookaheadset;
|
||||||
@@ -359,8 +359,8 @@ count_rr_conflicts (int state)
|
|||||||
|
|
||||||
int rrc_count = 0;
|
int rrc_count = 0;
|
||||||
|
|
||||||
int m = lookaheads[state];
|
int m = state_table[state].lookaheads;
|
||||||
int n = lookaheads[state + 1];
|
int n = state_table[state + 1].lookaheads;
|
||||||
|
|
||||||
if (n - m < 2)
|
if (n - m < 2)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -565,8 +565,8 @@ print_reductions (FILE *out, int state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m = lookaheads[state];
|
m = state_table[state].lookaheads;
|
||||||
n = lookaheads[state + 1];
|
n = state_table[state + 1].lookaheads;
|
||||||
|
|
||||||
if (n - m == 1 && !nodefault)
|
if (n - m == 1 && !nodefault)
|
||||||
{
|
{
|
||||||
|
|||||||
24
src/lalr.c
24
src/lalr.c
@@ -38,7 +38,6 @@
|
|||||||
state_t *state_table = NULL;
|
state_t *state_table = NULL;
|
||||||
|
|
||||||
int tokensetsize;
|
int tokensetsize;
|
||||||
short *lookaheads;
|
|
||||||
short *LAruleno;
|
short *LAruleno;
|
||||||
unsigned *LA;
|
unsigned *LA;
|
||||||
|
|
||||||
@@ -145,7 +144,10 @@ digraph (short **relation)
|
|||||||
static void
|
static void
|
||||||
set_state_table (void)
|
set_state_table (void)
|
||||||
{
|
{
|
||||||
state_table = XCALLOC (state_t, nstates);
|
/* NSTATES + 1 because lookahead for the pseudo state number NSTATES
|
||||||
|
might be used (see conflicts.c). It is too opaque for me to
|
||||||
|
provide a probably less hacky implementation. --akim */
|
||||||
|
state_table = XCALLOC (state_t, nstates + 1);
|
||||||
|
|
||||||
{
|
{
|
||||||
core *sp;
|
core *sp;
|
||||||
@@ -202,19 +204,16 @@ initialize_LA (void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int count;
|
int count = 0;
|
||||||
reductions *rp;
|
reductions *rp;
|
||||||
shifts *sp;
|
shifts *sp;
|
||||||
short *np;
|
short *np;
|
||||||
|
|
||||||
lookaheads = XCALLOC (short, nstates + 1);
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
for (i = 0; i < nstates; i++)
|
for (i = 0; i < nstates; i++)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
lookaheads[i] = count;
|
state_table[i].lookaheads = count;
|
||||||
|
|
||||||
rp = state_table[i].reduction_table;
|
rp = state_table[i].reduction_table;
|
||||||
sp = state_table[i].shift_table;
|
sp = state_table[i].shift_table;
|
||||||
@@ -235,7 +234,7 @@ initialize_LA (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lookaheads[nstates] = count;
|
state_table[nstates].lookaheads = count;
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
@@ -450,8 +449,8 @@ add_lookback_edge (int stateno, int ruleno, int gotono)
|
|||||||
int found;
|
int found;
|
||||||
shorts *sp;
|
shorts *sp;
|
||||||
|
|
||||||
i = lookaheads[stateno];
|
i = state_table[stateno].lookaheads;
|
||||||
k = lookaheads[stateno + 1];
|
k = state_table[stateno + 1].lookaheads;
|
||||||
found = 0;
|
found = 0;
|
||||||
while (!found && i < k)
|
while (!found && i < k)
|
||||||
{
|
{
|
||||||
@@ -653,8 +652,7 @@ compute_lookaheads (void)
|
|||||||
shorts *sptmp; /* JF */
|
shorts *sptmp; /* JF */
|
||||||
|
|
||||||
rowp = LA;
|
rowp = LA;
|
||||||
n = lookaheads[nstates];
|
for (i = 0; i < state_table[nstates].lookaheads; i++)
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
{
|
||||||
fp3 = rowp + tokensetsize;
|
fp3 = rowp + tokensetsize;
|
||||||
for (sp = lookback[i]; sp; sp = sp->next)
|
for (sp = lookback[i]; sp; sp = sp->next)
|
||||||
@@ -668,7 +666,7 @@ compute_lookaheads (void)
|
|||||||
rowp = fp3;
|
rowp = fp3;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < state_table[nstates].lookaheads; i++)
|
||||||
{
|
{
|
||||||
/* JF removed ref to freed storage */
|
/* JF removed ref to freed storage */
|
||||||
for (sp = lookback[i]; sp; sp = sptmp)
|
for (sp = lookback[i]; sp; sp = sptmp)
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ typedef struct state_s
|
|||||||
/* Nonzero if no lookahead is needed to decide what to do in state
|
/* Nonzero if no lookahead is needed to decide what to do in state
|
||||||
S. */
|
S. */
|
||||||
char consistent;
|
char consistent;
|
||||||
|
|
||||||
|
short lookaheads;
|
||||||
} state_t;
|
} state_t;
|
||||||
|
|
||||||
/* All the decorated states, indexed by the state number. Warning:
|
/* All the decorated states, indexed by the state number. Warning:
|
||||||
@@ -91,9 +93,7 @@ typedef struct state_s
|
|||||||
extern state_t *state_table;
|
extern state_t *state_table;
|
||||||
|
|
||||||
extern int tokensetsize;
|
extern int tokensetsize;
|
||||||
extern short *lookaheads;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* The number of lookaheads. */
|
||||||
|
extern size_t nlookaheads;
|
||||||
#endif /* !LALR_H_ */
|
#endif /* !LALR_H_ */
|
||||||
|
|||||||
@@ -348,8 +348,8 @@ action_row (int state)
|
|||||||
{
|
{
|
||||||
/* loop over all the rules available here which require
|
/* loop over all the rules available here which require
|
||||||
lookahead */
|
lookahead */
|
||||||
m = lookaheads[state];
|
m = state_table[state].lookaheads;
|
||||||
n = lookaheads[state + 1];
|
n = state_table[state + 1].lookaheads;
|
||||||
|
|
||||||
for (i = n - 1; i >= m; i--)
|
for (i = n - 1; i >= m; i--)
|
||||||
{
|
{
|
||||||
@@ -928,7 +928,6 @@ output_actions (void)
|
|||||||
token_actions ();
|
token_actions ();
|
||||||
free_shifts ();
|
free_shifts ();
|
||||||
free_reductions ();
|
free_reductions ();
|
||||||
XFREE (lookaheads);
|
|
||||||
XFREE (LA);
|
XFREE (LA);
|
||||||
XFREE (LAruleno);
|
XFREE (LAruleno);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user