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