(save_shifts, insert_start_shift, augment_automaton): Use it.
+2001-11-28 Akim Demaille <akim@epita.fr>
+
+ * src/LR0.c (shifts_new): New.
+ (save_shifts, insert_start_shift, augment_automaton): Use it.
+
2001-11-28 Akim Demaille <akim@epita.fr>
* src/closure.c (closure): `b' and `ruleno' denote the same value:
2001-11-28 Akim Demaille <akim@epita.fr>
* src/closure.c (closure): `b' and `ruleno' denote the same value:
+/*---------------------------------.
+| Create a new array of N shitfs. |
+`---------------------------------*/
+
+static shifts *
+shifts_new (int n)
+{
+ shifts *res = SHIFTS_ALLOC (n);
+ res->nshifts = n;
+ return res;
+}
+
+
+/*------------------------------------------------------------.
+| Save the NSHIFTS of SHIFTSET into the current linked list. |
+`------------------------------------------------------------*/
+
static void
save_shifts (void)
{
static void
save_shifts (void)
{
- shifts *p = SHIFTS_ALLOC (nshifts);
+ shifts *p = shifts_new (nshifts);
p->number = this_state->number;
p->number = this_state->number;
shortcpy (p->shifts, shiftset, nshifts);
shortcpy (p->shifts, shiftset, nshifts);
last_state = statep;
/* Make a shift from this state to (what will be) the final state. */
last_state = statep;
/* Make a shift from this state to (what will be) the final state. */
sp->shifts[0] = nstates;
last_shift->next = sp;
sp->shifts[0] = nstates;
last_shift->next = sp;
if (sp && sp->number == k)
{
if (sp && sp->number == k)
{
- sp2 = SHIFTS_ALLOC (sp->nshifts + 1);
+ sp2 = shifts_new (sp->nshifts + 1);
- sp2->nshifts = sp->nshifts + 1;
sp2->shifts[0] = nstates;
for (i = sp->nshifts; i > 0; i--)
sp2->shifts[i] = sp->shifts[i - 1];
sp2->shifts[0] = nstates;
for (i = sp->nshifts; i > 0; i--)
sp2->shifts[i] = sp->shifts[i - 1];
- sp2 = SHIFTS_ALLOC (1);
sp2->shifts[0] = nstates;
/* Patch sp2 into the chain of shifts between sp1 and sp. */
sp2->shifts[0] = nstates;
/* Patch sp2 into the chain of shifts between sp1 and sp. */
going to the next-to-final state (yet to be made). */
sp = first_shift;
going to the next-to-final state (yet to be made). */
sp = first_shift;
- sp2 = SHIFTS_ALLOC (sp->nshifts + 1);
- sp2->nshifts = sp->nshifts + 1;
+ sp2 = shifts_new (sp->nshifts + 1);
/* Stick this shift into the vector at the proper place. */
statep = first_state->next;
/* Stick this shift into the vector at the proper place. */
statep = first_state->next;
{
/* The initial state didn't even have any shifts.
Give it one shift, to the next-to-final state. */
{
/* The initial state didn't even have any shifts.
Give it one shift, to the next-to-final state. */
- sp = SHIFTS_ALLOC (1);
- sp->nshifts = 1;
sp->shifts[0] = nstates;
/* Patch sp into the chain of shifts at the beginning. */
sp->shifts[0] = nstates;
/* Patch sp into the chain of shifts at the beginning. */
/* There are no shifts for any state.
Make one shift, from the initial state to the next-to-final state. */
/* There are no shifts for any state.
Make one shift, from the initial state to the next-to-final state. */
- sp = SHIFTS_ALLOC (1);
- sp->nshifts = 1;
sp->shifts[0] = nstates;
/* Initialize the chain of shifts with sp. */
sp->shifts[0] = nstates;
/* Initialize the chain of shifts with sp. */
last_state = statep;
/* Make the shift from the final state to the termination state. */
last_state = statep;
/* Make the shift from the final state to the termination state. */
sp->shifts[0] = nstates;
last_shift->next = sp;
last_shift = sp;
sp->shifts[0] = nstates;
last_shift->next = sp;
last_shift = sp;