]> git.saurik.com Git - bison.git/blame - src/output.c
Regen.
[bison.git] / src / output.c
CommitLineData
c3e23647 1/* Output the generated parsing program for bison,
5bb18f9a 2 Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002
255ef638 3 Free Software Foundation, Inc.
c3e23647 4
9ee3c97b 5 This file is part of Bison, the GNU Compiler Compiler.
c3e23647 6
9ee3c97b
AD
7 Bison is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
c3e23647 11
9ee3c97b
AD
12 Bison is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
c3e23647 16
9ee3c97b
AD
17 You should have received a copy of the GNU General Public License
18 along with Bison; see the file COPYING. If not, write to the Free
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
c3e23647
RS
21
22
7db2ed2d 23/* The parser tables consist of these tables.
c3e23647 24
255ef638
AD
25 YYTRANSLATE = vector mapping yylex's token numbers into bison's
26 token numbers.
c3e23647 27
7db2ed2d 28 YYTNAME = vector of string-names indexed by bison token number.
c3e23647 29
7db2ed2d
AD
30 YYTOKNUM = vector of yylex token numbers corresponding to entries
31 in YYTNAME.
c3e23647 32
255ef638
AD
33 YYRLINE = vector of line-numbers of all rules. For yydebug
34 printouts.
c3e23647 35
255ef638
AD
36 YYRHS = vector of items of all rules. This is exactly what RITEMS
37 contains. For yydebug and for semantic parser.
c3e23647 38
255ef638 39 YYPRHS[R] = index in YYRHS of first item for rule R.
c3e23647 40
255ef638 41 YYR1[R] = symbol number of symbol that rule R derives.
c3e23647 42
255ef638 43 YYR2[R] = number of symbols composing right hand side of rule R.
c3e23647 44
7db2ed2d 45 YYSTOS[S] = the symbol number of the symbol that leads to state S.
e372befa 46
255ef638
AD
47 YYDEFACT[S] = default rule to reduce with in state s, when YYTABLE
48 doesn't specify something else to do. Zero means the default is an
49 error.
c3e23647 50
255ef638
AD
51 YYDEFGOTO[I] = default state to go to after a reduction of a rule
52 that generates variable NTOKENS + I, except when YYTABLE specifies
53 something else to do.
c3e23647 54
255ef638
AD
55 YYPACT[S] = index in YYTABLE of the portion describing state S.
56 The lookahead token's type is used to index that portion to find
57 out what to do.
c3e23647 58
255ef638
AD
59 If the value in YYTABLE is positive, we shift the token and go to
60 that state.
c3e23647 61
6c89f1c1 62 If the value is negative, it is minus a rule number to reduce by.
c3e23647 63
255ef638
AD
64 If the value is zero, the default action from YYDEFACT[S] is used.
65
66 YYPGOTO[I] = the index in YYTABLE of the portion describing what to
67 do after reducing a rule that derives variable I + NTOKENS. This
68 portion is indexed by the parser state number, S, as of before the
69 text for this nonterminal was read. The value from YYTABLE is the
70 state to go to if the corresponding value in YYCHECK is S.
71
72 YYTABLE = a vector filled with portions for different uses, found
73 via YYPACT and YYPGOTO.
74
75 YYCHECK = a vector indexed in parallel with YYTABLE. It indicates,
76 in a roundabout way, the bounds of the portion you are trying to
77 examine.
78
12b0043a 79 Suppose that the portion of YYTABLE starts at index P and the index
255ef638
AD
80 to be examined within the portion is I. Then if YYCHECK[P+I] != I,
81 I is outside the bounds of what is actually allocated, and the
82 default (from YYDEFACT or YYDEFGOTO) should be used. Otherwise,
83 YYTABLE[P+I] should be used.
84
85 YYFINAL = the state number of the termination state. YYFLAG = most
86 negative short int. Used to flag ?? */
c3e23647 87
c3e23647 88#include "system.h"
14d3eb9b 89#include "quotearg.h"
be2a1a68 90#include "error.h"
ceed8467 91#include "getargs.h"
c3e23647
RS
92#include "files.h"
93#include "gram.h"
a0f6b076 94#include "complain.h"
6c89f1c1 95#include "output.h"
a70083a3 96#include "reader.h"
ad949da9 97#include "symtab.h"
c6f1a33c 98#include "tables.h"
11d82f03 99#include "muscle_tab.h"
be2a1a68 100
be2a1a68 101/* From src/scan-skel.l. */
536545f3 102void m4_invoke PARAMS ((const char *definitions));
d019d655 103
12b0043a 104
f87685c3 105static struct obstack format_obstack;
c3e23647 106
c7925b99
MA
107int error_verbose = 0;
108
f0440388 109
133c20e2 110
5372019f
AD
111/*-------------------------------------------------------------------.
112| Create a function NAME which associates to the muscle NAME the |
113| result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
114| TYPE), and to the muscle NAME_max, the max value of the |
115| TABLE_DATA. |
116`-------------------------------------------------------------------*/
62a3e4f0 117
62a3e4f0 118
5372019f 119#define GENERATE_MUSCLE_INSERT_TABLE(Name, Type) \
5fbb0954 120 \
5372019f
AD
121static void \
122Name (const char *name, \
5fbb0954
AD
123 Type *table_data, \
124 Type first, \
125 int begin, \
126 int end) \
127{ \
12b0043a 128 Type min = first; \
0c2d3f4c 129 Type max = first; \
5fbb0954
AD
130 int i; \
131 int j = 1; \
132 \
5372019f 133 obstack_fgrow1 (&format_obstack, "%6d", first); \
5fbb0954
AD
134 for (i = begin; i < end; ++i) \
135 { \
5372019f 136 obstack_1grow (&format_obstack, ','); \
5fbb0954
AD
137 if (j >= 10) \
138 { \
5372019f 139 obstack_sgrow (&format_obstack, "\n "); \
5fbb0954
AD
140 j = 1; \
141 } \
142 else \
143 ++j; \
5372019f 144 obstack_fgrow1 (&format_obstack, "%6d", table_data[i]); \
12b0043a
AD
145 if (table_data[i] < min) \
146 min = table_data[i]; \
147 if (max < table_data[i]) \
5fbb0954
AD
148 max = table_data[i]; \
149 } \
5372019f
AD
150 obstack_1grow (&format_obstack, 0); \
151 muscle_insert (name, obstack_finish (&format_obstack)); \
5fbb0954 152 \
12b0043a
AD
153 /* Build `NAME_min' and `NAME_max' in the obstack. */ \
154 obstack_fgrow1 (&format_obstack, "%s_min", name); \
155 obstack_1grow (&format_obstack, 0); \
156 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), \
157 (long int) min); \
5372019f
AD
158 obstack_fgrow1 (&format_obstack, "%s_max", name); \
159 obstack_1grow (&format_obstack, 0); \
0c2d3f4c
AD
160 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), \
161 (long int) max); \
62a3e4f0
AD
162}
163
5372019f 164GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
12b0043a 165GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int)
5372019f 166GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short)
12b0043a
AD
167GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_t)
168GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number_t)
a49aecd5 169GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number_t)
5372019f 170GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t)
d57650a5 171GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number_t)
c3e23647
RS
172
173
b0940840
AD
174/*-----------------------------------------------------------------.
175| Prepare the muscles related to the tokens: translate, tname, and |
176| toknum. |
177`-----------------------------------------------------------------*/
178
4a120d45 179static void
b0940840 180prepare_tokens (void)
c3e23647 181{
a49aecd5 182 muscle_insert_symbol_number_table ("translate",
fc5734fe
AD
183 token_translations,
184 token_translations[0],
185 1, max_user_token_number + 1);
c3e23647 186
b0940840
AD
187 {
188 int i;
189 int j = 0;
190 for (i = 0; i < nsyms; i++)
191 {
6b98e4b5
AD
192 /* Be sure not to use twice the same QUOTEARG slot:
193 SYMBOL_TAG_GET uses slot 0. */
b0940840
AD
194 const char *cp =
195 quotearg_n_style (1, c_quoting_style,
97650f4e 196 symbols[i]->tag);
b0940840
AD
197 /* Width of the next token, including the two quotes, the coma
198 and the space. */
199 int strsize = strlen (cp) + 2;
200
201 if (j + strsize > 75)
202 {
203 obstack_sgrow (&format_obstack, "\n ");
204 j = 2;
205 }
206
207 obstack_sgrow (&format_obstack, cp);
208 obstack_sgrow (&format_obstack, ", ");
209 j += strsize;
210 }
211 /* Add a NULL entry to list of tokens (well, 0, as NULL might not be
212 defined). */
213 obstack_sgrow (&format_obstack, "0");
c3e23647 214
b0940840
AD
215 /* Finish table and store. */
216 obstack_1grow (&format_obstack, 0);
217 muscle_insert ("tname", obstack_finish (&format_obstack));
218 }
219
12b0043a 220 /* Output YYTOKNUM. */
b2ed6e58
AD
221 {
222 int i;
3650b4b8
AD
223 int *values = XCALLOC (int, ntokens);
224 for (i = 0; i < ntokens; ++i)
b0940840 225 values[i] = symbols[i]->user_token_number;
12b0043a 226 muscle_insert_int_table ("toknum", values,
3650b4b8 227 values[0], 1, ntokens);
b0940840 228 free (values);
b2ed6e58 229 }
b0940840 230}
b2ed6e58 231
b0940840
AD
232
233/*-------------------------------------------------------------.
234| Prepare the muscles related to the rules: rhs, prhs, r1, r2, |
676385e2 235| rline, dprec, merger |
b0940840
AD
236`-------------------------------------------------------------*/
237
238static void
239prepare_rules (void)
240{
9222837b 241 rule_number_t r;
5df5f6d5 242 unsigned int i = 0;
62a3e4f0 243 item_number_t *rhs = XMALLOC (item_number_t, nritems);
4b3d3a8e
AD
244 unsigned int *prhs = XMALLOC (unsigned int, nrules);
245 unsigned int *rline = XMALLOC (unsigned int, nrules);
246 symbol_number_t *r1 = XMALLOC (symbol_number_t, nrules);
247 unsigned int *r2 = XMALLOC (unsigned int, nrules);
248 short *dprec = XMALLOC (short, nrules);
249 short *merger = XMALLOC (short, nrules);
250
251 for (r = 0; r < nrules; ++r)
b0940840 252 {
9222837b 253 item_number_t *rhsp = NULL;
b0940840
AD
254 /* Index of rule R in RHS. */
255 prhs[r] = i;
256 /* RHS of the rule R. */
257 for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
258 rhs[i++] = *rhsp;
259 /* LHS of the rule R. */
260 r1[r] = rules[r].lhs->number;
261 /* Length of rule R's RHS. */
262 r2[r] = i - prhs[r];
263 /* Separator in RHS. */
264 rhs[i++] = -1;
265 /* Line where rule was defined. */
8efe435c 266 rline[r] = rules[r].location.first_line;
676385e2
PH
267 /* Dynamic precedence (GLR) */
268 dprec[r] = rules[r].dprec;
269 /* Merger-function index (GLR) */
270 merger[r] = rules[r].merger;
b0940840
AD
271 }
272 assert (i == nritems);
273
5372019f 274 muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems);
4b3d3a8e
AD
275 muscle_insert_unsigned_int_table ("prhs", prhs, 0, 0, nrules);
276 muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules);
277 muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules);
278 muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules);
279 muscle_insert_short_table ("dprec", dprec, 0, 0, nrules);
280 muscle_insert_short_table ("merger", merger, 0, 0, nrules);
796d61fb 281
b0940840
AD
282 free (rhs);
283 free (prhs);
5df5f6d5
AD
284 free (rline);
285 free (r1);
b0940840 286 free (r2);
676385e2
PH
287 free (dprec);
288 free (merger);
c3e23647
RS
289}
290
b0940840
AD
291/*--------------------------------------------.
292| Prepare the muscles related to the states. |
293`--------------------------------------------*/
c3e23647 294
4a120d45 295static void
b0940840 296prepare_states (void)
c3e23647 297{
d57650a5 298 state_number_t i;
a49aecd5
AD
299 symbol_number_t *values =
300 (symbol_number_t *) alloca (sizeof (symbol_number_t) * nstates);
9703cc49 301 for (i = 0; i < nstates; ++i)
29e88316 302 values[i] = states[i]->accessing_symbol;
a49aecd5 303 muscle_insert_symbol_number_table ("stos", values,
d57650a5 304 0, 1, nstates);
c3e23647
RS
305}
306
307
c3e23647 308
c6f1a33c
AD
309/*----------------------------------.
310| Output the user actions to OOUT. |
311`----------------------------------*/
12b0043a 312
4a120d45 313static void
c6f1a33c 314user_actions_output (FILE *out)
3f96f4dc 315{
9222837b 316 rule_number_t r;
dafdc66f
AD
317
318 fputs ("m4_define([b4_actions], \n[[", out);
4b3d3a8e 319 for (r = 0; r < nrules; ++r)
9222837b 320 if (rules[r].action)
3f96f4dc 321 {
4b3d3a8e 322 fprintf (out, " case %d:\n", r + 1);
3f96f4dc
AD
323
324 if (!no_lines_flag)
ea52d706 325 fprintf (out, muscle_find ("linef"),
9222837b 326 rules[r].action_location.first_line,
ea52d706
AD
327 quotearg_style (c_quoting_style,
328 muscle_find ("filename")));
e9955c83 329 fprintf (out, " %s\n break;\n\n",
9222837b 330 rules[r].action);
3f96f4dc 331 }
dafdc66f 332 fputs ("]])\n\n", out);
3f96f4dc
AD
333}
334
676385e2
PH
335/*--------------------------------------.
336| Output the merge functions to OUT. |
337`--------------------------------------*/
338
41442480 339static void
676385e2
PH
340merger_output (FILE *out)
341{
342 int n;
343 merger_list* p;
344
345 fputs ("m4_define([b4_mergers], \n[[", out);
e0e5bf84 346 for (n = 1, p = merge_functions; p != NULL; n += 1, p = p->next)
676385e2 347 {
e0e5bf84 348 if (p->type[0] == '\0')
676385e2
PH
349 fprintf (out, " case %d: yyval = %s (*yy0, *yy1); break;\n",
350 n, p->name);
351 else
352 fprintf (out, " case %d: yyval.%s = %s (*yy0, *yy1); break;\n",
353 n, p->type, p->name);
354 }
355 fputs ("]])\n\n", out);
356}
3f96f4dc 357
091e20bb
AD
358/*---------------------------------------.
359| Output the tokens definition to OOUT. |
360`---------------------------------------*/
361
c6f1a33c 362static void
be2a1a68 363token_definitions_output (FILE *out)
091e20bb
AD
364{
365 int i;
0d8bed56 366 int first = 1;
dafdc66f
AD
367
368 fputs ("m4_define([b4_tokens], \n[", out);
091e20bb
AD
369 for (i = 0; i < ntokens; ++i)
370 {
db8837cb 371 symbol_t *symbol = symbols[i];
091e20bb
AD
372 int number = symbol->user_token_number;
373
b87f8b21
AD
374 /* At this stage, if there are literal aliases, they are part of
375 SYMBOLS, so we should not find symbols which are the aliases
376 here. */
377 assert (number != USER_NUMBER_ALIAS);
378
091e20bb 379 /* Skip error token. */
007a50a4 380 if (symbol == errtoken)
091e20bb 381 continue;
b87f8b21
AD
382
383 /* If this string has an alias, then it is necessarily the alias
384 which is to be output. */
385 if (symbol->alias)
386 symbol = symbol->alias;
387
388 /* Don't output literal chars or strings (when defined only as a
389 string). Note that must be done after the alias resolution:
390 think about `%token 'f' "f"'. */
391 if (symbol->tag[0] == '\'' || symbol->tag[0] == '\"')
392 continue;
091e20bb
AD
393
394 /* Don't #define nonliteral tokens whose names contain periods
395 or '$' (as does the default value of the EOF token). */
396 if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$'))
397 continue;
398
83ccf991 399 fprintf (out, "%s[[[%s]], [%d]]",
0d8bed56 400 first ? "" : ",\n", symbol->tag, number);
b87f8b21 401
0d8bed56 402 first = 0;
091e20bb 403 }
dafdc66f 404 fputs ("])\n\n", out);
091e20bb
AD
405}
406
407
9280d3ef
AD
408/*----------------------------------------.
409| Output the symbol destructors to OOUT. |
410`----------------------------------------*/
411
412static void
413symbol_destructors_output (FILE *out)
414{
415 int i;
416 int first = 1;
417
418 fputs ("m4_define([b4_symbol_destructors], \n[", out);
419 for (i = 0; i < nsyms; ++i)
420 if (symbols[i]->destructor)
421 {
422 symbol_t *symbol = symbols[i];
423
24c0aad7
AD
424 /* Filename, lineno,
425 Symbol-name, Symbol-number,
426 destructor, typename. */
427 fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
9280d3ef 428 first ? "" : ",\n",
24c0aad7 429 infile, symbol->destructor_location.first_line,
97650f4e 430 symbol->tag,
24c0aad7
AD
431 symbol->number,
432 symbol->destructor,
433 symbol->type_name);
9280d3ef
AD
434
435 first = 0;
436 }
437 fputs ("])\n\n", out);
438}
439
440
366eea36
AD
441/*-------------------------------------.
442| Output the symbol printers to OOUT. |
443`-------------------------------------*/
444
445static void
446symbol_printers_output (FILE *out)
447{
448 int i;
449 int first = 1;
450
451 fputs ("m4_define([b4_symbol_printers], \n[", out);
452 for (i = 0; i < nsyms; ++i)
453 if (symbols[i]->destructor)
454 {
455 symbol_t *symbol = symbols[i];
456
457 /* Filename, lineno,
458 Symbol-name, Symbol-number,
459 destructor, typename. */
460 fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
461 first ? "" : ",\n",
462 infile, symbol->printer_location.first_line,
97650f4e 463 symbol->tag,
366eea36
AD
464 symbol->number,
465 symbol->printer,
466 symbol->type_name);
467
468 first = 0;
469 }
470 fputs ("])\n\n", out);
471}
472
473
4a120d45 474static void
c6f1a33c 475prepare_actions (void)
6c89f1c1 476{
c6f1a33c
AD
477 /* Figure out the actions for the specified state, indexed by
478 lookahead token type. */
bbb5bcc6 479
c6f1a33c
AD
480 muscle_insert_rule_number_table ("defact", yydefact,
481 yydefact[0], 1, nstates);
6c89f1c1 482
c6f1a33c
AD
483 /* Figure out what to do after reducing with each rule, depending on
484 the saved state from before the beginning of parsing the data
485 that matched this rule. */
d57650a5
AD
486 muscle_insert_state_number_table ("defgoto", yydefgoto,
487 yydefgoto[0], 1, nsyms - ntokens);
12b0043a 488
12b0043a 489
12b0043a
AD
490 /* Output PACT. */
491 muscle_insert_base_table ("pact", base,
5372019f 492 base[0], 1, nstates);
12b0043a 493 MUSCLE_INSERT_INT ("pact_ninf", base_ninf);
c3e23647 494
12b0043a
AD
495 /* Output PGOTO. */
496 muscle_insert_base_table ("pgoto", base,
5372019f 497 base[nstates], nstates + 1, nvectors);
c3e23647 498
12b0043a
AD
499 muscle_insert_base_table ("table", table,
500 table[0], 1, high + 1);
501 MUSCLE_INSERT_INT ("table_ninf", table_ninf);
676385e2 502
12b0043a
AD
503 muscle_insert_base_table ("check", check,
504 check[0], 1, high + 1);
c3e23647 505
c6f1a33c
AD
506 if (glr_parser)
507 {
508 /* GLR parsing slightly modifies yytable and yycheck
509 (and thus yypact) so that in states with unresolved conflicts,
510 the default reduction is not used in the conflicted entries, so
511 that there is a place to put a conflict pointer. This means that
512 yyconflp and yyconfl are nonsense for a non-GLR parser, so we
513 avoid accidents by not writing them out in that case. */
514 muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table,
515 conflict_table[0], 1, high+1);
516 muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list,
517 conflict_list[0], 1, conflict_list_cnt);
518 }
6c89f1c1 519}
c3e23647 520
652def80 521\f
1239777d
AD
522/*---------------------------.
523| Call the skeleton parser. |
524`---------------------------*/
c3e23647 525
4a120d45 526static void
1239777d 527output_skeleton (void)
9b3add5b 528{
be2a1a68 529 /* Store the definition of all the muscles. */
d0039cbc 530 const char *tempdir = getenv ("TMPDIR");
381fb12e
AD
531 char *tempfile = NULL;
532 FILE *out = NULL;
381fb12e
AD
533 int fd;
534
535 if (tempdir == NULL)
536 tempdir = DEFAULT_TMPDIR;
537 tempfile = xmalloc (strlen (tempdir) + 11);
538 sprintf (tempfile, "%s/bsnXXXXXX", tempdir);
539 fd = mkstemp (tempfile);
540 if (fd == -1)
541 error (EXIT_FAILURE, errno, "%s", tempfile);
542
543 out = fdopen (fd, "w");
544 if (out == NULL)
545 error (EXIT_FAILURE, errno, "%s", tempfile);
546
547 /* There are no comments, especially not `#': we do want M4 expansion
548 after `#': think of CPP macros! */
549 fputs ("m4_changecom()\n", out);
550 fputs ("m4_init()\n", out);
551
c6f1a33c 552 user_actions_output (out);
676385e2 553 merger_output (out);
381fb12e 554 token_definitions_output (out);
9280d3ef 555 symbol_destructors_output (out);
366eea36 556 symbol_printers_output (out);
be2a1a68 557
381fb12e 558 muscles_m4_output (out);
be2a1a68 559
381fb12e
AD
560 fputs ("m4_wrap([m4_divert_pop(0)])\n", out);
561 fputs ("m4_divert_push(0)dnl\n", out);
562 xfclose (out);
be2a1a68 563
1509d42f 564 timevar_push (TV_M4);
f958596b 565 m4_invoke (tempfile);
1509d42f 566 timevar_pop (TV_M4);
f958596b
AD
567
568 /* If `debugging', keep this file alive. */
273a74fa 569 if (!(trace_flag & trace_tools))
f958596b
AD
570 unlink (tempfile);
571
572 free (tempfile);
26f609ff
RA
573}
574
575static void
576prepare (void)
577{
7db2ed2d
AD
578 /* Flags. */
579 MUSCLE_INSERT_INT ("locations_flag", locations_flag);
580 MUSCLE_INSERT_INT ("defines_flag", defines_flag);
581 MUSCLE_INSERT_INT ("error_verbose", error_verbose);
11d82f03 582 MUSCLE_INSERT_INT ("pure", pure_parser);
11d82f03 583 MUSCLE_INSERT_INT ("debug", debug_flag);
11d82f03 584
b85810ae
AD
585 /* FIXME: This is wrong: the muscles should decide whether they hold
586 a copy or not, but the situation is too obscure currently. */
7db2ed2d 587 MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy");
be2a1a68
AD
588 MUSCLE_INSERT_STRING ("output_infix", output_infix ? output_infix : "");
589 MUSCLE_INSERT_STRING ("output_prefix", short_base_name);
590 MUSCLE_INSERT_STRING ("output_parser_name", parser_file_name);
591 MUSCLE_INSERT_STRING ("output_header_name", spec_defines_file);
b85810ae 592
7db2ed2d
AD
593 /* Symbols. */
594 MUSCLE_INSERT_INT ("tokens_number", ntokens);
595 MUSCLE_INSERT_INT ("nterms_number", nvars);
596 MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
597 MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
11d82f03 598
7db2ed2d
AD
599 /* Rules. */
600 MUSCLE_INSERT_INT ("rules_number", nrules);
601
602 /* States. */
603 MUSCLE_INSERT_INT ("last", high);
7db2ed2d
AD
604 MUSCLE_INSERT_INT ("final_state_number", final_state->number);
605 MUSCLE_INSERT_INT ("states_number", nstates);
381fb12e 606
7db2ed2d 607 /* User Code. */
0dd1580a
RA
608 obstack_1grow (&pre_prologue_obstack, 0);
609 obstack_1grow (&post_prologue_obstack, 0);
610 muscle_insert ("pre_prologue", obstack_finish (&pre_prologue_obstack));
611 muscle_insert ("post_prologue", obstack_finish (&post_prologue_obstack));
381fb12e
AD
612
613 /* Find the right skeleton file. */
614 if (!skeleton)
676385e2
PH
615 {
616 if (glr_parser)
617 skeleton = "glr.c";
618 else
619 skeleton = "yacc.c";
620 }
381fb12e
AD
621
622 /* Parse the skeleton file and output the needed parsers. */
623 muscle_insert ("skeleton", skeleton);
26f609ff 624}
c3e23647 625
93ede233 626
6c89f1c1
AD
627/*----------------------------------------------------------.
628| Output the parsing tables and the parser code to ftable. |
629`----------------------------------------------------------*/
c3e23647 630
6c89f1c1
AD
631void
632output (void)
633{
f87685c3 634 obstack_init (&format_obstack);
dd60faec 635
b0940840
AD
636 prepare_tokens ();
637 prepare_rules ();
638 prepare_states ();
536545f3 639 prepare_actions ();
342b8b6e 640
26f609ff 641 prepare ();
652def80 642
9b3add5b
RA
643 /* Process the selected skeleton file. */
644 output_skeleton ();
645
f499b062 646 obstack_free (&format_obstack, NULL);
0dd1580a
RA
647 obstack_free (&pre_prologue_obstack, NULL);
648 obstack_free (&post_prologue_obstack, NULL);
c3e23647 649}