Import byacc-20170709
[dragonfly.git] / contrib / byacc / output.c
blob9f87911d801412a3c7b84ebdf4523909c3f1d57a
1 /* $Id: output.c,v 1.83 2017/07/09 18:13:42 tom Exp $ */
3 #include "defs.h"
5 #define StaticOrR (rflag ? "" : "static ")
6 #define CountLine(fp) (!rflag || ((fp) == code_file))
8 #if defined(YYBTYACC)
9 #define PER_STATE 3
10 #else
11 #define PER_STATE 2
12 #endif
14 static int nvectors;
15 static int nentries;
16 static Value_t **froms;
17 static Value_t **tos;
18 #if defined(YYBTYACC)
19 static Value_t *conflicts = NULL;
20 static Value_t nconflicts = 0;
21 #endif
22 static Value_t *tally;
23 static Value_t *width;
24 static Value_t *state_count;
25 static Value_t *order;
26 static Value_t *base;
27 static Value_t *pos;
28 static int maxtable;
29 static Value_t *table;
30 static Value_t *check;
31 static int lowzero;
32 static long high;
34 static void
35 putc_code(FILE * fp, int c)
37 if ((c == '\n') && (fp == code_file))
38 ++outline;
39 putc(c, fp);
42 static void
43 putl_code(FILE * fp, const char *s)
45 if (fp == code_file)
46 ++outline;
47 fputs(s, fp);
50 static void
51 puts_code(FILE * fp, const char *s)
53 fputs(s, fp);
56 static void
57 puts_param_types(FILE * fp, param *list, int more)
59 param *p;
61 if (list != 0)
63 for (p = list; p; p = p->next)
65 size_t len_type = strlen(p->type);
66 fprintf(fp, "%s%s%s%s%s", p->type,
67 (((len_type != 0) && (p->type[len_type - 1] == '*'))
68 ? ""
69 : " "),
70 p->name, p->type2,
71 ((more || p->next) ? ", " : ""));
74 else
76 if (!more)
77 fprintf(fp, "void");
81 static void
82 puts_param_names(FILE * fp, param *list, int more)
84 param *p;
86 for (p = list; p; p = p->next)
88 fprintf(fp, "%s%s", p->name,
89 ((more || p->next) ? ", " : ""));
93 static void
94 write_code_lineno(FILE * fp)
96 if (!lflag && (fp == code_file))
98 ++outline;
99 fprintf(fp, line_format, outline + 1, code_file_name);
103 static void
104 write_input_lineno(void)
106 if (!lflag)
108 ++outline;
109 fprintf(code_file, line_format, lineno, input_file_name);
113 static void
114 define_prefixed(FILE * fp, const char *name)
116 int bump_line = CountLine(fp);
117 if (bump_line)
118 ++outline;
119 fprintf(fp, "\n");
121 if (bump_line)
122 ++outline;
123 fprintf(fp, "#ifndef %s\n", name);
125 if (bump_line)
126 ++outline;
127 fprintf(fp, "#define %-10s %s%s\n", name, symbol_prefix, name + 2);
129 if (bump_line)
130 ++outline;
131 fprintf(fp, "#endif /* %s */\n", name);
134 static void
135 output_prefix(FILE * fp)
137 if (symbol_prefix == NULL)
139 symbol_prefix = "yy";
141 else
143 define_prefixed(fp, "yyparse");
144 define_prefixed(fp, "yylex");
145 define_prefixed(fp, "yyerror");
146 define_prefixed(fp, "yychar");
147 define_prefixed(fp, "yyval");
148 define_prefixed(fp, "yylval");
149 define_prefixed(fp, "yydebug");
150 define_prefixed(fp, "yynerrs");
151 define_prefixed(fp, "yyerrflag");
152 define_prefixed(fp, "yylhs");
153 define_prefixed(fp, "yylen");
154 define_prefixed(fp, "yydefred");
155 #if defined(YYBTYACC)
156 define_prefixed(fp, "yystos");
157 #endif
158 define_prefixed(fp, "yydgoto");
159 define_prefixed(fp, "yysindex");
160 define_prefixed(fp, "yyrindex");
161 define_prefixed(fp, "yygindex");
162 define_prefixed(fp, "yytable");
163 define_prefixed(fp, "yycheck");
164 define_prefixed(fp, "yyname");
165 define_prefixed(fp, "yyrule");
166 #if defined(YYBTYACC)
167 if (locations)
169 define_prefixed(fp, "yyloc");
170 define_prefixed(fp, "yylloc");
172 putc_code(fp, '\n');
173 putl_code(fp, "#if YYBTYACC\n");
175 define_prefixed(fp, "yycindex");
176 define_prefixed(fp, "yyctable");
178 putc_code(fp, '\n');
179 putl_code(fp, "#endif /* YYBTYACC */\n");
180 putc_code(fp, '\n');
181 #endif
183 if (CountLine(fp))
184 ++outline;
185 fprintf(fp, "#define YYPREFIX \"%s\"\n", symbol_prefix);
188 static void
189 output_newline(void)
191 if (!rflag)
192 ++outline;
193 putc('\n', output_file);
196 static void
197 output_line(const char *value)
199 fputs(value, output_file);
200 output_newline();
203 static void
204 output_int(int value)
206 fprintf(output_file, "%5d,", value);
209 static void
210 start_int_table(const char *name, int value)
212 int need = 34 - (int)(strlen(symbol_prefix) + strlen(name));
214 if (need < 6)
215 need = 6;
216 fprintf(output_file,
217 "%sconst YYINT %s%s[] = {%*d,",
218 StaticOrR, symbol_prefix, name, need, value);
221 static void
222 start_str_table(const char *name)
224 fprintf(output_file,
225 "%sconst char *const %s%s[] = {",
226 StaticOrR, symbol_prefix, name);
227 output_newline();
230 static void
231 end_table(void)
233 output_newline();
234 output_line("};");
237 static void
238 output_stype(FILE * fp)
240 if (!unionized && ntags == 0)
242 putc_code(fp, '\n');
243 putl_code(fp, "#if "
244 "! defined(YYSTYPE) && "
245 "! defined(YYSTYPE_IS_DECLARED)\n");
246 putl_code(fp, "/* Default: YYSTYPE is the semantic value type. */\n");
247 putl_code(fp, "typedef int YYSTYPE;\n");
248 putl_code(fp, "# define YYSTYPE_IS_DECLARED 1\n");
249 putl_code(fp, "#endif\n");
253 #if defined(YYBTYACC)
254 static void
255 output_ltype(FILE * fp)
257 putc_code(fp, '\n');
258 putl_code(fp, "#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n");
259 putl_code(fp, "/* Default: YYLTYPE is the text position type. */\n");
260 putl_code(fp, "typedef struct YYLTYPE\n");
261 putl_code(fp, "{\n");
262 putl_code(fp, " int first_line;\n");
263 putl_code(fp, " int first_column;\n");
264 putl_code(fp, " int last_line;\n");
265 putl_code(fp, " int last_column;\n");
266 putl_code(fp, " unsigned source;\n");
267 putl_code(fp, "} YYLTYPE;\n");
268 putl_code(fp, "#define YYLTYPE_IS_DECLARED 1\n");
269 putl_code(fp, "#endif\n");
270 putl_code(fp, "#define YYRHSLOC(rhs, k) ((rhs)[k])\n");
272 #endif
274 static void
275 output_YYINT_typedef(FILE * fp)
277 /* generate the type used to index the various parser tables */
278 if (CountLine(fp))
279 ++outline;
280 fprintf(fp, "typedef %s YYINT;\n", CONCAT1("", YYINT));
283 static void
284 output_rule_data(void)
286 int i;
287 int j;
289 output_YYINT_typedef(output_file);
291 start_int_table("lhs", symbol_value[start_symbol]);
293 j = 10;
294 for (i = 3; i < nrules; i++)
296 if (j >= 10)
298 output_newline();
299 j = 1;
301 else
302 ++j;
304 output_int(symbol_value[rlhs[i]]);
306 end_table();
308 start_int_table("len", 2);
310 j = 10;
311 for (i = 3; i < nrules; i++)
313 if (j >= 10)
315 output_newline();
316 j = 1;
318 else
319 j++;
321 output_int(rrhs[i + 1] - rrhs[i] - 1);
323 end_table();
326 static void
327 output_yydefred(void)
329 int i, j;
331 start_int_table("defred", (defred[0] ? defred[0] - 2 : 0));
333 j = 10;
334 for (i = 1; i < nstates; i++)
336 if (j < 10)
337 ++j;
338 else
340 output_newline();
341 j = 1;
344 output_int((defred[i] ? defred[i] - 2 : 0));
347 end_table();
350 #if defined(YYBTYACC)
351 static void
352 output_accessing_symbols(void)
354 int i, j;
355 int *translate;
357 if (nstates != 0)
359 translate = TMALLOC(int, nstates);
360 NO_SPACE(translate);
362 for (i = 0; i < nstates; ++i)
364 int gsymb = accessing_symbol[i];
366 translate[i] = symbol_pval[gsymb];
369 putl_code(output_file,
370 "#if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)\n");
371 /* yystos[] may be unused, depending on compile-time defines */
372 start_int_table("stos", translate[0]);
374 j = 10;
375 for (i = 1; i < nstates; ++i)
377 if (j < 10)
378 ++j;
379 else
381 output_newline();
382 j = 1;
385 output_int(translate[i]);
388 end_table();
389 FREE(translate);
390 putl_code(output_file,
391 "#endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */\n");
395 static Value_t
396 find_conflict_base(int cbase)
398 int i, j;
400 for (i = 0; i < cbase; i++)
402 for (j = 0; j + cbase < nconflicts; j++)
404 if (conflicts[i + j] != conflicts[cbase + j])
405 break;
407 if (j + cbase >= nconflicts)
408 break;
410 return (Value_t)i;
412 #endif
414 static void
415 token_actions(void)
417 int i, j;
418 Value_t shiftcount, reducecount;
419 #if defined(YYBTYACC)
420 Value_t conflictcount = 0;
421 Value_t csym = -1;
422 Value_t cbase = 0;
423 #endif
424 int max, min;
425 Value_t *actionrow, *r, *s;
426 action *p;
428 actionrow = NEW2(PER_STATE * ntokens, Value_t);
429 for (i = 0; i < nstates; ++i)
431 if (parser[i])
433 for (j = 0; j < PER_STATE * ntokens; ++j)
434 actionrow[j] = 0;
436 shiftcount = 0;
437 reducecount = 0;
438 #if defined(YYBTYACC)
439 if (backtrack)
441 conflictcount = 0;
442 csym = -1;
443 cbase = nconflicts;
445 #endif
446 for (p = parser[i]; p; p = p->next)
448 #if defined(YYBTYACC)
449 if (backtrack)
451 if (csym != -1 && csym != p->symbol)
453 conflictcount++;
454 conflicts[nconflicts++] = -1;
455 j = find_conflict_base(cbase);
456 actionrow[csym + 2 * ntokens] = (Value_t)(j + 1);
457 if (j == cbase)
459 cbase = nconflicts;
461 else
463 if (conflicts[cbase] == -1)
464 cbase++;
465 nconflicts = cbase;
467 csym = -1;
470 #endif
471 if (p->suppressed == 0)
473 if (p->action_code == SHIFT)
475 ++shiftcount;
476 actionrow[p->symbol] = p->number;
478 else if (p->action_code == REDUCE && p->number != defred[i])
480 ++reducecount;
481 actionrow[p->symbol + ntokens] = p->number;
484 #if defined(YYBTYACC)
485 else if (backtrack && p->suppressed == 1)
487 csym = p->symbol;
488 if (p->action_code == SHIFT)
490 conflicts[nconflicts++] = p->number;
492 else if (p->action_code == REDUCE && p->number != defred[i])
494 if (cbase == nconflicts)
496 if (cbase)
497 cbase--;
498 else
499 conflicts[nconflicts++] = -1;
501 conflicts[nconflicts++] = (Value_t)(p->number - 2);
504 #endif
506 #if defined(YYBTYACC)
507 if (backtrack && csym != -1)
509 conflictcount++;
510 conflicts[nconflicts++] = -1;
511 j = find_conflict_base(cbase);
512 actionrow[csym + 2 * ntokens] = (Value_t)(j + 1);
513 if (j == cbase)
515 cbase = nconflicts;
517 else
519 if (conflicts[cbase] == -1)
520 cbase++;
521 nconflicts = cbase;
524 #endif
526 tally[i] = shiftcount;
527 tally[nstates + i] = reducecount;
528 #if defined(YYBTYACC)
529 if (backtrack)
530 tally[2 * nstates + i] = conflictcount;
531 #endif
532 width[i] = 0;
533 width[nstates + i] = 0;
534 #if defined(YYBTYACC)
535 if (backtrack)
536 width[2 * nstates + i] = 0;
537 #endif
538 if (shiftcount > 0)
540 froms[i] = r = NEW2(shiftcount, Value_t);
541 tos[i] = s = NEW2(shiftcount, Value_t);
542 min = MAXYYINT;
543 max = 0;
544 for (j = 0; j < ntokens; ++j)
546 if (actionrow[j])
548 if (min > symbol_value[j])
549 min = symbol_value[j];
550 if (max < symbol_value[j])
551 max = symbol_value[j];
552 *r++ = symbol_value[j];
553 *s++ = actionrow[j];
556 width[i] = (Value_t)(max - min + 1);
558 if (reducecount > 0)
560 froms[nstates + i] = r = NEW2(reducecount, Value_t);
561 tos[nstates + i] = s = NEW2(reducecount, Value_t);
562 min = MAXYYINT;
563 max = 0;
564 for (j = 0; j < ntokens; ++j)
566 if (actionrow[ntokens + j])
568 if (min > symbol_value[j])
569 min = symbol_value[j];
570 if (max < symbol_value[j])
571 max = symbol_value[j];
572 *r++ = symbol_value[j];
573 *s++ = (Value_t)(actionrow[ntokens + j] - 2);
576 width[nstates + i] = (Value_t)(max - min + 1);
578 #if defined(YYBTYACC)
579 if (backtrack && conflictcount > 0)
581 froms[2 * nstates + i] = r = NEW2(conflictcount, Value_t);
582 tos[2 * nstates + i] = s = NEW2(conflictcount, Value_t);
583 min = MAXYYINT;
584 max = 0;
585 for (j = 0; j < ntokens; ++j)
587 if (actionrow[2 * ntokens + j])
589 if (min > symbol_value[j])
590 min = symbol_value[j];
591 if (max < symbol_value[j])
592 max = symbol_value[j];
593 *r++ = symbol_value[j];
594 *s++ = (Value_t)(actionrow[2 * ntokens + j] - 1);
597 width[2 * nstates + i] = (Value_t)(max - min + 1);
599 #endif
602 FREE(actionrow);
605 static int
606 default_goto(int symbol)
608 int i;
609 int m;
610 int n;
611 int default_state;
612 int max;
614 m = goto_map[symbol];
615 n = goto_map[symbol + 1];
617 if (m == n)
618 return (0);
620 for (i = 0; i < nstates; i++)
621 state_count[i] = 0;
623 for (i = m; i < n; i++)
624 state_count[to_state[i]]++;
626 max = 0;
627 default_state = 0;
628 for (i = 0; i < nstates; i++)
630 if (state_count[i] > max)
632 max = state_count[i];
633 default_state = i;
637 return (default_state);
640 static void
641 save_column(int symbol, int default_state)
643 int i;
644 int m;
645 int n;
646 Value_t *sp;
647 Value_t *sp1;
648 Value_t *sp2;
649 Value_t count;
650 int symno;
652 m = goto_map[symbol];
653 n = goto_map[symbol + 1];
655 count = 0;
656 for (i = m; i < n; i++)
658 if (to_state[i] != default_state)
659 ++count;
661 if (count == 0)
662 return;
664 symno = symbol_value[symbol] + PER_STATE * nstates;
666 froms[symno] = sp1 = sp = NEW2(count, Value_t);
667 tos[symno] = sp2 = NEW2(count, Value_t);
669 for (i = m; i < n; i++)
671 if (to_state[i] != default_state)
673 *sp1++ = from_state[i];
674 *sp2++ = to_state[i];
678 tally[symno] = count;
679 width[symno] = (Value_t)(sp1[-1] - sp[0] + 1);
682 static void
683 goto_actions(void)
685 int i, j, k;
687 state_count = NEW2(nstates, Value_t);
689 k = default_goto(start_symbol + 1);
690 start_int_table("dgoto", k);
691 save_column(start_symbol + 1, k);
693 j = 10;
694 for (i = start_symbol + 2; i < nsyms; i++)
696 if (j >= 10)
698 output_newline();
699 j = 1;
701 else
702 ++j;
704 k = default_goto(i);
705 output_int(k);
706 save_column(i, k);
709 end_table();
710 FREE(state_count);
713 static void
714 sort_actions(void)
716 Value_t i;
717 int j;
718 int k;
719 int t;
720 int w;
722 order = NEW2(nvectors, Value_t);
723 nentries = 0;
725 for (i = 0; i < nvectors; i++)
727 if (tally[i] > 0)
729 t = tally[i];
730 w = width[i];
731 j = nentries - 1;
733 while (j >= 0 && (width[order[j]] < w))
734 j--;
736 while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
737 j--;
739 for (k = nentries - 1; k > j; k--)
740 order[k + 1] = order[k];
742 order[j + 1] = i;
743 nentries++;
748 /* The function matching_vector determines if the vector specified by */
749 /* the input parameter matches a previously considered vector. The */
750 /* test at the start of the function checks if the vector represents */
751 /* a row of shifts over terminal symbols or a row of reductions, or a */
752 /* column of shifts over a nonterminal symbol. Berkeley Yacc does not */
753 /* check if a column of shifts over a nonterminal symbols matches a */
754 /* previously considered vector. Because of the nature of LR parsing */
755 /* tables, no two columns can match. Therefore, the only possible */
756 /* match would be between a row and a column. Such matches are */
757 /* unlikely. Therefore, to save time, no attempt is made to see if a */
758 /* column matches a previously considered vector. */
759 /* */
760 /* Matching_vector is poorly designed. The test could easily be made */
761 /* faster. Also, it depends on the vectors being in a specific */
762 /* order. */
763 #if defined(YYBTYACC)
764 /* */
765 /* Not really any point in checking for matching conflicts -- it is */
766 /* extremely unlikely to occur, and conflicts are (hopefully) rare. */
767 #endif
769 static int
770 matching_vector(int vector)
772 int i;
773 int j;
774 int k;
775 int t;
776 int w;
777 int match;
778 int prev;
780 i = order[vector];
781 if (i >= 2 * nstates)
782 return (-1);
784 t = tally[i];
785 w = width[i];
787 for (prev = vector - 1; prev >= 0; prev--)
789 j = order[prev];
790 if (width[j] != w || tally[j] != t)
791 return (-1);
793 match = 1;
794 for (k = 0; match && k < t; k++)
796 if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
797 match = 0;
800 if (match)
801 return (j);
804 return (-1);
807 static int
808 pack_vector(int vector)
810 int i, j, k, l;
811 int t;
812 int loc;
813 int ok;
814 Value_t *from;
815 Value_t *to;
816 int newmax;
818 i = order[vector];
819 t = tally[i];
820 assert(t);
822 from = froms[i];
823 to = tos[i];
825 j = lowzero - from[0];
826 for (k = 1; k < t; ++k)
827 if (lowzero - from[k] > j)
828 j = lowzero - from[k];
829 for (;; ++j)
831 if (j == 0)
832 continue;
833 ok = 1;
834 for (k = 0; ok && k < t; k++)
836 loc = j + from[k];
837 if (loc >= maxtable - 1)
839 if (loc >= MAXTABLE - 1)
840 fatal("maximum table size exceeded");
842 newmax = maxtable;
845 newmax += 200;
847 while (newmax <= loc);
849 table = TREALLOC(Value_t, table, newmax);
850 NO_SPACE(table);
852 check = TREALLOC(Value_t, check, newmax);
853 NO_SPACE(check);
855 for (l = maxtable; l < newmax; ++l)
857 table[l] = 0;
858 check[l] = -1;
860 maxtable = newmax;
863 if (check[loc] != -1)
864 ok = 0;
866 for (k = 0; ok && k < vector; k++)
868 if (pos[k] == j)
869 ok = 0;
871 if (ok)
873 for (k = 0; k < t; k++)
875 loc = j + from[k];
876 table[loc] = to[k];
877 check[loc] = from[k];
878 if (loc > high)
879 high = loc;
882 while (check[lowzero] != -1)
883 ++lowzero;
885 return (j);
890 static void
891 pack_table(void)
893 int i;
894 Value_t place;
895 int state;
897 base = NEW2(nvectors, Value_t);
898 pos = NEW2(nentries, Value_t);
900 maxtable = 1000;
901 table = NEW2(maxtable, Value_t);
902 check = NEW2(maxtable, Value_t);
904 lowzero = 0;
905 high = 0;
907 for (i = 0; i < maxtable; i++)
908 check[i] = -1;
910 for (i = 0; i < nentries; i++)
912 state = matching_vector(i);
914 if (state < 0)
915 place = (Value_t)pack_vector(i);
916 else
917 place = base[state];
919 pos[i] = place;
920 base[order[i]] = place;
923 for (i = 0; i < nvectors; i++)
925 if (froms[i])
926 FREE(froms[i]);
927 if (tos[i])
928 FREE(tos[i]);
931 DO_FREE(froms);
932 DO_FREE(tos);
933 DO_FREE(tally);
934 DO_FREE(width);
935 DO_FREE(pos);
938 static void
939 output_base(void)
941 int i, j;
943 start_int_table("sindex", base[0]);
945 j = 10;
946 for (i = 1; i < nstates; i++)
948 if (j >= 10)
950 output_newline();
951 j = 1;
953 else
954 ++j;
956 output_int(base[i]);
959 end_table();
961 start_int_table("rindex", base[nstates]);
963 j = 10;
964 for (i = nstates + 1; i < 2 * nstates; i++)
966 if (j >= 10)
968 output_newline();
969 j = 1;
971 else
972 ++j;
974 output_int(base[i]);
977 end_table();
979 #if defined(YYBTYACC)
980 output_line("#if YYBTYACC");
981 start_int_table("cindex", base[2 * nstates]);
983 j = 10;
984 for (i = 2 * nstates + 1; i < 3 * nstates; i++)
986 if (j >= 10)
988 output_newline();
989 j = 1;
991 else
992 ++j;
994 output_int(base[i]);
997 end_table();
998 output_line("#endif");
999 #endif
1001 start_int_table("gindex", base[PER_STATE * nstates]);
1003 j = 10;
1004 for (i = PER_STATE * nstates + 1; i < nvectors - 1; i++)
1006 if (j >= 10)
1008 output_newline();
1009 j = 1;
1011 else
1012 ++j;
1014 output_int(base[i]);
1017 end_table();
1018 FREE(base);
1021 static void
1022 output_table(void)
1024 int i;
1025 int j;
1027 if (high >= MAXYYINT)
1029 fprintf(stderr, "YYTABLESIZE: %ld\n", high);
1030 fprintf(stderr, "Table is longer than %d elements.\n", MAXYYINT);
1031 done(1);
1034 ++outline;
1035 fprintf(code_file, "#define YYTABLESIZE %ld\n", high);
1036 start_int_table("table", table[0]);
1038 j = 10;
1039 for (i = 1; i <= high; i++)
1041 if (j >= 10)
1043 output_newline();
1044 j = 1;
1046 else
1047 ++j;
1049 output_int(table[i]);
1052 end_table();
1053 FREE(table);
1056 static void
1057 output_check(void)
1059 int i;
1060 int j;
1062 start_int_table("check", check[0]);
1064 j = 10;
1065 for (i = 1; i <= high; i++)
1067 if (j >= 10)
1069 output_newline();
1070 j = 1;
1072 else
1073 ++j;
1075 output_int(check[i]);
1078 end_table();
1079 FREE(check);
1082 #if defined(YYBTYACC)
1083 static void
1084 output_ctable(void)
1086 int i;
1087 int j;
1088 int limit = (conflicts != 0) ? nconflicts : 0;
1090 if (limit < high)
1091 limit = (int)high;
1093 output_line("#if YYBTYACC");
1094 start_int_table("ctable", conflicts ? conflicts[0] : -1);
1096 j = 10;
1097 for (i = 1; i < limit; i++)
1099 if (j >= 10)
1101 output_newline();
1102 j = 1;
1104 else
1105 ++j;
1107 output_int((conflicts != 0 && i < nconflicts) ? conflicts[i] : -1);
1110 if (conflicts)
1111 FREE(conflicts);
1113 end_table();
1114 output_line("#endif");
1116 #endif
1118 static void
1119 output_actions(void)
1121 nvectors = PER_STATE * nstates + nvars;
1123 froms = NEW2(nvectors, Value_t *);
1124 tos = NEW2(nvectors, Value_t *);
1125 tally = NEW2(nvectors, Value_t);
1126 width = NEW2(nvectors, Value_t);
1128 #if defined(YYBTYACC)
1129 if (backtrack && (SRtotal + RRtotal) != 0)
1130 conflicts = NEW2(4 * (SRtotal + RRtotal), Value_t);
1131 #endif
1133 token_actions();
1134 FREE(lookaheads);
1135 FREE(LA);
1136 FREE(LAruleno);
1137 FREE(accessing_symbol);
1139 goto_actions();
1140 FREE(goto_base);
1141 FREE(from_state);
1142 FREE(to_state);
1144 sort_actions();
1145 pack_table();
1146 output_base();
1147 output_table();
1148 output_check();
1149 #if defined(YYBTYACC)
1150 output_ctable();
1151 #endif
1154 static int
1155 is_C_identifier(char *name)
1157 char *s;
1158 int c;
1160 s = name;
1161 c = *s;
1162 if (c == '"')
1164 c = *++s;
1165 if (!IS_NAME1(c))
1166 return (0);
1167 while ((c = *++s) != '"')
1169 if (!IS_NAME2(c))
1170 return (0);
1172 return (1);
1175 if (!IS_NAME1(c))
1176 return (0);
1177 while ((c = *++s) != 0)
1179 if (!IS_NAME2(c))
1180 return (0);
1182 return (1);
1185 #if USE_HEADER_GUARDS
1186 static void
1187 start_defines_file(void)
1189 fprintf(defines_file, "#ifndef _%s_defines_h_\n", symbol_prefix);
1190 fprintf(defines_file, "#define _%s_defines_h_\n\n", symbol_prefix);
1193 static void
1194 end_defines_file(void)
1196 fprintf(defines_file, "\n#endif /* _%s_defines_h_ */\n", symbol_prefix);
1198 #else
1199 #define start_defines_file() /* nothing */
1200 #define end_defines_file() /* nothing */
1201 #endif
1203 static void
1204 output_defines(FILE * fp)
1206 int c, i;
1207 char *s;
1209 for (i = 2; i < ntokens; ++i)
1211 s = symbol_name[i];
1212 if (is_C_identifier(s) && (!sflag || *s != '"'))
1214 fprintf(fp, "#define ");
1215 c = *s;
1216 if (c == '"')
1218 while ((c = *++s) != '"')
1220 putc(c, fp);
1223 else
1227 putc(c, fp);
1229 while ((c = *++s) != 0);
1231 if (fp == code_file)
1232 ++outline;
1233 fprintf(fp, " %d\n", symbol_value[i]);
1237 if (fp == code_file)
1238 ++outline;
1239 if (fp != defines_file || iflag)
1240 fprintf(fp, "#define YYERRCODE %d\n", symbol_value[1]);
1242 if (token_table && rflag && fp != externs_file)
1244 if (fp == code_file)
1245 ++outline;
1246 fputs("#undef yytname\n", fp);
1247 if (fp == code_file)
1248 ++outline;
1249 fputs("#define yytname yyname\n", fp);
1252 if (fp == defines_file || (iflag && !dflag))
1254 if (unionized)
1256 if (union_file != 0)
1258 rewind(union_file);
1259 while ((c = getc(union_file)) != EOF)
1260 putc_code(fp, c);
1262 fprintf(fp, "extern YYSTYPE %slval;\n", symbol_prefix);
1264 #if defined(YYBTYACC)
1265 if (locations)
1266 output_ltype(fp);
1267 #endif
1271 static void
1272 output_stored_text(FILE * fp)
1274 int c;
1275 FILE *in;
1277 rewind(text_file);
1278 if (text_file == NULL)
1279 open_error("text_file");
1280 in = text_file;
1281 if ((c = getc(in)) == EOF)
1282 return;
1283 putc_code(fp, c);
1284 while ((c = getc(in)) != EOF)
1286 putc_code(fp, c);
1288 write_code_lineno(fp);
1291 static void
1292 output_debug(void)
1294 int i, j, k, max, maxtok;
1295 const char **symnam;
1296 const char *s;
1298 ++outline;
1299 fprintf(code_file, "#define YYFINAL %d\n", final_state);
1301 putl_code(code_file, "#ifndef YYDEBUG\n");
1302 ++outline;
1303 fprintf(code_file, "#define YYDEBUG %d\n", tflag);
1304 putl_code(code_file, "#endif\n");
1306 if (rflag)
1308 fprintf(output_file, "#ifndef YYDEBUG\n");
1309 fprintf(output_file, "#define YYDEBUG %d\n", tflag);
1310 fprintf(output_file, "#endif\n");
1313 maxtok = 0;
1314 for (i = 0; i < ntokens; ++i)
1315 if (symbol_value[i] > maxtok)
1316 maxtok = symbol_value[i];
1318 /* symbol_value[$accept] = -1 */
1319 /* symbol_value[<goal>] = 0 */
1320 /* remaining non-terminals start at 1 */
1321 max = maxtok;
1322 for (i = ntokens; i < nsyms; ++i)
1323 if (((maxtok + 1) + (symbol_value[i] + 1)) > max)
1324 max = (maxtok + 1) + (symbol_value[i] + 1);
1326 ++outline;
1327 fprintf(code_file, "#define YYMAXTOKEN %d\n", maxtok);
1329 ++outline;
1330 fprintf(code_file, "#define YYUNDFTOKEN %d\n", max + 1);
1332 ++outline;
1333 fprintf(code_file, "#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? "
1334 "YYUNDFTOKEN : (a))\n");
1336 symnam = TMALLOC(const char *, max + 2);
1337 NO_SPACE(symnam);
1339 /* Note that it is not necessary to initialize the element */
1340 /* symnam[max]. */
1341 #if defined(YYBTYACC)
1342 for (i = 0; i < max; ++i)
1343 symnam[i] = 0;
1344 for (i = nsyms - 1; i >= 0; --i)
1345 symnam[symbol_pval[i]] = symbol_name[i];
1346 symnam[max + 1] = "illegal-symbol";
1347 #else
1348 for (i = 0; i <= max; ++i)
1349 symnam[i] = 0;
1350 for (i = ntokens - 1; i >= 2; --i)
1351 symnam[symbol_value[i]] = symbol_name[i];
1352 symnam[0] = "end-of-file";
1353 symnam[max + 1] = "illegal-symbol";
1354 #endif
1357 * bison's yytname[] array is roughly the same as byacc's yyname[] array.
1358 * The difference is that byacc does not predefine "$undefined".
1360 * If the grammar declares "%token-table", define symbol "yytname" so
1361 * an application such as ntpd can build.
1363 if (token_table)
1365 if (!rflag)
1367 output_line("#undef yytname");
1368 output_line("#define yytname yyname");
1371 else
1373 output_line("#if YYDEBUG");
1376 start_str_table("name");
1377 j = 80;
1378 for (i = 0; i <= max + 1; ++i)
1380 if ((s = symnam[i]) != 0)
1382 if (s[0] == '"')
1384 k = 7;
1385 while (*++s != '"')
1387 ++k;
1388 if (*s == '\\')
1390 k += 2;
1391 if (*++s == '\\')
1392 ++k;
1395 j += k;
1396 if (j > 80)
1398 output_newline();
1399 j = k;
1401 fprintf(output_file, "\"\\\"");
1402 s = symnam[i];
1403 while (*++s != '"')
1405 if (*s == '\\')
1407 fprintf(output_file, "\\\\");
1408 if (*++s == '\\')
1409 fprintf(output_file, "\\\\");
1410 else
1411 putc(*s, output_file);
1413 else
1414 putc(*s, output_file);
1416 fprintf(output_file, "\\\"\",");
1418 else if (s[0] == '\'')
1420 if (s[1] == '"')
1422 j += 7;
1423 if (j > 80)
1425 output_newline();
1426 j = 7;
1428 fprintf(output_file, "\"'\\\"'\",");
1430 else
1432 k = 5;
1433 while (*++s != '\'')
1435 ++k;
1436 if (*s == '\\')
1438 k += 2;
1439 if (*++s == '\\')
1440 ++k;
1443 j += k;
1444 if (j > 80)
1446 output_newline();
1447 j = k;
1449 fprintf(output_file, "\"'");
1450 s = symnam[i];
1451 while (*++s != '\'')
1453 if (*s == '\\')
1455 fprintf(output_file, "\\\\");
1456 if (*++s == '\\')
1457 fprintf(output_file, "\\\\");
1458 else
1459 putc(*s, output_file);
1461 else
1462 putc(*s, output_file);
1464 fprintf(output_file, "'\",");
1467 else
1469 k = (int)strlen(s) + 3;
1470 j += k;
1471 if (j > 80)
1473 output_newline();
1474 j = k;
1476 putc('"', output_file);
1479 putc(*s, output_file);
1481 while (*++s);
1482 fprintf(output_file, "\",");
1485 else
1487 j += 2;
1488 if (j > 80)
1490 output_newline();
1491 j = 2;
1493 fprintf(output_file, "0,");
1496 end_table();
1497 FREE(symnam);
1499 if (token_table)
1500 output_line("#if YYDEBUG");
1501 start_str_table("rule");
1502 for (i = 2; i < nrules; ++i)
1504 fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
1505 for (j = rrhs[i]; ritem[j] > 0; ++j)
1507 s = symbol_name[ritem[j]];
1508 if (s[0] == '"')
1510 fprintf(output_file, " \\\"");
1511 while (*++s != '"')
1513 if (*s == '\\')
1515 if (s[1] == '\\')
1516 fprintf(output_file, "\\\\\\\\");
1517 else
1518 fprintf(output_file, "\\\\%c", s[1]);
1519 ++s;
1521 else
1522 putc(*s, output_file);
1524 fprintf(output_file, "\\\"");
1526 else if (s[0] == '\'')
1528 if (s[1] == '"')
1529 fprintf(output_file, " '\\\"'");
1530 else if (s[1] == '\\')
1532 if (s[2] == '\\')
1533 fprintf(output_file, " '\\\\\\\\");
1534 else
1535 fprintf(output_file, " '\\\\%c", s[2]);
1536 s += 2;
1537 while (*++s != '\'')
1538 putc(*s, output_file);
1539 putc('\'', output_file);
1541 else
1542 fprintf(output_file, " '%c'", s[1]);
1544 else
1545 fprintf(output_file, " %s", s);
1547 fprintf(output_file, "\",");
1548 output_newline();
1551 end_table();
1552 output_line("#endif");
1555 #if defined(YYBTYACC)
1556 static void
1557 output_backtracking_parser(FILE * fp)
1559 putl_code(fp, "#undef YYBTYACC\n");
1560 #if defined(YYBTYACC)
1561 if (backtrack)
1563 putl_code(fp, "#define YYBTYACC 1\n");
1564 putl_code(fp,
1565 "#define YYDEBUGSTR (yytrial ? YYPREFIX \"debug(trial)\" : YYPREFIX \"debug\")\n");
1567 else
1568 #endif
1570 putl_code(fp, "#define YYBTYACC 0\n");
1571 putl_code(fp, "#define YYDEBUGSTR YYPREFIX \"debug\"\n");
1574 #endif
1576 static void
1577 output_pure_parser(FILE * fp)
1579 putc_code(fp, '\n');
1581 if (fp == code_file)
1582 ++outline;
1583 fprintf(fp, "#define YYPURE %d\n", pure_parser);
1584 putc_code(fp, '\n');
1587 #if defined(YY_NO_LEAKS)
1588 static void
1589 output_no_leaks(FILE * fp)
1591 putc_code(fp, '\n');
1593 if (fp == code_file)
1594 ++outline;
1595 fputs("#define YY_NO_LEAKS 1\n", fp);
1596 putc_code(fp, '\n');
1598 #endif
1600 static void
1601 output_trailing_text(void)
1603 int c, last;
1604 FILE *in;
1606 if (line == 0)
1607 return;
1609 in = input_file;
1610 c = *cptr;
1611 if (c == '\n')
1613 ++lineno;
1614 if ((c = getc(in)) == EOF)
1615 return;
1616 write_input_lineno();
1617 putc_code(code_file, c);
1618 last = c;
1620 else
1622 write_input_lineno();
1625 putc_code(code_file, c);
1627 while ((c = *++cptr) != '\n');
1628 putc_code(code_file, c);
1629 last = '\n';
1632 while ((c = getc(in)) != EOF)
1634 putc_code(code_file, c);
1635 last = c;
1638 if (last != '\n')
1640 putc_code(code_file, '\n');
1642 write_code_lineno(code_file);
1645 static void
1646 output_semantic_actions(void)
1648 int c, last;
1650 rewind(action_file);
1651 if ((c = getc(action_file)) == EOF)
1652 return;
1654 last = c;
1655 putc_code(code_file, c);
1656 while ((c = getc(action_file)) != EOF)
1658 putc_code(code_file, c);
1659 last = c;
1662 if (last != '\n')
1664 putc_code(code_file, '\n');
1667 write_code_lineno(code_file);
1670 static void
1671 output_parse_decl(FILE * fp)
1673 putc_code(fp, '\n');
1674 putl_code(fp, "/* compatibility with bison */\n");
1675 putl_code(fp, "#ifdef YYPARSE_PARAM\n");
1676 putl_code(fp, "/* compatibility with FreeBSD */\n");
1677 putl_code(fp, "# ifdef YYPARSE_PARAM_TYPE\n");
1678 putl_code(fp,
1679 "# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)\n");
1680 putl_code(fp, "# else\n");
1681 putl_code(fp, "# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)\n");
1682 putl_code(fp, "# endif\n");
1683 putl_code(fp, "#else\n");
1685 puts_code(fp, "# define YYPARSE_DECL() yyparse(");
1686 puts_param_types(fp, parse_param, 0);
1687 putl_code(fp, ")\n");
1689 putl_code(fp, "#endif\n");
1692 static void
1693 output_lex_decl(FILE * fp)
1695 putc_code(fp, '\n');
1696 putl_code(fp, "/* Parameters sent to lex. */\n");
1697 putl_code(fp, "#ifdef YYLEX_PARAM\n");
1698 if (pure_parser)
1700 putl_code(fp, "# ifdef YYLEX_PARAM_TYPE\n");
1701 #if defined(YYBTYACC)
1702 if (locations)
1704 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1705 " YYLTYPE *yylloc,"
1706 " YYLEX_PARAM_TYPE YYLEX_PARAM)\n");
1708 else
1709 #endif
1711 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1712 " YYLEX_PARAM_TYPE YYLEX_PARAM)\n");
1714 putl_code(fp, "# else\n");
1715 #if defined(YYBTYACC)
1716 if (locations)
1718 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1719 " YYLTYPE *yylloc,"
1720 " void * YYLEX_PARAM)\n");
1722 else
1723 #endif
1725 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval,"
1726 " void * YYLEX_PARAM)\n");
1728 putl_code(fp, "# endif\n");
1729 #if defined(YYBTYACC)
1730 if (locations)
1731 putl_code(fp,
1732 "# define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)\n");
1733 else
1734 #endif
1735 putl_code(fp, "# define YYLEX yylex(&yylval, YYLEX_PARAM)\n");
1737 else
1739 putl_code(fp, "# define YYLEX_DECL() yylex(void *YYLEX_PARAM)\n");
1740 putl_code(fp, "# define YYLEX yylex(YYLEX_PARAM)\n");
1742 putl_code(fp, "#else\n");
1743 if (pure_parser && lex_param)
1745 #if defined(YYBTYACC)
1746 if (locations)
1747 puts_code(fp,
1748 "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc, ");
1749 else
1750 #endif
1751 puts_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, ");
1752 puts_param_types(fp, lex_param, 0);
1753 putl_code(fp, ")\n");
1755 #if defined(YYBTYACC)
1756 if (locations)
1757 puts_code(fp, "# define YYLEX yylex(&yylval, &yylloc, ");
1758 else
1759 #endif
1760 puts_code(fp, "# define YYLEX yylex(&yylval, ");
1761 puts_param_names(fp, lex_param, 0);
1762 putl_code(fp, ")\n");
1764 else if (pure_parser)
1766 #if defined(YYBTYACC)
1767 if (locations)
1769 putl_code(fp,
1770 "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc)\n");
1771 putl_code(fp, "# define YYLEX yylex(&yylval, &yylloc)\n");
1773 else
1774 #endif
1776 putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval)\n");
1777 putl_code(fp, "# define YYLEX yylex(&yylval)\n");
1780 else if (lex_param)
1782 puts_code(fp, "# define YYLEX_DECL() yylex(");
1783 puts_param_types(fp, lex_param, 0);
1784 putl_code(fp, ")\n");
1786 puts_code(fp, "# define YYLEX yylex(");
1787 puts_param_names(fp, lex_param, 0);
1788 putl_code(fp, ")\n");
1790 else
1792 putl_code(fp, "# define YYLEX_DECL() yylex(void)\n");
1793 putl_code(fp, "# define YYLEX yylex()\n");
1795 putl_code(fp, "#endif\n");
1798 static void
1799 output_error_decl(FILE * fp)
1801 putc_code(fp, '\n');
1802 putl_code(fp, "/* Parameters sent to yyerror. */\n");
1803 putl_code(fp, "#ifndef YYERROR_DECL\n");
1804 puts_code(fp, "#define YYERROR_DECL() yyerror(");
1805 #if defined(YYBTYACC)
1806 if (locations)
1807 puts_code(fp, "YYLTYPE *loc, ");
1808 #endif
1809 puts_param_types(fp, parse_param, 1);
1810 putl_code(fp, "const char *s)\n");
1811 putl_code(fp, "#endif\n");
1813 putl_code(fp, "#ifndef YYERROR_CALL\n");
1815 puts_code(fp, "#define YYERROR_CALL(msg) yyerror(");
1816 #if defined(YYBTYACC)
1817 if (locations)
1818 puts_code(fp, "&yylloc, ");
1819 #endif
1820 puts_param_names(fp, parse_param, 1);
1821 putl_code(fp, "msg)\n");
1823 putl_code(fp, "#endif\n");
1826 #if defined(YYBTYACC)
1827 static void
1828 output_yydestruct_decl(FILE * fp)
1830 putc_code(fp, '\n');
1831 putl_code(fp, "#ifndef YYDESTRUCT_DECL\n");
1833 puts_code(fp,
1834 "#define YYDESTRUCT_DECL() "
1835 "yydestruct(const char *msg, int psymb, YYSTYPE *val");
1836 #if defined(YYBTYACC)
1837 if (locations)
1838 puts_code(fp, ", YYLTYPE *loc");
1839 #endif
1840 if (parse_param)
1842 puts_code(fp, ", ");
1843 puts_param_types(fp, parse_param, 0);
1845 putl_code(fp, ")\n");
1847 putl_code(fp, "#endif\n");
1849 putl_code(fp, "#ifndef YYDESTRUCT_CALL\n");
1851 puts_code(fp, "#define YYDESTRUCT_CALL(msg, psymb, val");
1852 #if defined(YYBTYACC)
1853 if (locations)
1854 puts_code(fp, ", loc");
1855 #endif
1856 puts_code(fp, ") yydestruct(msg, psymb, val");
1857 #if defined(YYBTYACC)
1858 if (locations)
1859 puts_code(fp, ", loc");
1860 #endif
1861 if (parse_param)
1863 puts_code(fp, ", ");
1864 puts_param_names(fp, parse_param, 0);
1866 putl_code(fp, ")\n");
1868 putl_code(fp, "#endif\n");
1871 static void
1872 output_initial_action(void)
1874 if (initial_action)
1875 fprintf(code_file, "%s\n", initial_action);
1878 static void
1879 output_yydestruct_impl(void)
1881 int i;
1882 char *s, *destructor_code;
1884 putc_code(code_file, '\n');
1885 putl_code(code_file, "/* Release memory associated with symbol. */\n");
1886 putl_code(code_file, "#if ! defined YYDESTRUCT_IS_DECLARED\n");
1887 putl_code(code_file, "static void\n");
1888 putl_code(code_file, "YYDESTRUCT_DECL()\n");
1889 putl_code(code_file, "{\n");
1890 putl_code(code_file, " switch (psymb)\n");
1891 putl_code(code_file, " {\n");
1892 for (i = 2; i < nsyms; ++i)
1894 if ((destructor_code = symbol_destructor[i]) != NULL)
1896 ++outline;
1897 fprintf(code_file, "\tcase %d:\n", symbol_pval[i]);
1898 /* comprehend the number of lines in the destructor code */
1899 for (s = destructor_code; (s = strchr(s, '\n')) != NULL; s++)
1900 ++outline;
1901 puts_code(code_file, destructor_code);
1902 putc_code(code_file, '\n');
1903 putl_code(code_file, "\tbreak;\n");
1904 write_code_lineno(code_file);
1905 FREE(destructor_code);
1908 putl_code(code_file, " }\n");
1909 putl_code(code_file, "}\n");
1910 putl_code(code_file, "#define YYDESTRUCT_IS_DECLARED 1\n");
1911 putl_code(code_file, "#endif\n");
1913 DO_FREE(symbol_destructor);
1915 #endif
1917 static void
1918 free_itemsets(void)
1920 core *cp, *next;
1922 FREE(state_table);
1923 for (cp = first_state; cp; cp = next)
1925 next = cp->next;
1926 FREE(cp);
1930 static void
1931 free_shifts(void)
1933 shifts *sp, *next;
1935 FREE(shift_table);
1936 for (sp = first_shift; sp; sp = next)
1938 next = sp->next;
1939 FREE(sp);
1943 static void
1944 free_reductions(void)
1946 reductions *rp, *next;
1948 FREE(reduction_table);
1949 for (rp = first_reduction; rp; rp = next)
1951 next = rp->next;
1952 FREE(rp);
1956 static void
1957 output_externs(FILE * fp, const char *const section[])
1959 int i;
1960 const char *s;
1962 for (i = 0; (s = section[i]) != 0; ++i)
1964 /* prefix non-blank lines that don't start with
1965 C pre-processor directives with 'extern ' */
1966 if (*s && (*s != '#'))
1967 fputs("extern\t", fp);
1968 if (fp == code_file)
1969 ++outline;
1970 fprintf(fp, "%s\n", s);
1974 void
1975 output(void)
1977 FILE *fp;
1979 free_itemsets();
1980 free_shifts();
1981 free_reductions();
1983 #if defined(YYBTYACC)
1984 output_backtracking_parser(output_file);
1985 if (rflag)
1986 output_backtracking_parser(code_file);
1987 #endif
1989 if (iflag)
1991 write_code_lineno(code_file);
1992 ++outline;
1993 fprintf(code_file, "#include \"%s\"\n", externs_file_name);
1994 fp = externs_file;
1996 else
1997 fp = code_file;
1999 output_prefix(fp);
2000 output_pure_parser(fp);
2001 #if defined(YY_NO_LEAKS)
2002 output_no_leaks(fp);
2003 #endif
2004 output_stored_text(fp);
2005 output_stype(fp);
2006 #if defined(YYBTYACC)
2007 if (locations)
2008 output_ltype(fp);
2009 #endif
2010 output_parse_decl(fp);
2011 output_lex_decl(fp);
2012 output_error_decl(fp);
2013 #if defined(YYBTYACC)
2014 if (destructor)
2015 output_yydestruct_decl(fp);
2016 #endif
2017 if (iflag || !rflag)
2019 write_section(fp, xdecls);
2022 if (iflag)
2024 output_externs(externs_file, global_vars);
2025 if (!pure_parser)
2026 output_externs(externs_file, impure_vars);
2029 if (iflag)
2031 if (dflag)
2033 ++outline;
2034 fprintf(code_file, "#include \"%s\"\n", defines_file_name);
2036 else
2037 output_defines(externs_file);
2039 else
2041 putc_code(code_file, '\n');
2042 output_defines(code_file);
2045 if (dflag)
2047 start_defines_file();
2048 output_defines(defines_file);
2049 end_defines_file();
2052 output_rule_data();
2053 output_yydefred();
2054 #if defined(YYBTYACC)
2055 output_accessing_symbols();
2056 #endif
2057 output_actions();
2058 free_parser();
2059 output_debug();
2060 if (rflag)
2062 write_section(code_file, xdecls);
2063 output_YYINT_typedef(code_file);
2064 write_section(code_file, tables);
2066 write_section(code_file, global_vars);
2067 if (!pure_parser)
2069 write_section(code_file, impure_vars);
2071 write_section(code_file, hdr_defs);
2072 if (!pure_parser)
2074 write_section(code_file, hdr_vars);
2076 output_trailing_text();
2077 #if defined(YYBTYACC)
2078 if (destructor)
2079 output_yydestruct_impl();
2080 #endif
2081 write_section(code_file, body_1);
2082 if (pure_parser)
2084 write_section(code_file, body_vars);
2086 write_section(code_file, body_2);
2087 if (pure_parser)
2089 write_section(code_file, init_vars);
2091 #if defined(YYBTYACC)
2092 if (initial_action)
2093 output_initial_action();
2094 #endif
2095 write_section(code_file, body_3);
2096 output_semantic_actions();
2097 write_section(code_file, trailer);
2100 #ifdef NO_LEAKS
2101 void
2102 output_leaks(void)
2104 DO_FREE(tally);
2105 DO_FREE(width);
2106 DO_FREE(order);
2108 #endif