35 |
| Create a new array of N shifts/gotos. | |
| Create a new array of N shifts/gotos. | |
36 |
`---------------------------------------*/ |
`---------------------------------------*/ |
37 |
|
|
38 |
#define TRANSITIONS_ALLOC(Num) \ |
#define TRANSITIONS_ALLOC(Num) \ |
39 |
(transitions_t *) xcalloc ((sizeof (transitions_t) \ |
(transitions_t *) xcalloc ((sizeof (transitions_t) \ |
40 |
+ (Num - 1) * sizeof (state_number_t)), 1) |
+ (Num - 1) * sizeof (state_t *)), 1) |
41 |
|
|
42 |
static transitions_t * |
static transitions_t * |
43 |
transitions_new (int num, state_number_t *the_states) |
transitions_new (int num, state_t **the_states) |
44 |
{ |
{ |
45 |
transitions_t *res = TRANSITIONS_ALLOC (num); |
transitions_t *res = TRANSITIONS_ALLOC (num); |
46 |
res->num = num; |
res->num = num; |
60 |
int j; |
int j; |
61 |
for (j = 0; j < shifts->num; j++) |
for (j = 0; j < shifts->num; j++) |
62 |
if (TRANSITION_SYMBOL (shifts, j) == s) |
if (TRANSITION_SYMBOL (shifts, j) == s) |
63 |
return states[shifts->states[j]]; |
return shifts->states[j]; |
64 |
abort (); |
abort (); |
65 |
} |
} |
66 |
|
|
76 |
|
|
77 |
#define ERRS_ALLOC(Nerrs) \ |
#define ERRS_ALLOC(Nerrs) \ |
78 |
(errs_t *) xcalloc ((sizeof (errs_t) \ |
(errs_t *) xcalloc ((sizeof (errs_t) \ |
79 |
+ (Nerrs - 1) * sizeof (symbol_number_t)), 1) |
+ (Nerrs - 1) * sizeof (symbol_t *)), 1) |
80 |
|
|
81 |
|
|
82 |
errs_t * |
errs_t * |
83 |
errs_new (int num, symbol_number_t *tokens) |
errs_new (int num, symbol_t **tokens) |
84 |
{ |
{ |
85 |
errs_t *res = ERRS_ALLOC (num); |
errs_t *res = ERRS_ALLOC (num); |
86 |
res->num = num; |
res->num = num; |
102 |
|
|
103 |
#define REDUCTIONS_ALLOC(Nreductions) \ |
#define REDUCTIONS_ALLOC(Nreductions) \ |
104 |
(reductions_t *) xcalloc ((sizeof (reductions_t) \ |
(reductions_t *) xcalloc ((sizeof (reductions_t) \ |
105 |
+ (Nreductions - 1) * sizeof (rule_number_t)), 1) |
+ (Nreductions - 1) * sizeof (rule_t *)), 1) |
106 |
|
|
107 |
static reductions_t * |
static reductions_t * |
108 |
reductions_new (int num, rule_number_t *reductions) |
reductions_new (int num, rule_t **reductions) |
109 |
{ |
{ |
110 |
reductions_t *res = REDUCTIONS_ALLOC (num); |
reductions_t *res = REDUCTIONS_ALLOC (num); |
111 |
res->num = num; |
res->num = num; |
126 |
state_t *final_state = NULL; |
state_t *final_state = NULL; |
127 |
|
|
128 |
#define STATE_ALLOC(Nitems) \ |
#define STATE_ALLOC(Nitems) \ |
129 |
(state_t *) xcalloc ((unsigned) (sizeof (state_t) \ |
(state_t *) xcalloc ((sizeof (state_t) \ |
130 |
+ (Nitems - 1) * sizeof (item_number_t)), 1) |
+ (Nitems - 1) * sizeof (item_number_t)), 1) |
131 |
|
|
132 |
/*------------------------------------------------------------------. |
/*------------------------------------------------------------------. |
133 |
| Create a new state with ACCESSING_SYMBOL, for those items. Store | |
| Create a new state with ACCESSING_SYMBOL, for those items. Store | |
177 |
`-------------------------------*/ |
`-------------------------------*/ |
178 |
|
|
179 |
void |
void |
180 |
state_transitions_set (state_t *state, int num, state_number_t *transitions) |
state_transitions_set (state_t *state, int num, state_t **transitions) |
181 |
{ |
{ |
182 |
assert (!state->transitions); |
assert (!state->transitions); |
183 |
state->transitions = transitions_new (num, transitions); |
state->transitions = transitions_new (num, transitions); |
189 |
`------------------------------*/ |
`------------------------------*/ |
190 |
|
|
191 |
void |
void |
192 |
state_reductions_set (state_t *state, int num, rule_number_t *reductions) |
state_reductions_set (state_t *state, int num, rule_t **reductions) |
193 |
{ |
{ |
194 |
assert (!state->reductions); |
assert (!state->reductions); |
195 |
state->reductions = reductions_new (num, reductions); |
state->reductions = reductions_new (num, reductions); |
201 |
`------------------------*/ |
`------------------------*/ |
202 |
|
|
203 |
void |
void |
204 |
state_errs_set (state_t *state, int num, symbol_number_t *tokens) |
state_errs_set (state_t *state, int num, symbol_t **tokens) |
205 |
{ |
{ |
206 |
assert (!state->errs); |
assert (!state->errs); |
207 |
state->errs = errs_new (num, tokens); |
state->errs = errs_new (num, tokens); |