Add root nuget.config to ensure CFS protection
[mono-project.git] / mcs / jay / output.c
blob859415a69f4b1a7b644c545f972066e732c6861d
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Robert Paul Corbett.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
37 #ifndef lint
38 static char sccsid[] = "@(#)output.c 5.7 (Berkeley) 5/24/93";
39 #endif /* not lint */
41 #include "defs.h"
42 #include <string.h>
44 static int nvectors;
45 static int nentries;
46 static short **froms;
47 static short **tos;
48 static short *tally;
49 static short *width;
50 static short *state_count;
51 static short *order;
52 static short *base;
53 static short *pos;
54 static int maxtable;
55 static short *table;
56 static short *check;
57 static int lowzero;
58 static int high;
59 extern int csharp;
61 static void
62 free_itemsets (void);
64 static void
65 free_reductions (void);
67 static void
68 free_shifts (void);
70 static void
71 goto_actions (void);
73 static void
74 output_actions (void);
76 static void
77 output_base (void);
79 static void
80 output_check (void);
82 static void
83 output_debug (void);
85 static void
86 output_defines (const char *prefix);
88 static void
89 output_rule_data (void);
91 static void
92 output_semantic_actions (void);
94 static void
95 output_stored_text (FILE *file, const char *name);
97 static void
98 output_table (void);
100 static void
101 output_trailing_text (void);
103 static void
104 save_column (int symbol, int default_state);
106 static void
107 sort_actions (void);
109 static void
110 output_yydefred (void);
112 static int
113 default_goto (int symbol);
115 static int
116 matching_vector (int vector);
118 static int
119 pack_vector (int vector);
121 static void
122 token_actions (void);
124 static void
125 pack_table (void);
127 void
128 output (void)
130 int lno = 0;
131 char buf [128];
133 free_itemsets();
134 free_shifts();
135 free_reductions();
137 while (fgets(buf, sizeof buf, stdin) != NULL) {
138 char * cp;
139 ++ lno;
140 if (buf[strlen(buf)-1] != '\n')
141 fprintf(stderr, "jay: line %d is too long\n", lno), done(1);
142 switch (buf[0]) {
143 case '#': continue;
144 case 't': if (!tflag) fputs("//t", output_file);
145 case '.': break;
146 default:
147 cp = strtok(buf, " \t\r\n");
148 if (cp) {
149 if (strcmp(cp, "actions") == 0) output_semantic_actions();
150 else if (strcmp(cp, "debug") == 0) output_debug();
151 else if (strcmp(cp, "epilog") == 0) output_trailing_text();
152 else if (strcmp(cp, "prolog") == 0)
153 output_stored_text(prolog_file, prolog_file_name);
154 else if (strcmp(cp, "local") == 0)
155 output_stored_text(local_file, local_file_name);
156 else if (strcmp(cp, "tables") == 0)
157 output_rule_data(), output_yydefred(), output_actions();
158 else if (strcmp(cp, "tokens") == 0)
159 output_defines(strtok(NULL, "\r\n"));
160 else
161 fprintf(stderr, "jay: unknown call (%s) in line %d\n", cp, lno);
163 continue;
165 fputs(buf+1, output_file), ++ outline;
167 free_parser();
170 static void
171 output_rule_data (void)
173 register int i;
174 register int j;
176 fprintf(output_file, "/*\n All more than 3 lines long rules are wrapped into a method\n*/\n");
178 for (i = 0; i < nmethods; ++i)
180 fprintf(output_file, "%s", methods[i]);
181 FREE(methods[i]);
182 fprintf(output_file, "\n\n");
184 FREE(methods);
186 fprintf(output_file, default_line_format, ++outline + 1);
188 fprintf(output_file, " %s static %s short [] yyLhs = {%16d,",
189 csharp ? "" : " protected",
190 csharp ? "readonly" : "final",
191 symbol_value[start_symbol]);
193 j = 10;
194 for (i = 3; i < nrules; i++)
196 if (j >= 10)
198 ++outline;
199 putc('\n', output_file);
200 j = 1;
202 else
203 ++j;
205 fprintf(output_file, "%5d,", symbol_value[rlhs[i]]);
207 outline += 2;
208 fprintf(output_file, "\n };\n");
210 fprintf(output_file, " %s static %s short [] yyLen = {%12d,",
211 csharp ? "" : "protected",
212 csharp ? "readonly" : "final",
215 j = 10;
216 for (i = 3; i < nrules; i++)
218 if (j >= 10)
220 ++outline;
221 putc('\n', output_file);
222 j = 1;
224 else
225 j++;
227 fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1);
229 outline += 2;
230 fprintf(output_file, "\n };\n");
233 static void
234 output_yydefred (void)
236 register int i, j;
238 fprintf(output_file, " %s static %s short [] yyDefRed = {%13d,",
239 csharp ? "" : "protected",
240 csharp ? "readonly" : "final",
241 (defred[0] ? defred[0] - 2 : 0));
243 j = 10;
244 for (i = 1; i < nstates; i++)
246 if (j < 10)
247 ++j;
248 else
250 ++outline;
251 putc('\n', output_file);
252 j = 1;
255 fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0));
258 outline += 2;
259 fprintf(output_file, "\n };\n");
262 static void
263 output_actions (void)
265 nvectors = 2*nstates + nvars;
267 froms = NEW2(nvectors, short *);
268 tos = NEW2(nvectors, short *);
269 tally = NEW2(nvectors, short);
270 width = NEW2(nvectors, short);
272 token_actions();
273 FREE(lookaheads);
274 FREE(LA);
275 FREE(LAruleno);
276 FREE(accessing_symbol);
278 goto_actions();
279 FREE(goto_map + ntokens);
280 FREE(from_state);
281 FREE(to_state);
283 sort_actions();
284 pack_table();
285 output_base();
286 output_table();
287 output_check();
290 static void
291 token_actions (void)
293 register int i, j;
294 register int shiftcount, reducecount;
295 register int max, min;
296 register short *actionrow, *r, *s;
297 register action *p;
299 actionrow = NEW2(2*ntokens, short);
300 for (i = 0; i < nstates; ++i)
302 if (parser[i])
304 for (j = 0; j < 2*ntokens; ++j)
305 actionrow[j] = 0;
307 shiftcount = 0;
308 reducecount = 0;
309 for (p = parser[i]; p; p = p->next)
311 if (p->suppressed == 0)
313 if (p->action_code == SHIFT)
315 ++shiftcount;
316 actionrow[p->symbol] = p->number;
318 else if (p->action_code == REDUCE && p->number != defred[i])
320 ++reducecount;
321 actionrow[p->symbol + ntokens] = p->number;
326 tally[i] = shiftcount;
327 tally[nstates+i] = reducecount;
328 width[i] = 0;
329 width[nstates+i] = 0;
330 if (shiftcount > 0)
332 froms[i] = r = NEW2(shiftcount, short);
333 tos[i] = s = NEW2(shiftcount, short);
334 min = MAXSHORT;
335 max = 0;
336 for (j = 0; j < ntokens; ++j)
338 if (actionrow[j])
340 if (min > symbol_value[j])
341 min = symbol_value[j];
342 if (max < symbol_value[j])
343 max = symbol_value[j];
344 *r++ = symbol_value[j];
345 *s++ = actionrow[j];
348 width[i] = max - min + 1;
350 if (reducecount > 0)
352 froms[nstates+i] = r = NEW2(reducecount, short);
353 tos[nstates+i] = s = NEW2(reducecount, short);
354 min = MAXSHORT;
355 max = 0;
356 for (j = 0; j < ntokens; ++j)
358 if (actionrow[ntokens+j])
360 if (min > symbol_value[j])
361 min = symbol_value[j];
362 if (max < symbol_value[j])
363 max = symbol_value[j];
364 *r++ = symbol_value[j];
365 *s++ = actionrow[ntokens+j] - 2;
368 width[nstates+i] = max - min + 1;
372 FREE(actionrow);
375 static void
376 goto_actions (void)
378 register int i, j, k;
380 state_count = NEW2(nstates, short);
382 k = default_goto(start_symbol + 1);
383 fprintf(output_file, " protected static %s short [] yyDgoto = {%14d,", csharp ? "readonly" : "final", k);
384 save_column(start_symbol + 1, k);
386 j = 10;
387 for (i = start_symbol + 2; i < nsyms; i++)
389 if (j >= 10)
391 ++outline;
392 putc('\n', output_file);
393 j = 1;
395 else
396 ++j;
398 k = default_goto(i);
399 fprintf(output_file, "%5d,", k);
400 save_column(i, k);
403 outline += 2;
404 fprintf(output_file, "\n };\n");
405 FREE(state_count);
408 static int
409 default_goto (int symbol)
411 register int i;
412 register int m;
413 register int n;
414 register int default_state;
415 register int max;
417 m = goto_map[symbol];
418 n = goto_map[symbol + 1];
420 if (m == n) return (0);
422 for (i = 0; i < nstates; i++)
423 state_count[i] = 0;
425 for (i = m; i < n; i++)
426 state_count[to_state[i]]++;
428 max = 0;
429 default_state = 0;
430 for (i = 0; i < nstates; i++)
432 if (state_count[i] > max)
434 max = state_count[i];
435 default_state = i;
439 return (default_state);
442 static void
443 save_column (int symbol, int default_state)
445 register int i;
446 register int m;
447 register int n;
448 register short *sp;
449 register short *sp1;
450 register short *sp2;
451 register int count;
452 register int symno;
454 m = goto_map[symbol];
455 n = goto_map[symbol + 1];
457 count = 0;
458 for (i = m; i < n; i++)
460 if (to_state[i] != default_state)
461 ++count;
463 if (count == 0) return;
465 symno = symbol_value[symbol] + 2*nstates;
467 froms[symno] = sp1 = sp = NEW2(count, short);
468 tos[symno] = sp2 = NEW2(count, short);
470 for (i = m; i < n; i++)
472 if (to_state[i] != default_state)
474 *sp1++ = from_state[i];
475 *sp2++ = to_state[i];
479 tally[symno] = count;
480 width[symno] = sp1[-1] - sp[0] + 1;
483 static void
484 sort_actions (void)
486 register int i;
487 register int j;
488 register int k;
489 register int t;
490 register int w;
492 order = NEW2(nvectors, short);
493 nentries = 0;
495 for (i = 0; i < nvectors; i++)
497 if (tally[i] > 0)
499 t = tally[i];
500 w = width[i];
501 j = nentries - 1;
503 while (j >= 0 && (width[order[j]] < w))
504 j--;
506 while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
507 j--;
509 for (k = nentries - 1; k > j; k--)
510 order[k + 1] = order[k];
512 order[j + 1] = i;
513 nentries++;
518 static void
519 pack_table (void)
521 register int i;
522 register int place;
523 register int state;
525 base = NEW2(nvectors, short);
526 pos = NEW2(nentries, short);
528 maxtable = 1000;
529 table = NEW2(maxtable, short);
530 check = NEW2(maxtable, short);
532 lowzero = 0;
533 high = 0;
535 for (i = 0; i < maxtable; i++)
536 check[i] = -1;
538 for (i = 0; i < nentries; i++)
540 state = matching_vector(i);
542 if (state < 0)
543 place = pack_vector(i);
544 else
545 place = base[state];
547 pos[i] = place;
548 base[order[i]] = place;
551 for (i = 0; i < nvectors; i++)
553 if (froms[i])
554 FREE(froms[i]);
555 if (tos[i])
556 FREE(tos[i]);
559 FREE(froms);
560 FREE(tos);
561 FREE(pos);
565 /* The function matching_vector determines if the vector specified by */
566 /* the input parameter matches a previously considered vector. The */
567 /* test at the start of the function checks if the vector represents */
568 /* a row of shifts over terminal symbols or a row of reductions, or a */
569 /* column of shifts over a nonterminal symbol. Berkeley Yacc does not */
570 /* check if a column of shifts over a nonterminal symbols matches a */
571 /* previously considered vector. Because of the nature of LR parsing */
572 /* tables, no two columns can match. Therefore, the only possible */
573 /* match would be between a row and a column. Such matches are */
574 /* unlikely. Therefore, to save time, no attempt is made to see if a */
575 /* column matches a previously considered vector. */
576 /* */
577 /* Matching_vector is poorly designed. The test could easily be made */
578 /* faster. Also, it depends on the vectors being in a specific */
579 /* order. */
581 static int
582 matching_vector (int vector)
584 register int i;
585 register int j;
586 register int k;
587 register int t;
588 register int w;
589 register int match;
590 register int prev;
592 i = order[vector];
593 if (i >= 2*nstates)
594 return (-1);
596 t = tally[i];
597 w = width[i];
599 for (prev = vector - 1; prev >= 0; prev--)
601 j = order[prev];
602 if (width[j] != w || tally[j] != t)
603 return (-1);
605 match = 1;
606 for (k = 0; match && k < t; k++)
608 if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
609 match = 0;
612 if (match)
613 return (j);
616 return (-1);
619 static int
620 pack_vector (int vector)
622 register int i, j, k, l;
623 register int t;
624 register int loc;
625 register int ok;
626 register short *from;
627 register short *to;
628 int newmax;
630 i = order[vector];
631 t = tally[i];
632 assert(t);
634 from = froms[i];
635 to = tos[i];
637 j = lowzero - from[0];
638 for (k = 1; k < t; ++k)
639 if (lowzero - from[k] > j)
640 j = lowzero - from[k];
641 for (;; ++j)
643 if (j == 0)
644 continue;
645 ok = 1;
646 for (k = 0; ok && k < t; k++)
648 loc = j + from[k];
649 if (loc >= maxtable)
651 if (loc >= MAXTABLE)
652 fatal("maximum table size exceeded");
654 newmax = maxtable;
655 do { newmax += 200; } while (newmax <= loc);
656 table = (short *) REALLOC(table, newmax*sizeof(short));
657 if (table == 0) no_space();
658 check = (short *) REALLOC(check, newmax*sizeof(short));
659 if (check == 0) no_space();
660 for (l = maxtable; l < newmax; ++l)
662 table[l] = 0;
663 check[l] = -1;
665 maxtable = newmax;
668 if (check[loc] != -1)
669 ok = 0;
671 for (k = 0; ok && k < vector; k++)
673 if (pos[k] == j)
674 ok = 0;
676 if (ok)
678 for (k = 0; k < t; k++)
680 loc = j + from[k];
681 table[loc] = to[k];
682 check[loc] = from[k];
683 if (loc > high) high = loc;
686 while (check[lowzero] != -1)
687 ++lowzero;
689 return (j);
694 static void
695 output_base (void)
697 register int i, j;
699 fprintf(output_file, " protected static %s short [] yySindex = {%13d,", csharp? "readonly":"final", base[0]);
701 j = 10;
702 for (i = 1; i < nstates; i++)
704 if (j >= 10)
706 ++outline;
707 putc('\n', output_file);
708 j = 1;
710 else
711 ++j;
713 fprintf(output_file, "%5d,", base[i]);
716 outline += 2;
717 fprintf(output_file, "\n };\n protected static %s short [] yyRindex = {%13d,",
718 csharp ? "readonly" : "final",
719 base[nstates]);
721 j = 10;
722 for (i = nstates + 1; i < 2*nstates; i++)
724 if (j >= 10)
726 ++outline;
727 putc('\n', output_file);
728 j = 1;
730 else
731 ++j;
733 fprintf(output_file, "%5d,", base[i]);
736 outline += 2;
737 fprintf(output_file, "\n };\n protected static %s short [] yyGindex = {%13d,",
738 csharp ? "readonly" : "final",
739 base[2*nstates]);
741 j = 10;
742 for (i = 2*nstates + 1; i < nvectors - 1; i++)
744 if (j >= 10)
746 ++outline;
747 putc('\n', output_file);
748 j = 1;
750 else
751 ++j;
753 fprintf(output_file, "%5d,", base[i]);
756 outline += 2;
757 fprintf(output_file, "\n };\n");
758 FREE(base);
761 static void
762 output_table (void)
764 register int i;
765 register int j;
767 fprintf(output_file, " protected static %s short [] yyTable = {%14d,", csharp ? "readonly" : "final", table[0]);
769 j = 10;
770 for (i = 1; i <= high; i++)
772 if (j >= 10)
774 ++outline;
775 putc('\n', output_file);
776 j = 1;
778 else
779 ++j;
781 fprintf(output_file, "%5d,", table[i]);
784 outline += 2;
785 fprintf(output_file, "\n };\n");
786 FREE(table);
789 static void
790 output_check (void)
792 register int i;
793 register int j;
795 fprintf(output_file, " protected static %s short [] yyCheck = {%14d,",
796 csharp ? "readonly" : "final",
797 check[0]);
799 j = 10;
800 for (i = 1; i <= high; i++)
802 if (j >= 10)
804 ++outline;
805 putc('\n', output_file);
806 j = 1;
808 else
809 ++j;
811 fprintf(output_file, "%5d,", check[i]);
814 outline += 2;
815 fprintf(output_file, "\n };\n");
816 FREE(check);
819 static int
820 is_C_identifier (const char *name)
822 const char *s;
823 register int c;
825 s = name;
826 c = *s;
827 if (c == '"')
829 c = *++s;
830 if (!isalpha(c) && c != '_' && c != '$')
831 return (0);
832 while ((c = *++s) != '"')
834 if (!isalnum(c) && c != '_' && c != '$')
835 return (0);
837 return (1);
840 if (!isalpha(c) && c != '_' && c != '$')
841 return (0);
842 while ((c = *++s))
844 if (!isalnum(c) && c != '_' && c != '$')
845 return (0);
847 return (1);
850 static void
851 output_defines (const char *prefix)
853 register int c, i;
854 const char *s;
856 for (i = 2; i < ntokens; ++i)
858 s = symbol_name[i];
859 if (is_C_identifier(s))
861 if (prefix)
862 fprintf(output_file, " %s ", prefix);
863 c = *s;
864 if (c == '"')
866 while ((c = *++s) != '"')
868 putc(c, output_file);
871 else
875 putc(c, output_file);
877 while ((c = *++s));
879 ++outline;
880 fprintf(output_file, " = %d%s\n", symbol_value[i], csharp ? ";" : ";");
884 ++outline;
885 fprintf(output_file, " %s yyErrorCode = %d%s\n", prefix ? prefix : "", symbol_value[1], csharp ? ";" : ";");
888 static void
889 output_stored_text (FILE *file, const char *name)
891 register int c;
892 register FILE *in;
894 fflush(file);
895 in = fopen(name, "r");
896 if (in == NULL)
897 open_error(name);
898 if ((c = getc(in)) != EOF) {
899 if (c == '\n')
900 ++outline;
901 putc(c, output_file);
902 while ((c = getc(in)) != EOF)
904 if (c == '\n')
905 ++outline;
906 putc(c, output_file);
908 fprintf(output_file, default_line_format, ++outline + 1);
910 fclose(in);
913 static void
914 output_debug (void)
916 register int i, j, k, max;
917 char **symnam, *s;
918 const char * prefix = tflag ? "" : "//t";
920 ++outline;
921 fprintf(output_file, " protected %s int yyFinal = %d;\n", csharp ? "const" : "static final", final_state);
923 ++outline;
924 fprintf(output_file, "%s // Put this array into a separate class so it is only initialized if debugging is actually used\n", prefix);
925 fprintf(output_file, "%s // Use MarshalByRefObject to disable inlining\n", prefix);
926 fprintf(output_file, "%s class YYRules %s {\n", prefix, csharp ? ": MarshalByRefObject" : "");
927 fprintf(output_file, "%s public static %s string [] yyRule = {\n", prefix, csharp ? "readonly" : "final");
928 for (i = 2; i < nrules; ++i)
930 fprintf(output_file, "%s \"%s :", prefix, symbol_name[rlhs[i]]);
931 for (j = rrhs[i]; ritem[j] > 0; ++j)
933 s = symbol_name[ritem[j]];
934 if (s[0] == '"')
936 fprintf(output_file, " \\\"");
937 while (*++s != '"')
939 if (*s == '\\')
941 if (s[1] == '\\')
942 fprintf(output_file, "\\\\\\\\");
943 else
944 fprintf(output_file, "\\\\%c", s[1]);
945 ++s;
947 else
948 putc(*s, output_file);
950 fprintf(output_file, "\\\"");
952 else if (s[0] == '\'')
954 if (s[1] == '"')
955 fprintf(output_file, " '\\\"'");
956 else if (s[1] == '\\')
958 if (s[2] == '\\')
959 fprintf(output_file, " '\\\\\\\\");
960 else
961 fprintf(output_file, " '\\\\%c", s[2]);
962 s += 2;
963 while (*++s != '\'')
964 putc(*s, output_file);
965 putc('\'', output_file);
967 else
968 fprintf(output_file, " '%c'", s[1]);
970 else
971 fprintf(output_file, " %s", s);
973 ++outline;
974 fprintf(output_file, "\",\n");
976 ++ outline;
977 fprintf(output_file, "%s };\n", prefix);
978 fprintf(output_file, "%s public static string getRule (int index) {\n", prefix);
979 fprintf(output_file, "%s return yyRule [index];\n", prefix);
980 fprintf(output_file, "%s }\n", prefix);
981 fprintf(output_file, "%s}\n", prefix);
983 max = 0;
984 for (i = 2; i < ntokens; ++i)
985 if (symbol_value[i] > max)
986 max = symbol_value[i];
988 /* need yyNames for yyExpecting() */
990 fprintf(output_file, " protected static %s string [] yyNames = {", csharp ? "readonly" : "final");
991 symnam = (char **) MALLOC((max+1)*sizeof(char *));
992 if (symnam == 0) no_space();
994 /* Note that it is not necessary to initialize the element */
995 /* symnam[max]. */
996 for (i = 0; i < max; ++i)
997 symnam[i] = 0;
998 for (i = ntokens - 1; i >= 2; --i)
999 symnam[symbol_value[i]] = symbol_name[i];
1000 symnam[0] = (char*)"end-of-file";
1002 j = 70; fputs(" ", output_file);
1003 for (i = 0; i <= max; ++i)
1005 if ((s = symnam[i]))
1007 if (s[0] == '"')
1009 k = 7;
1010 while (*++s != '"')
1012 ++k;
1013 if (*s == '\\')
1015 k += 2;
1016 if (*++s == '\\')
1017 ++k;
1020 j += k;
1021 if (j > 70)
1023 ++outline;
1024 fprintf(output_file, "\n ");
1025 j = k;
1027 fprintf(output_file, "\"\\\"");
1028 s = symnam[i];
1029 while (*++s != '"')
1031 if (*s == '\\')
1033 fprintf(output_file, "\\\\");
1034 if (*++s == '\\')
1035 fprintf(output_file, "\\\\");
1036 else
1037 putc(*s, output_file);
1039 else
1040 putc(*s, output_file);
1042 fprintf(output_file, "\\\"\",");
1044 else if (s[0] == '\'')
1046 if (s[1] == '"')
1048 j += 7;
1049 if (j > 70)
1051 ++outline;
1052 fprintf(output_file, "\n ");
1053 j = 7;
1055 fprintf(output_file, "\"'\\\"'\",");
1057 else
1059 k = 5;
1060 while (*++s != '\'')
1062 ++k;
1063 if (*s == '\\')
1065 k += 2;
1066 if (*++s == '\\')
1067 ++k;
1070 j += k;
1071 if (j > 70)
1073 ++outline;
1074 fprintf(output_file, "\n ");
1075 j = k;
1077 fprintf(output_file, "\"'");
1078 s = symnam[i];
1079 while (*++s != '\'')
1081 if (*s == '\\')
1083 fprintf(output_file, "\\\\");
1084 if (*++s == '\\')
1085 fprintf(output_file, "\\\\");
1086 else
1087 putc(*s, output_file);
1089 else
1090 putc(*s, output_file);
1092 fprintf(output_file, "'\",");
1095 else
1097 k = strlen(s) + 3;
1098 j += k;
1099 if (j > 70)
1101 ++outline;
1102 fprintf(output_file, "\n ");
1103 j = k;
1105 putc('"', output_file);
1106 do { putc(*s, output_file); } while (*++s);
1107 fprintf(output_file, "\",");
1110 else
1112 j += 5;
1113 if (j > 70)
1115 ++outline;
1116 fprintf(output_file, "\n ");
1117 j = 5;
1119 fprintf(output_file, "null,");
1122 outline += 2;
1123 fprintf(output_file, "\n };\n");
1124 FREE(symnam);
1127 static void
1128 output_trailing_text (void)
1130 register int c, last;
1131 register FILE *in;
1133 if (line == 0)
1134 return;
1136 in = input_file;
1137 c = *cptr;
1138 if (c == '\n')
1140 ++lineno;
1141 if ((c = getc(in)) == EOF)
1142 return;
1143 ++outline;
1144 fprintf(output_file, line_format, lineno, input_file_name);
1145 if (c == '\n')
1146 ++outline;
1147 putc(c, output_file);
1148 last = c;
1150 else
1152 ++outline;
1153 fprintf(output_file, line_format, lineno, input_file_name);
1154 do { putc(c, output_file); } while ((c = *++cptr) != '\n');
1155 ++outline;
1156 putc('\n', output_file);
1157 last = '\n';
1160 while ((c = getc(in)) != EOF)
1162 if (c == '\n')
1163 ++outline;
1164 putc(c, output_file);
1165 last = c;
1168 if (last != '\n')
1170 ++outline;
1171 putc('\n', output_file);
1173 fprintf(output_file, default_line_format, ++outline + 1);
1176 static void
1177 output_semantic_actions (void)
1179 register int c, last;
1181 fclose(action_file);
1182 action_file = fopen(action_file_name, "r");
1183 if (action_file == NULL)
1184 open_error(action_file_name);
1186 if ((c = getc(action_file)) == EOF)
1187 return;
1189 last = c;
1190 if (c == '\n')
1191 ++outline;
1192 putc(c, output_file);
1193 while ((c = getc(action_file)) != EOF)
1195 if (c == '\n')
1196 ++outline;
1197 putc(c, output_file);
1198 last = c;
1201 if (last != '\n')
1203 ++outline;
1204 putc('\n', output_file);
1207 fprintf(output_file, default_line_format, ++outline + 1);
1210 static void
1211 free_itemsets (void)
1213 register core *cp, *next;
1215 FREE(state_table);
1216 for (cp = first_state; cp; cp = next)
1218 next = cp->next;
1219 FREE(cp);
1223 static void
1224 free_shifts (void)
1226 register shifts *sp, *next;
1228 FREE(shift_table);
1229 for (sp = first_shift; sp; sp = next)
1231 next = sp->next;
1232 FREE(sp);
1236 static void
1237 free_reductions (void)
1239 register reductions *rp, *next;
1241 FREE(reduction_table);
1242 for (rp = first_reduction; rp; rp = next)
1244 next = rp->next;
1245 FREE(rp);