150 |
state_table[sp->number] = sp; |
state_table[sp->number] = sp; |
151 |
} |
} |
152 |
|
|
|
{ |
|
|
shifts *sp; |
|
|
for (sp = first_shift; sp; sp = sp->next) |
|
|
assert (state_table[sp->number]->shifts == sp); |
|
|
} |
|
|
|
|
153 |
/* Pessimization, but simplification of the code: make sure all the |
/* Pessimization, but simplification of the code: make sure all the |
154 |
states have a shifts, even if reduced to 0 shifts. */ |
states have a shifts, even if reduced to 0 shifts. */ |
155 |
{ |
{ |
222 |
static void |
static void |
223 |
set_goto_map (void) |
set_goto_map (void) |
224 |
{ |
{ |
225 |
shifts *sp; |
int state; |
226 |
int i; |
int i; |
227 |
int symbol; |
int symbol; |
228 |
int k; |
int k; |
229 |
short *temp_map; |
short *temp_map; |
230 |
int state2; |
int state2; |
|
int state1; |
|
231 |
|
|
232 |
goto_map = XCALLOC (short, nvars + 1) - ntokens; |
goto_map = XCALLOC (short, nvars + 1) - ntokens; |
233 |
temp_map = XCALLOC (short, nvars + 1) - ntokens; |
temp_map = XCALLOC (short, nvars + 1) - ntokens; |
234 |
|
|
235 |
ngotos = 0; |
ngotos = 0; |
236 |
for (sp = first_shift; sp; sp = sp->next) |
for (state = 0; state < nstates; ++state) |
237 |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
{ |
238 |
{ |
shifts *sp = state_table[state]->shifts; |
239 |
symbol = state_table[sp->shifts[i]]->accessing_symbol; |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
240 |
|
{ |
241 |
|
symbol = state_table[sp->shifts[i]]->accessing_symbol; |
242 |
|
|
243 |
if (ngotos == MAXSHORT) |
if (ngotos == MAXSHORT) |
244 |
fatal (_("too many gotos (max %d)"), MAXSHORT); |
fatal (_("too many gotos (max %d)"), MAXSHORT); |
245 |
|
|
246 |
ngotos++; |
ngotos++; |
247 |
goto_map[symbol]++; |
goto_map[symbol]++; |
248 |
} |
} |
249 |
|
} |
250 |
|
|
251 |
k = 0; |
k = 0; |
252 |
for (i = ntokens; i < nsyms; i++) |
for (i = ntokens; i < nsyms; i++) |
264 |
from_state = XCALLOC (short, ngotos); |
from_state = XCALLOC (short, ngotos); |
265 |
to_state = XCALLOC (short, ngotos); |
to_state = XCALLOC (short, ngotos); |
266 |
|
|
267 |
for (sp = first_shift; sp; sp = sp->next) |
for (state = 0; state < nstates; ++state) |
268 |
{ |
{ |
269 |
state1 = sp->number; |
shifts *sp = state_table[state]->shifts; |
270 |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
271 |
{ |
{ |
272 |
state2 = sp->shifts[i]; |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
273 |
symbol = state_table[state2]->accessing_symbol; |
{ |
274 |
|
state2 = sp->shifts[i]; |
275 |
|
symbol = state_table[state2]->accessing_symbol; |
276 |
|
|
277 |
k = temp_map[symbol]++; |
k = temp_map[symbol]++; |
278 |
from_state[k] = state1; |
from_state[k] = state; |
279 |
to_state[k] = state2; |
to_state[k] = state2; |
280 |
|
} |
281 |
} |
} |
282 |
} |
} |
283 |
|
|