]> git.saurik.com Git - bison.git/blob - src/output.c
Fix portability problem on OpenBSD 4.7.
[bison.git] / src / output.c
1 /* Output the generated parsing program for Bison.
2
3 Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 This file is part of Bison, the GNU Compiler Compiler.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include <config.h>
22 #include "system.h"
23
24 #include <configmake.h>
25 #include <error.h>
26 #include <get-errno.h>
27 #include <pipe.h>
28 #include <quotearg.h>
29 #include <timevar.h>
30 #include <wait-process.h>
31
32 #include "complain.h"
33 #include "files.h"
34 #include "getargs.h"
35 #include "gram.h"
36 #include "muscle-tab.h"
37 #include "output.h"
38 #include "reader.h"
39 #include "scan-code.h" /* max_left_semantic_context */
40 #include "scan-skel.h"
41 #include "symtab.h"
42 #include "tables.h"
43
44 # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
45
46 static struct obstack format_obstack;
47
48
49 /*-------------------------------------------------------------------.
50 | Create a function NAME which associates to the muscle NAME the |
51 | result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
52 | TYPE), and to the muscle NAME_max, the max value of the |
53 | TABLE_DATA. |
54 `-------------------------------------------------------------------*/
55
56
57 #define GENERATE_MUSCLE_INSERT_TABLE(Name, Type) \
58 \
59 static void \
60 Name (char const *name, \
61 Type *table_data, \
62 Type first, \
63 int begin, \
64 int end) \
65 { \
66 Type min = first; \
67 Type max = first; \
68 long int lmin; \
69 long int lmax; \
70 int i; \
71 int j = 1; \
72 \
73 obstack_fgrow1 (&format_obstack, "%6d", first); \
74 for (i = begin; i < end; ++i) \
75 { \
76 obstack_1grow (&format_obstack, ','); \
77 if (j >= 10) \
78 { \
79 obstack_sgrow (&format_obstack, "\n "); \
80 j = 1; \
81 } \
82 else \
83 ++j; \
84 obstack_fgrow1 (&format_obstack, "%6d", table_data[i]); \
85 if (table_data[i] < min) \
86 min = table_data[i]; \
87 if (max < table_data[i]) \
88 max = table_data[i]; \
89 } \
90 obstack_1grow (&format_obstack, 0); \
91 muscle_insert (name, obstack_finish (&format_obstack)); \
92 \
93 lmin = min; \
94 lmax = max; \
95 /* Build `NAME_min' and `NAME_max' in the obstack. */ \
96 obstack_fgrow1 (&format_obstack, "%s_min", name); \
97 obstack_1grow (&format_obstack, 0); \
98 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmin); \
99 obstack_fgrow1 (&format_obstack, "%s_max", name); \
100 obstack_1grow (&format_obstack, 0); \
101 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmax); \
102 }
103
104 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
105 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int)
106 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_number)
107 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number)
108 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number)
109 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number)
110
111
112 /*--------------------------------------------------------------------.
113 | Print to OUT a representation of STRING escaped both for C and M4. |
114 `--------------------------------------------------------------------*/
115
116 static void
117 escaped_output (FILE *out, char const *string)
118 {
119 char const *p;
120 fprintf (out, "[[");
121
122 for (p = quotearg_style (c_quoting_style, string); *p; p++)
123 switch (*p)
124 {
125 case '$': fputs ("$][", out); break;
126 case '@': fputs ("@@", out); break;
127 case '[': fputs ("@{", out); break;
128 case ']': fputs ("@}", out); break;
129 default: fputc (*p, out); break;
130 }
131
132 fprintf (out, "]]");
133 }
134
135
136 /*------------------------------------------------------------------.
137 | Prepare the muscles related to the symbols: translate, tname, and |
138 | toknum. |
139 `------------------------------------------------------------------*/
140
141 static void
142 prepare_symbols (void)
143 {
144 MUSCLE_INSERT_BOOL ("token_table", token_table_flag);
145 MUSCLE_INSERT_INT ("tokens_number", ntokens);
146 MUSCLE_INSERT_INT ("nterms_number", nvars);
147 MUSCLE_INSERT_INT ("symbols_number", nsyms);
148 MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
149 MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
150
151 muscle_insert_symbol_number_table ("translate",
152 token_translations,
153 token_translations[0],
154 1, max_user_token_number + 1);
155
156 /* tname -- token names. */
157 {
158 int i;
159 /* We assume that the table will be output starting at column 2. */
160 int j = 2;
161 struct quoting_options *qo = clone_quoting_options (0);
162 set_quoting_style (qo, c_quoting_style);
163 set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
164 for (i = 0; i < nsyms; i++)
165 {
166 char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);
167 /* Width of the next token, including the two quotes, the
168 comma and the space. */
169 int width = strlen (cp) + 2;
170
171 if (j + width > 75)
172 {
173 obstack_sgrow (&format_obstack, "\n ");
174 j = 1;
175 }
176
177 if (i)
178 obstack_1grow (&format_obstack, ' ');
179 MUSCLE_OBSTACK_SGROW (&format_obstack, cp);
180 free (cp);
181 obstack_1grow (&format_obstack, ',');
182 j += width;
183 }
184 free (qo);
185 obstack_sgrow (&format_obstack, " ]b4_null[");
186
187 /* Finish table and store. */
188 obstack_1grow (&format_obstack, 0);
189 muscle_insert ("tname", obstack_finish (&format_obstack));
190 }
191
192 /* Output YYTOKNUM. */
193 {
194 int i;
195 int *values = xnmalloc (ntokens, sizeof *values);
196 for (i = 0; i < ntokens; ++i)
197 values[i] = symbols[i]->user_token_number;
198 muscle_insert_int_table ("toknum", values,
199 values[0], 1, ntokens);
200 free (values);
201 }
202 }
203
204
205 /*----------------------------------------------------------------.
206 | Prepare the muscles related to the rules: r1, r2, rline, dprec, |
207 | merger, immediate. |
208 `----------------------------------------------------------------*/
209
210 static void
211 prepare_rules (void)
212 {
213 unsigned int *rline = xnmalloc (nrules, sizeof *rline);
214 symbol_number *r1 = xnmalloc (nrules, sizeof *r1);
215 unsigned int *r2 = xnmalloc (nrules, sizeof *r2);
216 int *dprec = xnmalloc (nrules, sizeof *dprec);
217 int *merger = xnmalloc (nrules, sizeof *merger);
218 int *immediate = xnmalloc (nrules, sizeof *immediate);
219
220 rule_number r;
221 for (r = 0; r < nrules; ++r)
222 {
223 /* LHS of the rule R. */
224 r1[r] = rules[r].lhs->number;
225 /* Length of rule R's RHS. */
226 r2[r] = rule_rhs_length(&rules[r]);
227 /* Line where rule was defined. */
228 rline[r] = rules[r].location.start.line;
229 /* Dynamic precedence (GLR). */
230 dprec[r] = rules[r].dprec;
231 /* Merger-function index (GLR). */
232 merger[r] = rules[r].merger;
233 /* Immediate reduction flags (GLR). */
234 immediate[r] = rules[r].is_predicate;
235 }
236
237 muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules);
238 muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules);
239 muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules);
240 muscle_insert_int_table ("dprec", dprec, 0, 0, nrules);
241 muscle_insert_int_table ("merger", merger, 0, 0, nrules);
242 muscle_insert_int_table ("immediate", immediate, 0, 0, nrules);
243
244 MUSCLE_INSERT_INT ("rules_number", nrules);
245 MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context);
246
247 free (rline);
248 free (r1);
249 free (r2);
250 free (dprec);
251 free (merger);
252 }
253
254 /*--------------------------------------------.
255 | Prepare the muscles related to the states. |
256 `--------------------------------------------*/
257
258 static void
259 prepare_states (void)
260 {
261 state_number i;
262 symbol_number *values = xnmalloc (nstates, sizeof *values);
263 for (i = 0; i < nstates; ++i)
264 values[i] = states[i]->accessing_symbol;
265 muscle_insert_symbol_number_table ("stos", values,
266 0, 1, nstates);
267 free (values);
268
269 MUSCLE_INSERT_INT ("last", high);
270 MUSCLE_INSERT_INT ("final_state_number", final_state->number);
271 MUSCLE_INSERT_INT ("states_number", nstates);
272 }
273
274
275 /*-------------------------------------------------------.
276 | Compare two symbols by type-name, and then by number. |
277 `-------------------------------------------------------*/
278
279 static int
280 symbol_type_name_cmp (const symbol **lhs, const symbol **rhs)
281 {
282 int res = UNIQSTR_CMP((*lhs)->type_name, (*rhs)->type_name);
283 if (res)
284 return res;
285 return (*lhs)->number - (*rhs)->number;
286 }
287
288
289 /*----------------------------------------------------------------.
290 | Return a (malloc'ed) table of the symbols sorted by type-name. |
291 `----------------------------------------------------------------*/
292
293 static symbol **
294 symbols_by_type_name (void)
295 {
296 typedef int (*qcmp_type) (const void *, const void *);
297 symbol **res = xmemdup (symbols, nsyms * sizeof *res);
298 qsort (res, nsyms, sizeof *res, (qcmp_type) &symbol_type_name_cmp);
299 return res;
300 }
301
302
303 /*------------------------------------------------------------------.
304 | Define b4_type_names, which is a list of (lists of the numbers of |
305 | symbols with same type-name). |
306 `------------------------------------------------------------------*/
307
308 static void
309 type_names_output (FILE *out)
310 {
311 int i;
312 symbol **syms = symbols_by_type_name ();
313 fputs ("m4_define([b4_type_names],\n[", out);
314 for (i = 0; i < nsyms; /* nothing */)
315 {
316 // The index of the first symbol of the current type-name.
317 int i0 = i;
318 fputs (i ? ",\n[" : "[", out);
319 for (; i < nsyms && syms[i]->type_name == syms[i0]->type_name; ++i)
320 fprintf (out, "%s%d", i != i0 ? ", " : "", syms[i]->number);
321 fputs ("]", out);
322 }
323 fputs ("])\n\n", out);
324 free (syms);
325 }
326
327
328 /*-------------------------------------.
329 | The list of all the symbol numbers. |
330 `-------------------------------------*/
331
332 static void
333 symbol_numbers_output (FILE *out)
334 {
335 int i;
336 fputs ("m4_define([b4_symbol_numbers],\n[", out);
337 for (i = 0; i < nsyms; ++i)
338 fprintf (out, "%s[%d]", i ? ", " : "", i);
339 fputs ("])\n\n", out);
340 }
341
342
343 /*---------------------------------.
344 | Output the user actions to OUT. |
345 `---------------------------------*/
346
347 static void
348 user_actions_output (FILE *out)
349 {
350 rule_number r;
351
352 fputs ("m4_define([b4_actions], \n[", out);
353 for (r = 0; r < nrules; ++r)
354 if (rules[r].action)
355 {
356 fprintf (out, "b4_%scase(%d, [b4_syncline(%d, ",
357 rules[r].is_predicate ? "predicate_" : "",
358 r + 1, rules[r].action_location.start.line);
359 escaped_output (out, rules[r].action_location.start.file);
360 fprintf (out, ")\n[ %s]])\n\n", rules[r].action);
361 }
362 fputs ("])\n\n", out);
363 }
364
365 /*------------------------------------.
366 | Output the merge functions to OUT. |
367 `------------------------------------*/
368
369 static void
370 merger_output (FILE *out)
371 {
372 int n;
373 merger_list* p;
374
375 fputs ("m4_define([b4_mergers], \n[[", out);
376 for (n = 1, p = merge_functions; p != NULL; n += 1, p = p->next)
377 {
378 if (p->type[0] == '\0')
379 fprintf (out, " case %d: *yy0 = %s (*yy0, *yy1); break;\n",
380 n, p->name);
381 else
382 fprintf (out, " case %d: yy0->%s = %s (*yy0, *yy1); break;\n",
383 n, p->type, p->name);
384 }
385 fputs ("]])\n\n", out);
386 }
387
388
389 /*---------------------------------------------.
390 | Prepare the muscles for symbol definitions. |
391 `---------------------------------------------*/
392
393 static void
394 prepare_symbol_definitions (void)
395 {
396 int i;
397 for (i = 0; i < nsyms; ++i)
398 {
399 symbol *sym = symbols[i];
400 const char *key;
401 const char *value;
402
403 #define SET_KEY(Entry) \
404 obstack_fgrow2 (&format_obstack, "symbol(%d, %s)", i, Entry); \
405 obstack_1grow (&format_obstack, 0); \
406 key = obstack_finish (&format_obstack);
407
408 // Whether the symbol has an identifier.
409 value = symbol_id_get (sym);
410 SET_KEY("has_id");
411 MUSCLE_INSERT_INT (key, !!value);
412
413 // Its identifier.
414 SET_KEY("id");
415 MUSCLE_INSERT_STRING (key, value ? value : "");
416
417 // Its tag. Typically for documentation purpose.
418 SET_KEY("tag");
419 MUSCLE_INSERT_STRING (key, sym->tag);
420
421 SET_KEY("user_number");
422 MUSCLE_INSERT_INT (key, sym->user_token_number);
423
424 SET_KEY("is_token");
425 MUSCLE_INSERT_INT (key,
426 i < ntokens && sym != errtoken && sym != undeftoken);
427
428 SET_KEY("number");
429 MUSCLE_INSERT_INT (key, sym->number);
430
431 SET_KEY("has_type");
432 MUSCLE_INSERT_INT (key, !!sym->type_name);
433
434 SET_KEY("type");
435 MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
436
437 #define CODE_PROP(PropName) \
438 do { \
439 code_props const *p = symbol_ ## PropName ## _get (sym); \
440 SET_KEY("has_" #PropName); \
441 MUSCLE_INSERT_INT (key, !!p->code); \
442 \
443 if (p->code) \
444 { \
445 SET_KEY(#PropName "_file"); \
446 MUSCLE_INSERT_STRING (key, p->location.start.file); \
447 \
448 SET_KEY(#PropName "_line"); \
449 MUSCLE_INSERT_INT (key, p->location.start.line); \
450 \
451 SET_KEY(#PropName); \
452 MUSCLE_INSERT_STRING_RAW (key, p->code); \
453 } \
454 } while (0)
455
456 CODE_PROP(destructor);
457 CODE_PROP(printer);
458 #undef CODE_PROP
459 #undef SET_KEY
460 }
461 }
462
463
464 /*--------------------------------------.
465 | Output the tokens definition to OUT. |
466 `--------------------------------------*/
467
468 static void
469 token_definitions_output (FILE *out)
470 {
471 int i;
472 char const *sep = "";
473
474 fputs ("m4_define([b4_tokens], \n[", out);
475 for (i = 0; i < ntokens; ++i)
476 {
477 symbol *sym = symbols[i];
478 int number = sym->user_token_number;
479 uniqstr id = symbol_id_get (sym);
480
481 /* At this stage, if there are literal string aliases, they are
482 part of SYMBOLS, so we should not find their aliased symbols
483 here. */
484 aver (number != USER_NUMBER_HAS_STRING_ALIAS);
485
486 /* Skip error token and tokens without identifier. */
487 if (sym != errtoken && id)
488 {
489 fprintf (out, "%s[[[%s]], %d]",
490 sep, id, number);
491 sep = ",\n";
492 }
493 }
494 fputs ("])\n\n", out);
495 }
496
497
498 static void
499 prepare_actions (void)
500 {
501 /* Figure out the actions for the specified state, indexed by
502 lookahead token type. */
503
504 muscle_insert_rule_number_table ("defact", yydefact,
505 yydefact[0], 1, nstates);
506
507 /* Figure out what to do after reducing with each rule, depending on
508 the saved state from before the beginning of parsing the data
509 that matched this rule. */
510 muscle_insert_state_number_table ("defgoto", yydefgoto,
511 yydefgoto[0], 1, nsyms - ntokens);
512
513
514 /* Output PACT. */
515 muscle_insert_base_table ("pact", base,
516 base[0], 1, nstates);
517 MUSCLE_INSERT_INT ("pact_ninf", base_ninf);
518
519 /* Output PGOTO. */
520 muscle_insert_base_table ("pgoto", base,
521 base[nstates], nstates + 1, nvectors);
522
523 muscle_insert_base_table ("table", table,
524 table[0], 1, high + 1);
525 MUSCLE_INSERT_INT ("table_ninf", table_ninf);
526
527 muscle_insert_base_table ("check", check,
528 check[0], 1, high + 1);
529
530 /* GLR parsing slightly modifies YYTABLE and YYCHECK (and thus
531 YYPACT) so that in states with unresolved conflicts, the default
532 reduction is not used in the conflicted entries, so that there is
533 a place to put a conflict pointer.
534
535 This means that YYCONFLP and YYCONFL are nonsense for a non-GLR
536 parser, so we could avoid accidents by not writing them out in
537 that case. Nevertheless, it seems even better to be able to use
538 the GLR skeletons even without the non-deterministic tables. */
539 muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table,
540 conflict_table[0], 1, high + 1);
541 muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list,
542 0, 1, conflict_list_cnt);
543 }
544
545
546 /*--------------------------------------------.
547 | Output the definitions of all the muscles. |
548 `--------------------------------------------*/
549
550 static void
551 muscles_output (FILE *out)
552 {
553 fputs ("m4_init()\n", out);
554 merger_output (out);
555 symbol_numbers_output (out);
556 token_definitions_output (out);
557 type_names_output (out);
558 user_actions_output (out);
559 // Must be last.
560 muscles_m4_output (out);
561 }
562 \f
563 /*---------------------------.
564 | Call the skeleton parser. |
565 `---------------------------*/
566
567 static void
568 output_skeleton (void)
569 {
570 FILE *in;
571 int filter_fd[2];
572 char const *argv[10];
573 pid_t pid;
574
575 /* Compute the names of the package data dir and skeleton files. */
576 char const m4sugar[] = "m4sugar/m4sugar.m4";
577 char const m4bison[] = "bison.m4";
578 char *full_m4sugar;
579 char *full_m4bison;
580 char *full_skeleton;
581 char const *p;
582 char const *m4 = (p = getenv ("M4")) ? p : M4;
583 char const *pkgdatadir = compute_pkgdatadir ();
584 size_t skeleton_size = strlen (skeleton) + 1;
585 size_t pkgdatadirlen = strlen (pkgdatadir);
586 while (pkgdatadirlen && pkgdatadir[pkgdatadirlen - 1] == '/')
587 pkgdatadirlen--;
588 full_skeleton = xmalloc (pkgdatadirlen + 1
589 + (skeleton_size < sizeof m4sugar
590 ? sizeof m4sugar : skeleton_size));
591 strncpy (full_skeleton, pkgdatadir, pkgdatadirlen);
592 full_skeleton[pkgdatadirlen] = '/';
593 strcpy (full_skeleton + pkgdatadirlen + 1, m4sugar);
594 full_m4sugar = xstrdup (full_skeleton);
595 strcpy (full_skeleton + pkgdatadirlen + 1, m4bison);
596 full_m4bison = xstrdup (full_skeleton);
597 if (strchr (skeleton, '/'))
598 strcpy (full_skeleton, skeleton);
599 else
600 strcpy (full_skeleton + pkgdatadirlen + 1, skeleton);
601
602 /* Test whether m4sugar.m4 is readable, to check for proper
603 installation. A faulty installation can cause deadlock, so a
604 cheap sanity check is worthwhile. */
605 xfclose (xfopen (full_m4sugar, "r"));
606
607 /* Create an m4 subprocess connected to us via two pipes. */
608
609 if (trace_flag & trace_tools)
610 fprintf (stderr, "running: %s %s - %s %s\n",
611 m4, full_m4sugar, full_m4bison, full_skeleton);
612
613 /* Some future version of GNU M4 (most likely 1.6) may treat the -dV in a
614 position-dependent manner. Keep it as the first argument so that all
615 files are traced.
616
617 See the thread starting at
618 <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
619 for details. */
620 {
621 int i = 0;
622 argv[i++] = m4;
623
624 /* When POSIXLY_CORRECT is set, GNU M4 1.6 and later disable GNU
625 extensions, which Bison's skeletons depend on. With older M4,
626 it has no effect. M4 1.4.12 added a -g/--gnu command-line
627 option to make it explicit that a program wants GNU M4
628 extensions even when POSIXLY_CORRECT is set.
629
630 See the thread starting at
631 <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
632 for details. */
633 if (*M4_GNU_OPTION)
634 argv[i++] = M4_GNU_OPTION;
635
636 argv[i++] = "-I";
637 argv[i++] = pkgdatadir;
638 if (trace_flag & trace_m4)
639 argv[i++] = "-dV";
640 argv[i++] = full_m4sugar;
641 argv[i++] = "-";
642 argv[i++] = full_m4bison;
643 argv[i++] = full_skeleton;
644 argv[i++] = NULL;
645 aver (i <= ARRAY_CARDINALITY (argv));
646 }
647
648 /* The ugly cast is because gnulib gets the const-ness wrong. */
649 pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true,
650 true, filter_fd);
651 free (full_m4sugar);
652 free (full_m4bison);
653 free (full_skeleton);
654
655 if (trace_flag & trace_muscles)
656 muscles_output (stderr);
657 {
658 FILE *out = fdopen (filter_fd[1], "w");
659 if (! out)
660 error (EXIT_FAILURE, get_errno (),
661 "fdopen");
662 muscles_output (out);
663 xfclose (out);
664 }
665
666 /* Read and process m4's output. */
667 timevar_push (TV_M4);
668 in = fdopen (filter_fd[0], "r");
669 if (! in)
670 error (EXIT_FAILURE, get_errno (),
671 "fdopen");
672 scan_skel (in);
673 /* scan_skel should have read all of M4's output. Otherwise, when we
674 close the pipe, we risk letting M4 report a broken-pipe to the
675 Bison user. */
676 aver (feof (in));
677 xfclose (in);
678 wait_subprocess (pid, "m4", false, false, true, true, NULL);
679 timevar_pop (TV_M4);
680 }
681
682 static void
683 prepare (void)
684 {
685 /* BISON_USE_PUSH_FOR_PULL is for the test suite and should not be documented
686 for the user. */
687 char const *use_push_for_pull_env = getenv ("BISON_USE_PUSH_FOR_PULL");
688 bool use_push_for_pull_flag = false;
689 if (use_push_for_pull_env != NULL
690 && use_push_for_pull_env[0] != '\0'
691 && 0 != strcmp (use_push_for_pull_env, "0"))
692 use_push_for_pull_flag = true;
693
694 /* Flags. */
695 MUSCLE_INSERT_BOOL ("defines_flag", defines_flag);
696 MUSCLE_INSERT_BOOL ("glr_flag", glr_parser);
697 MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
698 MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
699 MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen);
700 MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag);
701 MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);
702
703 /* File names. */
704 if (spec_name_prefix)
705 MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
706
707 MUSCLE_INSERT_STRING ("file_name_all_but_ext", all_but_ext);
708
709 #define DEFINE(Name) MUSCLE_INSERT_STRING (#Name, Name ? Name : "")
710 DEFINE (dir_prefix);
711 DEFINE (parser_file_name);
712 DEFINE (spec_defines_file);
713 DEFINE (spec_file_prefix);
714 DEFINE (spec_graph_file);
715 DEFINE (spec_name_prefix);
716 DEFINE (spec_outfile);
717 DEFINE (spec_verbose_file);
718 #undef DEFINE
719
720 /* Find the right skeleton file, and add muscles about the skeletons. */
721 if (skeleton)
722 MUSCLE_INSERT_C_STRING ("skeleton", skeleton);
723 else
724 skeleton = language->skeleton;
725
726 /* About the skeletons. */
727 {
728 /* b4_pkgdatadir is used inside m4_include in the skeletons, so digraphs
729 would never be expanded. Hopefully no one has M4-special characters in
730 his Bison installation path. */
731 MUSCLE_INSERT_STRING_RAW ("pkgdatadir", compute_pkgdatadir ());
732 }
733 }
734
735
736 /*----------------------------------------------------------.
737 | Output the parsing tables and the parser code to ftable. |
738 `----------------------------------------------------------*/
739
740 void
741 output (void)
742 {
743 obstack_init (&format_obstack);
744
745 prepare_symbols ();
746 prepare_rules ();
747 prepare_states ();
748 prepare_actions ();
749 prepare_symbol_definitions ();
750
751 prepare ();
752
753 /* Process the selected skeleton file. */
754 output_skeleton ();
755
756 obstack_free (&format_obstack, NULL);
757 }
758
759 char const *
760 compute_pkgdatadir (void)
761 {
762 char const *pkgdatadir = getenv ("BISON_PKGDATADIR");
763 return pkgdatadir ? pkgdatadir : PKGDATADIR;
764 }