176 |
} |
} |
177 |
|
|
178 |
|
|
179 |
|
/*-----------------------------------------------------------------. |
180 |
|
| Prepare the muscles related to the tokens: translate, tname, and | |
181 |
|
| toknum. | |
182 |
|
`-----------------------------------------------------------------*/ |
183 |
|
|
184 |
static void |
static void |
185 |
output_token_translations (void) |
prepare_tokens (void) |
186 |
{ |
{ |
187 |
output_table_data (&format_obstack, token_translations, |
output_table_data (&format_obstack, token_translations, |
188 |
0, 1, max_user_token_number + 1); |
0, 1, max_user_token_number + 1); |
189 |
muscle_insert ("translate", obstack_finish (&format_obstack)); |
muscle_insert ("translate", obstack_finish (&format_obstack)); |
190 |
XFREE (token_translations); |
XFREE (token_translations); |
|
} |
|
191 |
|
|
192 |
|
{ |
193 |
|
int i; |
194 |
|
int j = 0; |
195 |
|
for (i = 0; i < nsyms; i++) |
196 |
|
{ |
197 |
|
/* Be sure not to use twice the same quotearg slot. */ |
198 |
|
const char *cp = |
199 |
|
quotearg_n_style (1, c_quoting_style, |
200 |
|
quotearg_style (escape_quoting_style, |
201 |
|
symbols[i]->tag)); |
202 |
|
/* Width of the next token, including the two quotes, the coma |
203 |
|
and the space. */ |
204 |
|
int strsize = strlen (cp) + 2; |
205 |
|
|
206 |
|
if (j + strsize > 75) |
207 |
|
{ |
208 |
|
obstack_sgrow (&format_obstack, "\n "); |
209 |
|
j = 2; |
210 |
|
} |
211 |
|
|
212 |
|
obstack_sgrow (&format_obstack, cp); |
213 |
|
obstack_sgrow (&format_obstack, ", "); |
214 |
|
j += strsize; |
215 |
|
} |
216 |
|
/* Add a NULL entry to list of tokens (well, 0, as NULL might not be |
217 |
|
defined). */ |
218 |
|
obstack_sgrow (&format_obstack, "0"); |
219 |
|
|
220 |
|
/* Finish table and store. */ |
221 |
|
obstack_1grow (&format_obstack, 0); |
222 |
|
muscle_insert ("tname", obstack_finish (&format_obstack)); |
223 |
|
} |
224 |
|
|
225 |
static void |
/* Output YYTOKNUM. */ |
|
output_gram (void) |
|
|
{ |
|
226 |
{ |
{ |
227 |
int i; |
int i; |
228 |
short *values = XCALLOC (short, nrules + 1); |
short *values = XCALLOC (short, ntokens + 1); |
229 |
for (i = 1; i < nrules + 1; ++i) |
for (i = 0; i < ntokens + 1; ++i) |
230 |
values[i] = rules[i].rhs - ritem; |
values[i] = symbols[i]->user_token_number; |
231 |
output_table_data (&format_obstack, values, |
output_table_data (&format_obstack, values, |
232 |
0, 1, nrules + 1); |
0, 1, ntokens + 1); |
233 |
XFREE (values); |
muscle_insert ("toknum", obstack_finish (&format_obstack)); |
234 |
|
free (values); |
235 |
} |
} |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
/*-------------------------------------------------------------. |
240 |
|
| Prepare the muscles related to the rules: rhs, prhs, r1, r2, | |
241 |
|
| rline. | |
242 |
|
`-------------------------------------------------------------*/ |
243 |
|
|
244 |
|
static void |
245 |
|
prepare_rules (void) |
246 |
|
{ |
247 |
|
short *rhsp; |
248 |
|
int r; |
249 |
|
int i = 0; |
250 |
|
short *rhs = XMALLOC (short, nritems); |
251 |
|
short *prhs = XMALLOC (short, nrules + 1); |
252 |
|
short *r1 = XMALLOC (short, nrules + 1); |
253 |
|
short *r2 = XMALLOC (short, nrules + 1); |
254 |
|
short *rline = XMALLOC (short, nrules + 1); |
255 |
|
|
256 |
|
for (r = 1; r < nrules + 1; ++r) |
257 |
|
{ |
258 |
|
/* Index of rule R in RHS. */ |
259 |
|
prhs[r] = i; |
260 |
|
/* RHS of the rule R. */ |
261 |
|
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) |
262 |
|
rhs[i++] = *rhsp; |
263 |
|
/* LHS of the rule R. */ |
264 |
|
r1[r] = rules[r].lhs->number; |
265 |
|
/* Length of rule R's RHS. */ |
266 |
|
r2[r] = i - prhs[r]; |
267 |
|
/* Separator in RHS. */ |
268 |
|
rhs[i++] = -1; |
269 |
|
/* Line where rule was defined. */ |
270 |
|
rline[r] = rules[r].line; |
271 |
|
} |
272 |
|
assert (i == nritems); |
273 |
|
|
274 |
|
output_table_data (&format_obstack, rhs, ritem[0], 1, nritems); |
275 |
|
muscle_insert ("rhs", obstack_finish (&format_obstack)); |
276 |
|
|
277 |
|
output_table_data (&format_obstack, prhs, 0, 1, nrules + 1); |
278 |
muscle_insert ("prhs", obstack_finish (&format_obstack)); |
muscle_insert ("prhs", obstack_finish (&format_obstack)); |
279 |
|
|
280 |
{ |
output_table_data (&format_obstack, rline, 0, 1, nrules + 1); |
281 |
short *rhsp; |
muscle_insert ("rline", obstack_finish (&format_obstack)); |
|
int r; |
|
|
int i = 0; |
|
|
short *yyrhs = XMALLOC (short, nritems); |
|
282 |
|
|
283 |
for (r = 1; r < nrules + 1; ++r) |
output_table_data (&format_obstack, r1, 0, 1, nrules + 1); |
284 |
{ |
muscle_insert ("r1", obstack_finish (&format_obstack)); |
|
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) |
|
|
yyrhs[i++] = *rhsp; |
|
|
yyrhs[i++] = -1; |
|
|
} |
|
|
assert (i == nritems); |
|
|
output_table_data (&format_obstack, yyrhs, |
|
|
ritem[0], 1, nritems); |
|
|
muscle_insert ("rhs", obstack_finish (&format_obstack)); |
|
285 |
|
|
286 |
XFREE (yyrhs); |
output_table_data (&format_obstack, r2, 0, 1, nrules + 1); |
287 |
} |
muscle_insert ("r2", obstack_finish (&format_obstack)); |
288 |
|
|
289 |
#if 0 |
free (rhs); |
290 |
if (!semantic_parser) |
free (prhs); |
291 |
obstack_sgrow (&table_obstack, "\n#endif\n"); |
free (r2); |
|
#endif |
|
292 |
} |
} |
293 |
|
|
294 |
|
/*--------------------------------------------. |
295 |
|
| Prepare the muscles related to the states. | |
296 |
|
`--------------------------------------------*/ |
297 |
|
|
298 |
static void |
static void |
299 |
output_stos (void) |
prepare_states (void) |
300 |
{ |
{ |
301 |
size_t i; |
size_t i; |
302 |
short *values = (short *) alloca (sizeof (short) * nstates); |
short *values = (short *) alloca (sizeof (short) * nstates); |
308 |
} |
} |
309 |
|
|
310 |
|
|
|
static void |
|
|
output_rule_data (void) |
|
|
{ |
|
|
int i; |
|
|
int j; |
|
|
short *short_tab = NULL; |
|
|
|
|
|
{ |
|
|
short *values = XCALLOC (short, nrules + 1); |
|
|
for (i = 1; i < nrules + 1; ++i) |
|
|
values[i] = rules[i].line; |
|
|
output_table_data (&format_obstack, values, |
|
|
0, 1, nrules + 1); |
|
|
muscle_insert ("rline", obstack_finish (&format_obstack)); |
|
|
XFREE (values); |
|
|
} |
|
|
|
|
|
|
|
|
j = 0; |
|
|
for (i = 0; i < nsyms; i++) |
|
|
{ |
|
|
/* Be sure not to use twice the same quotearg slot. */ |
|
|
const char *cp = |
|
|
quotearg_n_style (1, c_quoting_style, |
|
|
quotearg_style (escape_quoting_style, symbols[i]->tag)); |
|
|
/* Width of the next token, including the two quotes, the coma |
|
|
and the space. */ |
|
|
int strsize = strlen (cp) + 2; |
|
|
|
|
|
if (j + strsize > 75) |
|
|
{ |
|
|
obstack_sgrow (&format_obstack, "\n "); |
|
|
j = 2; |
|
|
} |
|
|
|
|
|
obstack_sgrow (&format_obstack, cp); |
|
|
obstack_sgrow (&format_obstack, ", "); |
|
|
j += strsize; |
|
|
} |
|
|
/* Add a NULL entry to list of tokens (well, 0, as NULL might not be |
|
|
defined). */ |
|
|
obstack_sgrow (&format_obstack, "0"); |
|
|
|
|
|
/* Finish table and store. */ |
|
|
obstack_1grow (&format_obstack, 0); |
|
|
muscle_insert ("tname", obstack_finish (&format_obstack)); |
|
|
|
|
|
/* Output YYTOKNUM. */ |
|
|
{ |
|
|
short *values = XCALLOC (short, ntokens + 1); |
|
|
for (i = 0; i < ntokens + 1; ++i) |
|
|
values[i] = symbols[i]->user_token_number; |
|
|
output_table_data (&format_obstack, values, |
|
|
0, 1, ntokens + 1); |
|
|
muscle_insert ("toknum", obstack_finish (&format_obstack)); |
|
|
XFREE (values); |
|
|
} |
|
|
|
|
|
|
|
|
/* Output YYR1. */ |
|
|
{ |
|
|
short *values = XCALLOC (short, nrules + 1); |
|
|
for (i = 1; i < nrules + 1; ++i) |
|
|
values[i] = rules[i].lhs->number; |
|
|
output_table_data (&format_obstack, values, |
|
|
0, 1, nrules + 1); |
|
|
muscle_insert ("r1", obstack_finish (&format_obstack)); |
|
|
XFREE (values); |
|
|
} |
|
|
|
|
|
/* Output YYR2. */ |
|
|
short_tab = XMALLOC (short, nrules + 1); |
|
|
for (i = 1; i < nrules; i++) |
|
|
short_tab[i] = rules[i + 1].rhs - rules[i].rhs - 1; |
|
|
short_tab[nrules] = nritems - (rules[nrules].rhs - ritem) - 1; |
|
|
output_table_data (&format_obstack, short_tab, |
|
|
0, 1, nrules + 1); |
|
|
muscle_insert ("r2", obstack_finish (&format_obstack)); |
|
|
XFREE (short_tab); |
|
|
} |
|
|
|
|
311 |
/*------------------------------------------------------------------. |
/*------------------------------------------------------------------. |
312 |
| Decide what to do for each type of token if seen as the lookahead | |
| Decide what to do for each type of token if seen as the lookahead | |
313 |
| token in specified state. The value returned is used as the | |
| token in specified state. The value returned is used as the | |
900 |
XFREE (check); |
XFREE (check); |
901 |
} |
} |
902 |
|
|
903 |
/* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable |
/*-----------------------------------------------------------------. |
904 |
and yycheck. */ |
| Compute and output yydefact, yydefgoto, yypact, yypgoto, yytable | |
905 |
|
| and yycheck. | |
906 |
|
`-----------------------------------------------------------------*/ |
907 |
|
|
908 |
static void |
static void |
909 |
output_actions (void) |
output_actions (void) |
1075 |
{ |
{ |
1076 |
obstack_init (&format_obstack); |
obstack_init (&format_obstack); |
1077 |
|
|
1078 |
output_token_translations (); |
prepare_tokens (); |
1079 |
output_gram (); |
prepare_rules (); |
1080 |
|
prepare_states (); |
|
if (semantic_parser) |
|
|
output_stos (); |
|
|
output_rule_data (); |
|
1081 |
output_actions (); |
output_actions (); |
1082 |
|
|
1083 |
prepare (); |
prepare (); |