61 |
`-------------------------------*/ |
`-------------------------------*/ |
62 |
|
|
63 |
#define ERRS_ALLOC(Nerrs) \ |
#define ERRS_ALLOC(Nerrs) \ |
64 |
(errs *) xcalloc ((unsigned) (sizeof (errs) \ |
(errs_t *) xcalloc ((unsigned) (sizeof (errs_t) \ |
65 |
+ (Nerrs - 1) * sizeof (short)), 1) |
+ (Nerrs - 1) * sizeof (short)), 1) |
66 |
|
|
67 |
|
|
68 |
errs * |
errs_t * |
69 |
errs_new (int n) |
errs_new (int n) |
70 |
{ |
{ |
71 |
errs *res = ERRS_ALLOC (n); |
errs_t *res = ERRS_ALLOC (n); |
72 |
res->nerrs = n; |
res->nerrs = n; |
73 |
return res; |
return res; |
74 |
} |
} |
75 |
|
|
76 |
|
|
77 |
errs * |
errs_t * |
78 |
errs_dup (errs *src) |
errs_dup (errs_t *src) |
79 |
{ |
{ |
80 |
errs *res = errs_new (src->nerrs); |
errs_t *res = errs_new (src->nerrs); |
81 |
memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0])); |
memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0])); |
82 |
return res; |
return res; |
83 |
} |
} |
95 |
`-------------------------------------*/ |
`-------------------------------------*/ |
96 |
|
|
97 |
#define REDUCTIONS_ALLOC(Nreductions) \ |
#define REDUCTIONS_ALLOC(Nreductions) \ |
98 |
(reductions *) xcalloc ((unsigned) (sizeof (reductions) \ |
(reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t) \ |
99 |
+ (Nreductions - 1) * sizeof (short)), 1) |
+ (Nreductions - 1) * sizeof (short)), 1) |
100 |
|
|
101 |
reductions * |
static reductions_t * |
102 |
reductions_new (int n) |
reductions_new (int nreductions, short *reductions) |
103 |
{ |
{ |
104 |
reductions *res = REDUCTIONS_ALLOC (n); |
reductions_t *res = REDUCTIONS_ALLOC (nreductions); |
105 |
res->nreds = n; |
res->nreds = nreductions; |
106 |
|
memcpy (res->rules, reductions, nreductions * sizeof (reductions[0])); |
107 |
return res; |
return res; |
108 |
} |
} |
109 |
|
|
160 |
} |
} |
161 |
|
|
162 |
|
|
163 |
|
/*------------------------------. |
164 |
|
| Set the reductions of STATE. | |
165 |
|
`------------------------------*/ |
166 |
|
|
167 |
|
void |
168 |
|
state_reductions_set (state_t *state, int nreductions, short *reductions) |
169 |
|
{ |
170 |
|
state->reductions = reductions_new (nreductions, reductions); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
/*--------------------------------------------------------------. |
/*--------------------------------------------------------------. |
176 |
| Print on OUT all the lookaheads such that this STATE wants to | |
| Print on OUT all the lookaheads such that this STATE wants to | |