]> git.saurik.com Git - bison.git/blame - src/output.c
Adjust to type renaming.
[bison.git] / src / output.c
CommitLineData
a932883e 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
c3e23647 23#include "system.h"
14d3eb9b 24#include "quotearg.h"
be2a1a68 25#include "error.h"
573312ac 26#include "subpipe.h"
ceed8467 27#include "getargs.h"
c3e23647
RS
28#include "files.h"
29#include "gram.h"
a0f6b076 30#include "complain.h"
6c89f1c1 31#include "output.h"
a70083a3 32#include "reader.h"
ad949da9 33#include "symtab.h"
c6f1a33c 34#include "tables.h"
11d82f03 35#include "muscle_tab.h"
be2a1a68 36
be2a1a68 37/* From src/scan-skel.l. */
573312ac 38void scan_skel (FILE *);
d019d655 39
12b0043a 40
f87685c3 41static struct obstack format_obstack;
c3e23647 42
c7925b99
MA
43int error_verbose = 0;
44
f0440388 45
133c20e2 46
5372019f
AD
47/*-------------------------------------------------------------------.
48| Create a function NAME which associates to the muscle NAME the |
49| result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
50| TYPE), and to the muscle NAME_max, the max value of the |
51| TABLE_DATA. |
52`-------------------------------------------------------------------*/
62a3e4f0 53
62a3e4f0 54
5372019f 55#define GENERATE_MUSCLE_INSERT_TABLE(Name, Type) \
5fbb0954 56 \
5372019f
AD
57static void \
58Name (const char *name, \
5fbb0954
AD
59 Type *table_data, \
60 Type first, \
61 int begin, \
62 int end) \
63{ \
12b0043a 64 Type min = first; \
0c2d3f4c 65 Type max = first; \
5fbb0954
AD
66 int i; \
67 int j = 1; \
68 \
5372019f 69 obstack_fgrow1 (&format_obstack, "%6d", first); \
5fbb0954
AD
70 for (i = begin; i < end; ++i) \
71 { \
5372019f 72 obstack_1grow (&format_obstack, ','); \
5fbb0954
AD
73 if (j >= 10) \
74 { \
5372019f 75 obstack_sgrow (&format_obstack, "\n "); \
5fbb0954
AD
76 j = 1; \
77 } \
78 else \
79 ++j; \
5372019f 80 obstack_fgrow1 (&format_obstack, "%6d", table_data[i]); \
12b0043a
AD
81 if (table_data[i] < min) \
82 min = table_data[i]; \
83 if (max < table_data[i]) \
5fbb0954
AD
84 max = table_data[i]; \
85 } \
5372019f
AD
86 obstack_1grow (&format_obstack, 0); \
87 muscle_insert (name, obstack_finish (&format_obstack)); \
5fbb0954 88 \
12b0043a
AD
89 /* Build `NAME_min' and `NAME_max' in the obstack. */ \
90 obstack_fgrow1 (&format_obstack, "%s_min", name); \
91 obstack_1grow (&format_obstack, 0); \
92 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), \
93 (long int) min); \
5372019f
AD
94 obstack_fgrow1 (&format_obstack, "%s_max", name); \
95 obstack_1grow (&format_obstack, 0); \
0c2d3f4c
AD
96 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), \
97 (long int) max); \
62a3e4f0
AD
98}
99
5372019f 100GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
12b0043a 101GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int)
5372019f 102GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short)
12b0043a
AD
103GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_t)
104GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number_t)
a49aecd5 105GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number_t)
5372019f 106GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t)
d57650a5 107GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number_t)
c3e23647
RS
108
109
3813e141
PE
110/*----------------------------------------------------------------------.
111| Print to OUT a representation of FILENAME escaped both for C and M4. |
112`----------------------------------------------------------------------*/
113
114static void
115escaped_file_name_output (FILE *out, char const *filename)
116{
117 char const *p;
118 fprintf (out, "[[");
119
120 for (p = quotearg_style (c_quoting_style, filename); *p; p++)
121 switch (*p)
122 {
123 case '$': fputs ("$][", out); break;
124 case '@': fputs ("@@", out); break;
125 case '[': fputs ("@{", out); break;
126 case ']': fputs ("@}", out); break;
127 default: fputc (*p, out); break;
128 }
129
130 fprintf (out, "]]");
131}
132
133
39912f52
AD
134/*------------------------------------------------------------------.
135| Prepare the muscles related to the symbols: translate, tname, and |
136| toknum. |
137`------------------------------------------------------------------*/
b0940840 138
4a120d45 139static void
39912f52 140prepare_symbols (void)
c3e23647 141{
39912f52
AD
142 MUSCLE_INSERT_INT ("tokens_number", ntokens);
143 MUSCLE_INSERT_INT ("nterms_number", nvars);
144 MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
145 MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
146
a49aecd5 147 muscle_insert_symbol_number_table ("translate",
fc5734fe
AD
148 token_translations,
149 token_translations[0],
150 1, max_user_token_number + 1);
c3e23647 151
39912f52 152 /* tname -- token names. */
b0940840
AD
153 {
154 int i;
155 int j = 0;
156 for (i = 0; i < nsyms; i++)
157 {
6b98e4b5
AD
158 /* Be sure not to use twice the same QUOTEARG slot:
159 SYMBOL_TAG_GET uses slot 0. */
b0940840
AD
160 const char *cp =
161 quotearg_n_style (1, c_quoting_style,
97650f4e 162 symbols[i]->tag);
01cfa697 163 /* Width of the next token, including the two quotes, the comma
b0940840
AD
164 and the space. */
165 int strsize = strlen (cp) + 2;
166
167 if (j + strsize > 75)
168 {
169 obstack_sgrow (&format_obstack, "\n ");
170 j = 2;
171 }
172
3813e141 173 MUSCLE_OBSTACK_SGROW (&format_obstack, cp);
b0940840
AD
174 obstack_sgrow (&format_obstack, ", ");
175 j += strsize;
176 }
177 /* Add a NULL entry to list of tokens (well, 0, as NULL might not be
178 defined). */
179 obstack_sgrow (&format_obstack, "0");
c3e23647 180
b0940840
AD
181 /* Finish table and store. */
182 obstack_1grow (&format_obstack, 0);
183 muscle_insert ("tname", obstack_finish (&format_obstack));
184 }
185
12b0043a 186 /* Output YYTOKNUM. */
b2ed6e58
AD
187 {
188 int i;
3650b4b8
AD
189 int *values = XCALLOC (int, ntokens);
190 for (i = 0; i < ntokens; ++i)
b0940840 191 values[i] = symbols[i]->user_token_number;
12b0043a 192 muscle_insert_int_table ("toknum", values,
3650b4b8 193 values[0], 1, ntokens);
b0940840 194 free (values);
b2ed6e58 195 }
b0940840 196}
b2ed6e58 197
b0940840
AD
198
199/*-------------------------------------------------------------.
200| Prepare the muscles related to the rules: rhs, prhs, r1, r2, |
95612cfa 201| rline, dprec, merger. |
b0940840
AD
202`-------------------------------------------------------------*/
203
204static void
205prepare_rules (void)
206{
9222837b 207 rule_number_t r;
5df5f6d5 208 unsigned int i = 0;
62a3e4f0 209 item_number_t *rhs = XMALLOC (item_number_t, nritems);
4b3d3a8e
AD
210 unsigned int *prhs = XMALLOC (unsigned int, nrules);
211 unsigned int *rline = XMALLOC (unsigned int, nrules);
212 symbol_number_t *r1 = XMALLOC (symbol_number_t, nrules);
213 unsigned int *r2 = XMALLOC (unsigned int, nrules);
214 short *dprec = XMALLOC (short, nrules);
215 short *merger = XMALLOC (short, nrules);
216
217 for (r = 0; r < nrules; ++r)
b0940840 218 {
9222837b 219 item_number_t *rhsp = NULL;
b0940840
AD
220 /* Index of rule R in RHS. */
221 prhs[r] = i;
222 /* RHS of the rule R. */
223 for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
224 rhs[i++] = *rhsp;
225 /* LHS of the rule R. */
226 r1[r] = rules[r].lhs->number;
227 /* Length of rule R's RHS. */
228 r2[r] = i - prhs[r];
229 /* Separator in RHS. */
230 rhs[i++] = -1;
231 /* Line where rule was defined. */
2073702c 232 rline[r] = rules[r].location.start.line;
95612cfa 233 /* Dynamic precedence (GLR). */
676385e2 234 dprec[r] = rules[r].dprec;
95612cfa 235 /* Merger-function index (GLR). */
676385e2 236 merger[r] = rules[r].merger;
b0940840 237 }
a932883e
PE
238 if (i != nritems)
239 abort ();
b0940840 240
5372019f 241 muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems);
4b3d3a8e
AD
242 muscle_insert_unsigned_int_table ("prhs", prhs, 0, 0, nrules);
243 muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules);
244 muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules);
245 muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules);
246 muscle_insert_short_table ("dprec", dprec, 0, 0, nrules);
247 muscle_insert_short_table ("merger", merger, 0, 0, nrules);
796d61fb 248
39912f52
AD
249 MUSCLE_INSERT_INT ("rules_number", nrules);
250
b0940840
AD
251 free (rhs);
252 free (prhs);
5df5f6d5
AD
253 free (rline);
254 free (r1);
b0940840 255 free (r2);
676385e2
PH
256 free (dprec);
257 free (merger);
c3e23647
RS
258}
259
b0940840
AD
260/*--------------------------------------------.
261| Prepare the muscles related to the states. |
262`--------------------------------------------*/
c3e23647 263
4a120d45 264static void
b0940840 265prepare_states (void)
c3e23647 266{
d57650a5 267 state_number_t i;
a49aecd5
AD
268 symbol_number_t *values =
269 (symbol_number_t *) alloca (sizeof (symbol_number_t) * nstates);
9703cc49 270 for (i = 0; i < nstates; ++i)
29e88316 271 values[i] = states[i]->accessing_symbol;
a49aecd5 272 muscle_insert_symbol_number_table ("stos", values,
d57650a5 273 0, 1, nstates);
39912f52
AD
274
275 MUSCLE_INSERT_INT ("last", high);
276 MUSCLE_INSERT_INT ("final_state_number", final_state->number);
277 MUSCLE_INSERT_INT ("states_number", nstates);
c3e23647
RS
278}
279
280
c3e23647 281
bb33f19a
PE
282/*---------------------------------.
283| Output the user actions to OUT. |
284`---------------------------------*/
12b0043a 285
4a120d45 286static void
c6f1a33c 287user_actions_output (FILE *out)
3f96f4dc 288{
9222837b 289 rule_number_t r;
dafdc66f
AD
290
291 fputs ("m4_define([b4_actions], \n[[", out);
4b3d3a8e 292 for (r = 0; r < nrules; ++r)
9222837b 293 if (rules[r].action)
3f96f4dc 294 {
4b3d3a8e 295 fprintf (out, " case %d:\n", r + 1);
3f96f4dc 296
3813e141 297 fprintf (out, "]b4_syncline([[%d]], ",
2073702c
PE
298 rules[r].action_location.start.line);
299 escaped_file_name_output (out, rules[r].action_location.start.file);
3813e141 300 fprintf (out, ")[\n");
e9955c83 301 fprintf (out, " %s\n break;\n\n",
9222837b 302 rules[r].action);
3f96f4dc 303 }
dafdc66f 304 fputs ("]])\n\n", out);
3f96f4dc
AD
305}
306
676385e2
PH
307/*--------------------------------------.
308| Output the merge functions to OUT. |
309`--------------------------------------*/
310
41442480 311static void
676385e2
PH
312merger_output (FILE *out)
313{
314 int n;
315 merger_list* p;
316
317 fputs ("m4_define([b4_mergers], \n[[", out);
e0e5bf84 318 for (n = 1, p = merge_functions; p != NULL; n += 1, p = p->next)
676385e2 319 {
e0e5bf84 320 if (p->type[0] == '\0')
676385e2
PH
321 fprintf (out, " case %d: yyval = %s (*yy0, *yy1); break;\n",
322 n, p->name);
323 else
324 fprintf (out, " case %d: yyval.%s = %s (*yy0, *yy1); break;\n",
325 n, p->type, p->name);
326 }
327 fputs ("]])\n\n", out);
328}
3f96f4dc 329
ae7453f2
AD
330/*--------------------------------------.
331| Output the tokens definition to OUT. |
332`--------------------------------------*/
091e20bb 333
c6f1a33c 334static void
be2a1a68 335token_definitions_output (FILE *out)
091e20bb
AD
336{
337 int i;
0d8bed56 338 int first = 1;
dafdc66f
AD
339
340 fputs ("m4_define([b4_tokens], \n[", out);
091e20bb
AD
341 for (i = 0; i < ntokens; ++i)
342 {
db8837cb 343 symbol_t *symbol = symbols[i];
091e20bb
AD
344 int number = symbol->user_token_number;
345
b87f8b21
AD
346 /* At this stage, if there are literal aliases, they are part of
347 SYMBOLS, so we should not find symbols which are the aliases
348 here. */
a932883e
PE
349 if (number == USER_NUMBER_ALIAS)
350 abort ();
b87f8b21 351
091e20bb 352 /* Skip error token. */
007a50a4 353 if (symbol == errtoken)
091e20bb 354 continue;
b87f8b21
AD
355
356 /* If this string has an alias, then it is necessarily the alias
357 which is to be output. */
358 if (symbol->alias)
359 symbol = symbol->alias;
360
361 /* Don't output literal chars or strings (when defined only as a
362 string). Note that must be done after the alias resolution:
363 think about `%token 'f' "f"'. */
364 if (symbol->tag[0] == '\'' || symbol->tag[0] == '\"')
365 continue;
091e20bb
AD
366
367 /* Don't #define nonliteral tokens whose names contain periods
368 or '$' (as does the default value of the EOF token). */
369 if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$'))
370 continue;
371
83ccf991 372 fprintf (out, "%s[[[%s]], [%d]]",
0d8bed56 373 first ? "" : ",\n", symbol->tag, number);
b87f8b21 374
0d8bed56 375 first = 0;
091e20bb 376 }
dafdc66f 377 fputs ("])\n\n", out);
091e20bb
AD
378}
379
380
ae7453f2
AD
381/*---------------------------------------.
382| Output the symbol destructors to OUT. |
383`---------------------------------------*/
9280d3ef
AD
384
385static void
386symbol_destructors_output (FILE *out)
387{
388 int i;
389 int first = 1;
390
391 fputs ("m4_define([b4_symbol_destructors], \n[", out);
392 for (i = 0; i < nsyms; ++i)
393 if (symbols[i]->destructor)
394 {
395 symbol_t *symbol = symbols[i];
396
24c0aad7
AD
397 /* Filename, lineno,
398 Symbol-name, Symbol-number,
399 destructor, typename. */
3813e141
PE
400 fprintf (out, "%s[",
401 first ? "" : ",\n");
2073702c 402 escaped_file_name_output (out, symbol->destructor_location.start.file);
3813e141 403 fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
2073702c 404 symbol->destructor_location.start.line,
97650f4e 405 symbol->tag,
24c0aad7
AD
406 symbol->number,
407 symbol->destructor,
408 symbol->type_name);
9280d3ef
AD
409
410 first = 0;
411 }
412 fputs ("])\n\n", out);
413}
414
415
ae7453f2
AD
416/*------------------------------------.
417| Output the symbol printers to OUT. |
418`------------------------------------*/
366eea36
AD
419
420static void
421symbol_printers_output (FILE *out)
422{
423 int i;
424 int first = 1;
425
426 fputs ("m4_define([b4_symbol_printers], \n[", out);
427 for (i = 0; i < nsyms; ++i)
428 if (symbols[i]->destructor)
429 {
430 symbol_t *symbol = symbols[i];
431
432 /* Filename, lineno,
433 Symbol-name, Symbol-number,
ae7453f2 434 printer, typename. */
3813e141
PE
435 fprintf (out, "%s[",
436 first ? "" : ",\n");
2073702c 437 escaped_file_name_output (out, symbol->printer_location.start.file);
3813e141 438 fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
2073702c 439 symbol->printer_location.start.line,
97650f4e 440 symbol->tag,
366eea36
AD
441 symbol->number,
442 symbol->printer,
443 symbol->type_name);
444
445 first = 0;
446 }
447 fputs ("])\n\n", out);
448}
449
450
4a120d45 451static void
c6f1a33c 452prepare_actions (void)
6c89f1c1 453{
c6f1a33c
AD
454 /* Figure out the actions for the specified state, indexed by
455 lookahead token type. */
bbb5bcc6 456
c6f1a33c
AD
457 muscle_insert_rule_number_table ("defact", yydefact,
458 yydefact[0], 1, nstates);
6c89f1c1 459
c6f1a33c
AD
460 /* Figure out what to do after reducing with each rule, depending on
461 the saved state from before the beginning of parsing the data
462 that matched this rule. */
d57650a5
AD
463 muscle_insert_state_number_table ("defgoto", yydefgoto,
464 yydefgoto[0], 1, nsyms - ntokens);
12b0043a 465
12b0043a 466
12b0043a
AD
467 /* Output PACT. */
468 muscle_insert_base_table ("pact", base,
5372019f 469 base[0], 1, nstates);
12b0043a 470 MUSCLE_INSERT_INT ("pact_ninf", base_ninf);
c3e23647 471
12b0043a
AD
472 /* Output PGOTO. */
473 muscle_insert_base_table ("pgoto", base,
5372019f 474 base[nstates], nstates + 1, nvectors);
c3e23647 475
12b0043a
AD
476 muscle_insert_base_table ("table", table,
477 table[0], 1, high + 1);
478 MUSCLE_INSERT_INT ("table_ninf", table_ninf);
676385e2 479
12b0043a
AD
480 muscle_insert_base_table ("check", check,
481 check[0], 1, high + 1);
c3e23647 482
ea99527d
AD
483 /* GLR parsing slightly modifies YYTABLE and YYCHECK (and thus
484 YYPACT) so that in states with unresolved conflicts, the default
485 reduction is not used in the conflicted entries, so that there is
486 a place to put a conflict pointer.
487
488 This means that YYCONFLP and YYCONFL are nonsense for a non-GLR
489 parser, so we could avoid accidents by not writing them out in
490 that case. Nevertheless, it seems even better to be able to use
491 the GLR skeletons even without the non-deterministic tables. */
492 muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table,
39912f52 493 conflict_table[0], 1, high + 1);
ea99527d
AD
494 muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list,
495 conflict_list[0], 1, conflict_list_cnt);
6c89f1c1 496}
c3e23647 497
652def80 498\f
1239777d
AD
499/*---------------------------.
500| Call the skeleton parser. |
501`---------------------------*/
c3e23647 502
4a120d45 503static void
1239777d 504output_skeleton (void)
9b3add5b 505{
573312ac
PE
506 FILE *in;
507 FILE *out;
508 int filter_fd[2];
509 char const *argv[7];
510 pid_t pid;
511
512 /* Compute the names of the package data dir and skeleton file.
513 Test whether m4sugar.m4 is readable, to check for proper
514 installation. A faulty installation can cause deadlock, so a
515 cheap sanity check is worthwhile. */
516 char const m4sugar[] = "m4sugar/m4sugar.m4";
517 char *full_path;
518 char const *p;
519 char const *m4 = (p = getenv ("M4")) ? p : M4;
520 char const *pkgdatadir = (p = getenv ("BISON_PKGDATADIR")) ? p : PKGDATADIR;
521 size_t skeleton_size = strlen (skeleton) + 1;
522 size_t pkgdatadirlen = strlen (pkgdatadir);
523 while (pkgdatadirlen && pkgdatadir[pkgdatadirlen - 1] == '/')
524 pkgdatadirlen--;
525 full_path = xmalloc (pkgdatadirlen + 1
526 + (skeleton_size < sizeof m4sugar
527 ? sizeof m4sugar : skeleton_size));
528 strcpy (full_path, pkgdatadir);
529 full_path[pkgdatadirlen] = '/';
530 strcpy (full_path + pkgdatadirlen + 1, m4sugar);
93ba6bf3 531 xfclose (xfopen (full_path, "r"));
573312ac
PE
532 strcpy (full_path + pkgdatadirlen + 1, skeleton);
533
534 /* Create an m4 subprocess connected to us via two pipes. */
535
536 if (trace_flag & trace_tools)
537 fprintf (stderr, "running: %s -I %s %s - %s\n",
538 m4, pkgdatadir, m4sugar, full_path);
539
540 argv[0] = m4;
541 argv[1] = "-I";
542 argv[2] = pkgdatadir;
543 argv[3] = m4sugar;
544 argv[4] = "-";
545 argv[5] = full_path;
546 argv[6] = NULL;
547
548 init_subpipe ();
549 pid = create_subpipe (argv, filter_fd);
550 free (full_path);
551
552 out = fdopen (filter_fd[0], "w");
553 if (! out)
554 error (EXIT_FAILURE, errno, "fdopen");
555
556 /* Output the definitions of all the muscles. */
381fb12e
AD
557 fputs ("m4_init()\n", out);
558
c6f1a33c 559 user_actions_output (out);
676385e2 560 merger_output (out);
381fb12e 561 token_definitions_output (out);
9280d3ef 562 symbol_destructors_output (out);
366eea36 563 symbol_printers_output (out);
be2a1a68 564
381fb12e 565 muscles_m4_output (out);
be2a1a68 566
381fb12e
AD
567 fputs ("m4_wrap([m4_divert_pop(0)])\n", out);
568 fputs ("m4_divert_push(0)dnl\n", out);
569 xfclose (out);
be2a1a68 570
573312ac 571 /* Read and process m4's output. */
1509d42f 572 timevar_push (TV_M4);
573312ac
PE
573 in = fdopen (filter_fd[1], "r");
574 if (! in)
575 error (EXIT_FAILURE, errno, "fdopen");
576 scan_skel (in);
573312ac
PE
577 xfclose (in);
578 reap_subpipe (pid, m4);
1509d42f 579 timevar_pop (TV_M4);
26f609ff
RA
580}
581
582static void
583prepare (void)
584{
7db2ed2d 585 /* Flags. */
437c2d80 586 MUSCLE_INSERT_INT ("debug", debug_flag);
7db2ed2d
AD
587 MUSCLE_INSERT_INT ("defines_flag", defines_flag);
588 MUSCLE_INSERT_INT ("error_verbose", error_verbose);
437c2d80 589 MUSCLE_INSERT_INT ("locations_flag", locations_flag);
11d82f03 590 MUSCLE_INSERT_INT ("pure", pure_parser);
437c2d80 591 MUSCLE_INSERT_INT ("synclines_flag", !no_lines_flag);
11d82f03 592
573a6cd3 593 /* File names. */
7db2ed2d 594 MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy");
b85810ae 595
7db2ed2d 596 /* User Code. */
0dd1580a
RA
597 obstack_1grow (&pre_prologue_obstack, 0);
598 obstack_1grow (&post_prologue_obstack, 0);
599 muscle_insert ("pre_prologue", obstack_finish (&pre_prologue_obstack));
600 muscle_insert ("post_prologue", obstack_finish (&post_prologue_obstack));
381fb12e
AD
601
602 /* Find the right skeleton file. */
603 if (!skeleton)
676385e2
PH
604 {
605 if (glr_parser)
606 skeleton = "glr.c";
607 else
608 skeleton = "yacc.c";
609 }
381fb12e
AD
610
611 /* Parse the skeleton file and output the needed parsers. */
3813e141 612 MUSCLE_INSERT_C_STRING ("skeleton", skeleton);
26f609ff 613}
c3e23647 614
93ede233 615
6c89f1c1
AD
616/*----------------------------------------------------------.
617| Output the parsing tables and the parser code to ftable. |
618`----------------------------------------------------------*/
c3e23647 619
6c89f1c1
AD
620void
621output (void)
622{
f87685c3 623 obstack_init (&format_obstack);
dd60faec 624
39912f52 625 prepare_symbols ();
b0940840
AD
626 prepare_rules ();
627 prepare_states ();
536545f3 628 prepare_actions ();
342b8b6e 629
26f609ff 630 prepare ();
652def80 631
9b3add5b
RA
632 /* Process the selected skeleton file. */
633 output_skeleton ();
634
f499b062 635 obstack_free (&format_obstack, NULL);
0dd1580a
RA
636 obstack_free (&pre_prologue_obstack, NULL);
637 obstack_free (&post_prologue_obstack, NULL);
c3e23647 638}