1 |
/* Compute look-ahead criteria for bison, |
/* Compute look-ahead criteria for bison, |
2 |
Copyright 1984, 1986, 1989, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 |
3 |
|
Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of Bison, the GNU Compiler Compiler. |
This file is part of Bison, the GNU Compiler Compiler. |
6 |
|
|
41 |
/* All the decorated states, indexed by the state number. */ |
/* All the decorated states, indexed by the state number. */ |
42 |
state_t **states = NULL; |
state_t **states = NULL; |
43 |
|
|
44 |
short *LAruleno = NULL; |
rule_t **LArule = NULL; |
45 |
bitsetv LA = NULL; |
bitsetv LA = NULL; |
46 |
size_t nLA; |
size_t nLA; |
47 |
|
|
135 |
{ |
{ |
136 |
size_t i; |
size_t i; |
137 |
int j; |
int j; |
138 |
short *np; |
rule_t **np; |
139 |
|
|
140 |
/* Avoid having to special case 0. */ |
/* Avoid having to special case 0. */ |
141 |
if (!nLA) |
if (!nLA) |
142 |
nLA = 1; |
nLA = 1; |
143 |
|
|
144 |
LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); |
LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); |
145 |
LAruleno = XCALLOC (short, nLA); |
LArule = XCALLOC (rule_t *, nLA); |
146 |
lookback = XCALLOC (shorts *, nLA); |
lookback = XCALLOC (shorts *, nLA); |
147 |
|
|
148 |
np = LAruleno; |
np = LArule; |
149 |
for (i = 0; i < nstates; i++) |
for (i = 0; i < nstates; i++) |
150 |
if (!states[i]->consistent) |
if (!states[i]->consistent) |
151 |
for (j = 0; j < states[i]->reductions->nreds; j++) |
for (j = 0; j < states[i]->reductions->nreds; j++) |
152 |
*np++ = states[i]->reductions->rules[j]; |
*np++ = &rules[states[i]->reductions->rules[j]]; |
153 |
} |
} |
154 |
|
|
155 |
|
|
297 |
shorts *sp; |
shorts *sp; |
298 |
|
|
299 |
for (i = 0; i < state->nlookaheads; ++i) |
for (i = 0; i < state->nlookaheads; ++i) |
300 |
if (LAruleno[state->lookaheadsp + i] == ruleno) |
if (LArule[state->lookaheadsp + i]->number == ruleno) |
301 |
break; |
break; |
302 |
|
|
303 |
assert (LAruleno[state->lookaheadsp + i] == ruleno); |
assert (LArule[state->lookaheadsp + i]->number == ruleno); |
304 |
|
|
305 |
sp = XCALLOC (shorts, 1); |
sp = XCALLOC (shorts, 1); |
306 |
sp->next = lookback[state->lookaheadsp + i]; |
sp->next = lookback[state->lookaheadsp + i]; |
562 |
if (bitset_test (LA[states[i]->lookaheadsp + j], j)) |
if (bitset_test (LA[states[i]->lookaheadsp + j], j)) |
563 |
fprintf (out, " on %d (%s) -> rule %d\n", |
fprintf (out, " on %d (%s) -> rule %d\n", |
564 |
k, symbols[k]->tag, |
k, symbols[k]->tag, |
565 |
-LAruleno[states[i]->lookaheadsp + j] - 1); |
LArule[states[i]->lookaheadsp + j]->number - 1); |
566 |
} |
} |
567 |
fprintf (out, "Lookaheads: END\n"); |
fprintf (out, "Lookaheads: END\n"); |
568 |
} |
} |