35 |
| Create a new array of N shifts/gotos. | |
| Create a new array of N shifts/gotos. | |
36 |
`---------------------------------------*/ |
`---------------------------------------*/ |
37 |
|
|
38 |
#define SHIFTS_ALLOC(Nshifts) \ |
#define TRANSITIONS_ALLOC(Nshifts) \ |
39 |
(shifts_t *) xcalloc ((unsigned) (sizeof (shifts_t) \ |
(transitions_t *) xcalloc ((unsigned) (sizeof (transitions_t) \ |
40 |
+ (Nshifts - 1) * sizeof (state_number_t)), 1) |
+ (Nshifts - 1) * sizeof (state_number_t)), 1) |
41 |
|
|
42 |
static shifts_t * |
static transitions_t * |
43 |
shifts_new (int nshifts, state_number_t *shifts) |
transitions_new (int num, state_number_t *the_states) |
44 |
{ |
{ |
45 |
shifts_t *res = SHIFTS_ALLOC (nshifts); |
transitions_t *res = TRANSITIONS_ALLOC (num); |
46 |
res->nshifts = nshifts; |
res->num = num; |
47 |
memcpy (res->shifts, shifts, nshifts * sizeof (shifts[0])); |
memcpy (res->states, the_states, num * sizeof (the_states[0])); |
48 |
return res; |
return res; |
49 |
} |
} |
50 |
|
|
51 |
|
|
52 |
/*-----------------------------------------------------------------. |
/*-------------------------------------------------------------------. |
53 |
| Return the state such these SHIFTS contain a shift/goto to it on | |
| Return the state such these TRANSITIONS contain a shift/goto to it | |
54 |
| SYMBOL. Aborts if none found. | |
| on SYMBOL. Aborts if none found. | |
55 |
`-----------------------------------------------------------------*/ |
`-------------------------------------------------------------------*/ |
56 |
|
|
57 |
state_t * |
state_t * |
58 |
shifts_to (shifts_t *shifts, symbol_number_t s) |
transitions_to (transitions_t *shifts, symbol_number_t s) |
59 |
{ |
{ |
60 |
int j; |
int j; |
61 |
for (j = 0; j < shifts->nshifts; j++) |
for (j = 0; j < shifts->num; j++) |
62 |
if (SHIFT_SYMBOL (shifts, j) == s) |
if (TRANSITION_SYMBOL (shifts, j) == s) |
63 |
return states[shifts->shifts[j]]; |
return states[shifts->states[j]]; |
64 |
abort (); |
abort (); |
65 |
} |
} |
66 |
|
|
168 |
`--------------------------*/ |
`--------------------------*/ |
169 |
|
|
170 |
void |
void |
171 |
state_shifts_set (state_t *state, int nshifts, state_number_t *shifts) |
state_transitions_set (state_t *state, int nshifts, state_number_t *shifts) |
172 |
{ |
{ |
173 |
state->shifts = shifts_new (nshifts, shifts); |
state->shifts = transitions_new (nshifts, shifts); |
174 |
} |
} |
175 |
|
|
176 |
|
|