311 |
} |
} |
312 |
|
|
313 |
|
|
314 |
|
/*---------------------------------. |
315 |
|
| Create a new array of N shitfs. | |
316 |
|
`---------------------------------*/ |
317 |
|
|
318 |
|
static shifts * |
319 |
|
shifts_new (int n) |
320 |
|
{ |
321 |
|
shifts *res = SHIFTS_ALLOC (n); |
322 |
|
res->nshifts = n; |
323 |
|
return res; |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
/*------------------------------------------------------------. |
328 |
|
| Save the NSHIFTS of SHIFTSET into the current linked list. | |
329 |
|
`------------------------------------------------------------*/ |
330 |
|
|
331 |
static void |
static void |
332 |
save_shifts (void) |
save_shifts (void) |
333 |
{ |
{ |
334 |
shifts *p = SHIFTS_ALLOC (nshifts); |
shifts *p = shifts_new (nshifts); |
335 |
|
|
336 |
p->number = this_state->number; |
p->number = this_state->number; |
|
p->nshifts = nshifts; |
|
337 |
|
|
338 |
shortcpy (p->shifts, shiftset, nshifts); |
shortcpy (p->shifts, shiftset, nshifts); |
339 |
|
|
364 |
last_state = statep; |
last_state = statep; |
365 |
|
|
366 |
/* Make a shift from this state to (what will be) the final state. */ |
/* Make a shift from this state to (what will be) the final state. */ |
367 |
sp = SHIFTS_ALLOC (1); |
sp = shifts_new (1); |
368 |
sp->number = nstates++; |
sp->number = nstates++; |
|
sp->nshifts = 1; |
|
369 |
sp->shifts[0] = nstates; |
sp->shifts[0] = nstates; |
370 |
|
|
371 |
last_shift->next = sp; |
last_shift->next = sp; |
420 |
|
|
421 |
if (sp && sp->number == k) |
if (sp && sp->number == k) |
422 |
{ |
{ |
423 |
sp2 = SHIFTS_ALLOC (sp->nshifts + 1); |
sp2 = shifts_new (sp->nshifts + 1); |
424 |
sp2->number = k; |
sp2->number = k; |
|
sp2->nshifts = sp->nshifts + 1; |
|
425 |
sp2->shifts[0] = nstates; |
sp2->shifts[0] = nstates; |
426 |
for (i = sp->nshifts; i > 0; i--) |
for (i = sp->nshifts; i > 0; i--) |
427 |
sp2->shifts[i] = sp->shifts[i - 1]; |
sp2->shifts[i] = sp->shifts[i - 1]; |
436 |
} |
} |
437 |
else |
else |
438 |
{ |
{ |
439 |
sp2 = SHIFTS_ALLOC (1); |
sp2 = shifts_new (1); |
440 |
sp2->number = k; |
sp2->number = k; |
|
sp2->nshifts = 1; |
|
441 |
sp2->shifts[0] = nstates; |
sp2->shifts[0] = nstates; |
442 |
|
|
443 |
/* Patch sp2 into the chain of shifts between sp1 and sp. */ |
/* Patch sp2 into the chain of shifts between sp1 and sp. */ |
454 |
going to the next-to-final state (yet to be made). */ |
going to the next-to-final state (yet to be made). */ |
455 |
sp = first_shift; |
sp = first_shift; |
456 |
|
|
457 |
sp2 = SHIFTS_ALLOC (sp->nshifts + 1); |
sp2 = shifts_new (sp->nshifts + 1); |
|
sp2->nshifts = sp->nshifts + 1; |
|
458 |
|
|
459 |
/* Stick this shift into the vector at the proper place. */ |
/* Stick this shift into the vector at the proper place. */ |
460 |
statep = first_state->next; |
statep = first_state->next; |
486 |
{ |
{ |
487 |
/* The initial state didn't even have any shifts. |
/* The initial state didn't even have any shifts. |
488 |
Give it one shift, to the next-to-final state. */ |
Give it one shift, to the next-to-final state. */ |
489 |
sp = SHIFTS_ALLOC (1); |
sp = shifts_new (1); |
|
sp->nshifts = 1; |
|
490 |
sp->shifts[0] = nstates; |
sp->shifts[0] = nstates; |
491 |
|
|
492 |
/* Patch sp into the chain of shifts at the beginning. */ |
/* Patch sp into the chain of shifts at the beginning. */ |
503 |
/* There are no shifts for any state. |
/* There are no shifts for any state. |
504 |
Make one shift, from the initial state to the next-to-final state. */ |
Make one shift, from the initial state to the next-to-final state. */ |
505 |
|
|
506 |
sp = SHIFTS_ALLOC (1); |
sp = shifts_new (1); |
|
sp->nshifts = 1; |
|
507 |
sp->shifts[0] = nstates; |
sp->shifts[0] = nstates; |
508 |
|
|
509 |
/* Initialize the chain of shifts with sp. */ |
/* Initialize the chain of shifts with sp. */ |
524 |
last_state = statep; |
last_state = statep; |
525 |
|
|
526 |
/* Make the shift from the final state to the termination state. */ |
/* Make the shift from the final state to the termination state. */ |
527 |
sp = SHIFTS_ALLOC (1); |
sp = shifts_new (1); |
528 |
sp->number = nstates++; |
sp->number = nstates++; |
|
sp->nshifts = 1; |
|
529 |
sp->shifts[0] = nstates; |
sp->shifts[0] = nstates; |
530 |
last_shift->next = sp; |
last_shift->next = sp; |
531 |
last_shift = sp; |
last_shift = sp; |