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