1 |
/* Compute look-ahead criteria for bison, |
/* Compute look-ahead criteria for Bison. |
2 |
|
|
3 |
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 |
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 |
4 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
5 |
|
|
80 |
state_number s; |
state_number s; |
81 |
goto_number *temp_map; |
goto_number *temp_map; |
82 |
|
|
83 |
goto_map = XCALLOC (goto_number, nvars + 1) - ntokens; |
CALLOC (goto_map, nvars + 1); |
84 |
temp_map = XCALLOC (goto_number, nvars + 1) - ntokens; |
CALLOC (temp_map, nvars + 1); |
85 |
|
|
86 |
ngotos = 0; |
ngotos = 0; |
87 |
for (s = 0; s < nstates; ++s) |
for (s = 0; s < nstates; ++s) |
93 |
if (ngotos >= GOTO_NUMBER_MAXIMUM) |
if (ngotos >= GOTO_NUMBER_MAXIMUM) |
94 |
abort (); |
abort (); |
95 |
ngotos++; |
ngotos++; |
96 |
goto_map[TRANSITION_SYMBOL (sp, i)]++; |
goto_map[TRANSITION_SYMBOL (sp, i) - ntokens]++; |
97 |
} |
} |
98 |
} |
} |
99 |
|
|
102 |
int i; |
int i; |
103 |
for (i = ntokens; i < nsyms; i++) |
for (i = ntokens; i < nsyms; i++) |
104 |
{ |
{ |
105 |
temp_map[i] = k; |
temp_map[i - ntokens] = k; |
106 |
k += goto_map[i]; |
k += goto_map[i - ntokens]; |
107 |
} |
} |
108 |
|
|
109 |
for (i = ntokens; i < nsyms; i++) |
for (i = ntokens; i < nsyms; i++) |
110 |
goto_map[i] = temp_map[i]; |
goto_map[i - ntokens] = temp_map[i - ntokens]; |
111 |
|
|
112 |
goto_map[nsyms] = ngotos; |
goto_map[nsyms - ntokens] = ngotos; |
113 |
temp_map[nsyms] = ngotos; |
temp_map[nsyms - ntokens] = ngotos; |
114 |
} |
} |
115 |
|
|
116 |
from_state = XCALLOC (state_number, ngotos); |
CALLOC (from_state, ngotos); |
117 |
to_state = XCALLOC (state_number, ngotos); |
CALLOC (to_state, ngotos); |
118 |
|
|
119 |
for (s = 0; s < nstates; ++s) |
for (s = 0; s < nstates; ++s) |
120 |
{ |
{ |
122 |
int i; |
int i; |
123 |
for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i) |
for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i) |
124 |
{ |
{ |
125 |
int k = temp_map[TRANSITION_SYMBOL (sp, i)]++; |
int k = temp_map[TRANSITION_SYMBOL (sp, i) - ntokens]++; |
126 |
from_state[k] = s; |
from_state[k] = s; |
127 |
to_state[k] = sp->states[i]->number; |
to_state[k] = sp->states[i]->number; |
128 |
} |
} |
129 |
} |
} |
130 |
|
|
131 |
XFREE (temp_map + ntokens); |
XFREE (temp_map); |
132 |
} |
} |
133 |
|
|
134 |
|
|
145 |
int middle; |
int middle; |
146 |
state_number s; |
state_number s; |
147 |
|
|
148 |
low = goto_map[sym]; |
low = goto_map[sym - ntokens]; |
149 |
high = goto_map[sym + 1] - 1; |
high = goto_map[sym - ntokens + 1] - 1; |
150 |
|
|
151 |
for (;;) |
for (;;) |
152 |
{ |
{ |
167 |
static void |
static void |
168 |
initialize_F (void) |
initialize_F (void) |
169 |
{ |
{ |
170 |
goto_number **reads = XCALLOC (goto_number *, ngotos); |
goto_number **reads = CALLOC (reads, ngotos); |
171 |
goto_number *edge = XCALLOC (goto_number, ngotos + 1); |
goto_number *edge = CALLOC (edge, ngotos + 1); |
172 |
int nedges = 0; |
int nedges = 0; |
173 |
|
|
174 |
int i; |
int i; |
187 |
for (; j < sp->num; j++) |
for (; j < sp->num; j++) |
188 |
{ |
{ |
189 |
symbol_number sym = TRANSITION_SYMBOL (sp, j); |
symbol_number sym = TRANSITION_SYMBOL (sp, j); |
190 |
if (nullable[sym]) |
if (nullable[sym - ntokens]) |
191 |
edge[nedges++] = map_goto (stateno, sym); |
edge[nedges++] = map_goto (stateno, sym); |
192 |
} |
} |
193 |
|
|
194 |
if (nedges) |
if (nedges) |
195 |
{ |
{ |
196 |
reads[i] = XCALLOC (goto_number, nedges + 1); |
CALLOC (reads[i], nedges + 1); |
197 |
memcpy (reads[i], edge, nedges * sizeof (edge[0])); |
memcpy (reads[i], edge, nedges * sizeof (edge[0])); |
198 |
reads[i][nedges] = -1; |
reads[i][nedges] = -1; |
199 |
nedges = 0; |
nedges = 0; |
214 |
add_lookback_edge (state *s, rule *r, int gotono) |
add_lookback_edge (state *s, rule *r, int gotono) |
215 |
{ |
{ |
216 |
int ri = state_reduction_find (s, r); |
int ri = state_reduction_find (s, r); |
217 |
goto_list *sp = XCALLOC (goto_list, 1); |
goto_list *sp = MALLOC (sp, 1); |
218 |
sp->next = lookback[(s->reductions->lookaheads - LA) + ri]; |
sp->next = lookback[(s->reductions->lookaheads - LA) + ri]; |
219 |
sp->value = gotono; |
sp->value = gotono; |
220 |
lookback[(s->reductions->lookaheads - LA) + ri] = sp; |
lookback[(s->reductions->lookaheads - LA) + ri] = sp; |
225 |
static void |
static void |
226 |
build_relations (void) |
build_relations (void) |
227 |
{ |
{ |
228 |
goto_number *edge = XCALLOC (goto_number, ngotos + 1); |
goto_number *edge = CALLOC (edge, ngotos + 1); |
229 |
state_number *states1 = XCALLOC (state_number, ritem_longest_rhs () + 1); |
state_number *states1 = CALLOC (states1, ritem_longest_rhs () + 1); |
230 |
int i; |
int i; |
231 |
|
|
232 |
includes = XCALLOC (goto_number *, ngotos); |
CALLOC (includes, ngotos); |
233 |
|
|
234 |
for (i = 0; i < ngotos; i++) |
for (i = 0; i < ngotos; i++) |
235 |
{ |
{ |
237 |
symbol_number symbol1 = states[to_state[i]]->accessing_symbol; |
symbol_number symbol1 = states[to_state[i]]->accessing_symbol; |
238 |
rule **rulep; |
rule **rulep; |
239 |
|
|
240 |
for (rulep = derives[symbol1]; *rulep; rulep++) |
for (rulep = derives[symbol1 - ntokens]; *rulep; rulep++) |
241 |
{ |
{ |
242 |
int done; |
int done; |
243 |
int length = 1; |
int length = 1; |
267 |
/* Downcasting from item_number to symbol_number. */ |
/* Downcasting from item_number to symbol_number. */ |
268 |
edge[nedges++] = map_goto (states1[--length], |
edge[nedges++] = map_goto (states1[--length], |
269 |
item_number_as_symbol_number (*rp)); |
item_number_as_symbol_number (*rp)); |
270 |
if (nullable[*rp]) |
if (nullable[*rp - ntokens]) |
271 |
done = 0; |
done = 0; |
272 |
} |
} |
273 |
} |
} |
276 |
if (nedges) |
if (nedges) |
277 |
{ |
{ |
278 |
int j; |
int j; |
279 |
includes[i] = XCALLOC (goto_number, nedges + 1); |
CALLOC (includes[i], nedges + 1); |
280 |
for (j = 0; j < nedges; j++) |
for (j = 0; j < nedges; j++) |
281 |
includes[i][j] = edge[j]; |
includes[i][j] = edge[j]; |
282 |
includes[i][nedges] = -1; |
includes[i][nedges] = -1; |
378 |
nLA = 1; |
nLA = 1; |
379 |
|
|
380 |
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); |
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); |
381 |
lookback = XCALLOC (goto_list *, nLA); |
CALLOC (lookback, nLA); |
382 |
|
|
383 |
/* Initialize the members LOOKAHEADS for each state which reductions |
/* Initialize the members LOOKAHEADS for each state which reductions |
384 |
require lookaheads. */ |
require lookaheads. */ |