153 |
`----------------------------------------------------------------*/ |
`----------------------------------------------------------------*/ |
154 |
|
|
155 |
static inline long int |
static inline long int |
156 |
output_table_data (struct obstack *oout, |
output_short_table (struct obstack *oout, |
157 |
short *table_data, |
short *table_data, |
158 |
short first, |
short first, |
159 |
int begin, |
int begin, |
160 |
int end) |
int end) |
161 |
|
{ |
162 |
|
long int max = first; |
163 |
|
int i; |
164 |
|
int j = 1; |
165 |
|
|
166 |
|
obstack_fgrow1 (oout, "%6d", first); |
167 |
|
for (i = begin; i < end; ++i) |
168 |
|
{ |
169 |
|
obstack_1grow (oout, ','); |
170 |
|
if (j >= 10) |
171 |
|
{ |
172 |
|
obstack_sgrow (oout, "\n "); |
173 |
|
j = 1; |
174 |
|
} |
175 |
|
else |
176 |
|
++j; |
177 |
|
obstack_fgrow1 (oout, "%6d", table_data[i]); |
178 |
|
if (table_data[i] > max) |
179 |
|
max = table_data[i]; |
180 |
|
} |
181 |
|
obstack_1grow (oout, 0); |
182 |
|
|
183 |
|
return max; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
/*--------------------. |
188 |
|
| Similar, for ints. | |
189 |
|
`--------------------*/ |
190 |
|
|
191 |
|
static inline long int |
192 |
|
output_int_table (struct obstack *oout, |
193 |
|
int *table_data, |
194 |
|
int first, |
195 |
|
int begin, |
196 |
|
int end) |
197 |
{ |
{ |
198 |
long int max = first; |
long int max = first; |
199 |
int i; |
int i; |
228 |
static void |
static void |
229 |
prepare_tokens (void) |
prepare_tokens (void) |
230 |
{ |
{ |
231 |
long int max = output_table_data (&format_obstack, token_translations, |
long int max = output_short_table (&format_obstack, token_translations, |
232 |
0, 1, max_user_token_number + 1); |
0, 1, max_user_token_number + 1); |
233 |
muscle_insert ("translate", obstack_finish (&format_obstack)); |
muscle_insert ("translate", obstack_finish (&format_obstack)); |
234 |
MUSCLE_INSERT_LONG_INT ("token_number_max", max); |
MUSCLE_INSERT_LONG_INT ("token_number_max", max); |
273 |
short *values = XCALLOC (short, ntokens + 1); |
short *values = XCALLOC (short, ntokens + 1); |
274 |
for (i = 0; i < ntokens + 1; ++i) |
for (i = 0; i < ntokens + 1; ++i) |
275 |
values[i] = symbols[i]->user_token_number; |
values[i] = symbols[i]->user_token_number; |
276 |
output_table_data (&format_obstack, values, |
output_short_table (&format_obstack, values, |
277 |
0, 1, ntokens + 1); |
0, 1, ntokens + 1); |
278 |
muscle_insert ("toknum", obstack_finish (&format_obstack)); |
muscle_insert ("toknum", obstack_finish (&format_obstack)); |
279 |
free (values); |
free (values); |
289 |
static void |
static void |
290 |
prepare_rules (void) |
prepare_rules (void) |
291 |
{ |
{ |
292 |
short *rhsp; |
long int max; |
293 |
|
item_number_t *rhsp; |
294 |
int r; |
int r; |
295 |
int i = 0; |
int i = 0; |
296 |
short *rhs = XMALLOC (short, nritems); |
item_number_t *rhs = XMALLOC (item_number_t, nritems); |
297 |
short *prhs = XMALLOC (short, nrules + 1); |
short *prhs = XMALLOC (short, nrules + 1); |
298 |
short *r1 = XMALLOC (short, nrules + 1); |
short *r1 = XMALLOC (short, nrules + 1); |
299 |
short *r2 = XMALLOC (short, nrules + 1); |
short *r2 = XMALLOC (short, nrules + 1); |
317 |
} |
} |
318 |
assert (i == nritems); |
assert (i == nritems); |
319 |
|
|
320 |
output_table_data (&format_obstack, rhs, ritem[0], 1, nritems); |
max = output_int_table (&format_obstack, rhs, ritem[0], 1, nritems); |
321 |
muscle_insert ("rhs", obstack_finish (&format_obstack)); |
muscle_insert ("rhs", obstack_finish (&format_obstack)); |
322 |
|
MUSCLE_INSERT_LONG_INT ("rhs_number_max", max); |
323 |
|
|
324 |
output_table_data (&format_obstack, prhs, 0, 1, nrules + 1); |
output_short_table (&format_obstack, prhs, 0, 1, nrules + 1); |
325 |
muscle_insert ("prhs", obstack_finish (&format_obstack)); |
muscle_insert ("prhs", obstack_finish (&format_obstack)); |
326 |
|
|
327 |
output_table_data (&format_obstack, rline, 0, 1, nrules + 1); |
output_short_table (&format_obstack, rline, 0, 1, nrules + 1); |
328 |
muscle_insert ("rline", obstack_finish (&format_obstack)); |
muscle_insert ("rline", obstack_finish (&format_obstack)); |
329 |
|
|
330 |
output_table_data (&format_obstack, r1, 0, 1, nrules + 1); |
output_short_table (&format_obstack, r1, 0, 1, nrules + 1); |
331 |
muscle_insert ("r1", obstack_finish (&format_obstack)); |
muscle_insert ("r1", obstack_finish (&format_obstack)); |
332 |
|
|
333 |
output_table_data (&format_obstack, r2, 0, 1, nrules + 1); |
output_short_table (&format_obstack, r2, 0, 1, nrules + 1); |
334 |
muscle_insert ("r2", obstack_finish (&format_obstack)); |
muscle_insert ("r2", obstack_finish (&format_obstack)); |
335 |
|
|
336 |
free (rhs); |
free (rhs); |
349 |
short *values = (short *) alloca (sizeof (short) * nstates); |
short *values = (short *) alloca (sizeof (short) * nstates); |
350 |
for (i = 0; i < nstates; ++i) |
for (i = 0; i < nstates; ++i) |
351 |
values[i] = states[i]->accessing_symbol; |
values[i] = states[i]->accessing_symbol; |
352 |
output_table_data (&format_obstack, values, |
output_short_table (&format_obstack, values, |
353 |
0, 1, nstates); |
0, 1, nstates); |
354 |
muscle_insert ("stos", obstack_finish (&format_obstack)); |
muscle_insert ("stos", obstack_finish (&format_obstack)); |
355 |
} |
} |
361 |
| default action (yydefact) for the state. In addition, actrow is | |
| default action (yydefact) for the state. In addition, actrow is | |
362 |
| filled with what to do for each kind of token, index by symbol | |
| filled with what to do for each kind of token, index by symbol | |
363 |
| number, with zero meaning do the default action. The value | |
| number, with zero meaning do the default action. The value | |
364 |
| MINSHORT, a very negative number, means this situation is an | |
| SHRT_MIN, a very negative number, means this situation is an | |
365 |
| error. The parser recognizes this value specially. | |
| error. The parser recognizes this value specially. | |
366 |
| | |
| | |
367 |
| This is where conflicts are resolved. The loop over lookahead | |
| This is where conflicts are resolved. The loop over lookahead | |
422 |
} |
} |
423 |
|
|
424 |
/* See which tokens are an explicit error in this state (due to |
/* See which tokens are an explicit error in this state (due to |
425 |
%nonassoc). For them, record MINSHORT as the action. */ |
%nonassoc). For them, record SHRT_MIN as the action. */ |
426 |
for (i = 0; i < errp->nerrs; i++) |
for (i = 0; i < errp->nerrs; i++) |
427 |
{ |
{ |
428 |
int symbol = errp->errs[i]; |
int symbol = errp->errs[i]; |
429 |
actrow[symbol] = MINSHORT; |
actrow[symbol] = SHRT_MIN; |
430 |
} |
} |
431 |
|
|
432 |
/* Now find the most common reduction and make it the default action |
/* Now find the most common reduction and make it the default action |
476 |
|
|
477 |
if (default_rule == 0) |
if (default_rule == 0) |
478 |
for (i = 0; i < ntokens; i++) |
for (i = 0; i < ntokens; i++) |
479 |
if (actrow[i] == MINSHORT) |
if (actrow[i] == SHRT_MIN) |
480 |
actrow[i] = 0; |
actrow[i] = 0; |
481 |
|
|
482 |
return default_rule; |
return default_rule; |
536 |
save_row (i); |
save_row (i); |
537 |
} |
} |
538 |
|
|
539 |
output_table_data (&format_obstack, yydefact, |
output_short_table (&format_obstack, yydefact, |
540 |
yydefact[0], 1, nstates); |
yydefact[0], 1, nstates); |
541 |
muscle_insert ("defact", obstack_finish (&format_obstack)); |
muscle_insert ("defact", obstack_finish (&format_obstack)); |
542 |
|
|
730 |
yydefgoto[i - ntokens] = default_state; |
yydefgoto[i - ntokens] = default_state; |
731 |
} |
} |
732 |
|
|
733 |
output_table_data (&format_obstack, yydefgoto, |
output_short_table (&format_obstack, yydefgoto, |
734 |
yydefgoto[0], 1, nsyms - ntokens); |
yydefgoto[0], 1, nsyms - ntokens); |
735 |
muscle_insert ("defgoto", obstack_finish (&format_obstack)); |
muscle_insert ("defgoto", obstack_finish (&format_obstack)); |
736 |
|
|
807 |
return -1; |
return -1; |
808 |
} |
} |
809 |
|
|
810 |
|
/* FIXME: For the time being, best approximation... */ |
811 |
|
#define MAXTABLE SHRT_MAX |
812 |
|
|
813 |
static int |
static int |
814 |
pack_vector (int vector) |
pack_vector (int vector) |
881 |
high = 0; |
high = 0; |
882 |
|
|
883 |
for (i = 0; i < nvectors; i++) |
for (i = 0; i < nvectors; i++) |
884 |
base[i] = MINSHORT; |
base[i] = SHRT_MIN; |
885 |
|
|
886 |
for (i = 0; i < MAXTABLE; i++) |
for (i = 0; i < MAXTABLE; i++) |
887 |
check[i] = -1; |
check[i] = -1; |
917 |
output_base (void) |
output_base (void) |
918 |
{ |
{ |
919 |
/* Output pact. */ |
/* Output pact. */ |
920 |
output_table_data (&format_obstack, base, |
output_short_table (&format_obstack, base, |
921 |
base[0], 1, nstates); |
base[0], 1, nstates); |
922 |
muscle_insert ("pact", obstack_finish (&format_obstack)); |
muscle_insert ("pact", obstack_finish (&format_obstack)); |
923 |
|
|
924 |
/* Output pgoto. */ |
/* Output pgoto. */ |
925 |
output_table_data (&format_obstack, base, |
output_short_table (&format_obstack, base, |
926 |
base[nstates], nstates + 1, nvectors); |
base[nstates], nstates + 1, nvectors); |
927 |
muscle_insert ("pgoto", obstack_finish (&format_obstack)); |
muscle_insert ("pgoto", obstack_finish (&format_obstack)); |
928 |
|
|
933 |
static void |
static void |
934 |
output_table (void) |
output_table (void) |
935 |
{ |
{ |
936 |
output_table_data (&format_obstack, table, |
output_short_table (&format_obstack, table, |
937 |
table[0], 1, high + 1); |
table[0], 1, high + 1); |
938 |
muscle_insert ("table", obstack_finish (&format_obstack)); |
muscle_insert ("table", obstack_finish (&format_obstack)); |
939 |
XFREE (table); |
XFREE (table); |
943 |
static void |
static void |
944 |
output_check (void) |
output_check (void) |
945 |
{ |
{ |
946 |
output_table_data (&format_obstack, check, |
output_short_table (&format_obstack, check, |
947 |
check[0], 1, high + 1); |
check[0], 1, high + 1); |
948 |
muscle_insert ("check", obstack_finish (&format_obstack)); |
muscle_insert ("check", obstack_finish (&format_obstack)); |
949 |
XFREE (check); |
XFREE (check); |
1073 |
prepare (void) |
prepare (void) |
1074 |
{ |
{ |
1075 |
MUSCLE_INSERT_INT ("last", high); |
MUSCLE_INSERT_INT ("last", high); |
1076 |
MUSCLE_INSERT_INT ("flag", MINSHORT); |
MUSCLE_INSERT_INT ("flag", SHRT_MIN); |
1077 |
MUSCLE_INSERT_INT ("pure", pure_parser); |
MUSCLE_INSERT_INT ("pure", pure_parser); |
1078 |
MUSCLE_INSERT_INT ("nsym", nsyms); |
MUSCLE_INSERT_INT ("nsym", nsyms); |
1079 |
MUSCLE_INSERT_INT ("debug", debug_flag); |
MUSCLE_INSERT_INT ("debug", debug_flag); |