|
|
1.1 root 1: /*
2: * Copyright (c) 1989 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * Robert Paul Corbett.
7: *
8: * Redistribution and use in source and binary forms are permitted provided
9: * that: (1) source distributions retain this entire copyright notice and
10: * comment, and (2) distributions including binaries display the following
11: * acknowledgement: ``This product includes software developed by the
12: * University of California, Berkeley and its contributors'' in the
13: * documentation or other materials provided with the distribution and in
14: * all advertising materials mentioning features or use of this software.
15: * Neither the name of the University nor the names of its contributors may
16: * be used to endorse or promote products derived from this software without
17: * specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)output.c 5.5 (Berkeley) 6/1/90";
25: #endif /* not lint */
26:
27: #include "defs.h"
28:
29: static int nvectors;
30: static int nentries;
31: static short **froms;
32: static short **tos;
33: static short *tally;
34: static short *width;
35: static short *state_count;
36: static short *order;
37: static short *base;
38: static short *pos;
39: static int maxtable;
40: static short *table;
41: static short *check;
42: static int lowzero;
43: static int high;
44:
45:
46: output()
47: {
48: free_itemsets();
49: free_shifts();
50: free_reductions();
51: output_stored_text();
52: output_defines();
53: output_rule_data();
54: output_yydefred();
55: output_actions();
56: free_parser();
57: output_debug();
58: output_stype();
59: write_section(header);
60: output_trailing_text();
61: write_section(body);
62: output_semantic_actions();
63: write_section(trailer);
64: }
65:
66:
67: output_rule_data()
68: {
69: register int i;
70: register int j;
71:
72:
73: fprintf(output_file, "short yylhs[] = {%42d,",
74: symbol_value[start_symbol]);
75:
76: j = 10;
77: for (i = 3; i < nrules; i++)
78: {
79: if (j >= 10)
80: {
81: ++outline;
82: putc('\n', output_file);
83: j = 1;
84: }
85: else
86: ++j;
87:
88: fprintf(output_file, "%5d,", symbol_value[rlhs[i]]);
89: }
90: outline += 2;
91: fprintf(output_file, "\n};\n");
92:
93: fprintf(output_file, "short yylen[] = {%42d,", 2);
94:
95: j = 10;
96: for (i = 3; i < nrules; i++)
97: {
98: if (j >= 10)
99: {
100: ++outline;
101: putc('\n', output_file);
102: j = 1;
103: }
104: else
105: j++;
106:
107: fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1);
108: }
109: outline += 2;
110: fprintf(output_file, "\n};\n");
111: }
112:
113:
114: output_yydefred()
115: {
116: register int i, j;
117:
118: fprintf(output_file, "short yydefred[] = {%39d,",
119: (defred[0] ? defred[0] - 2 : 0));
120:
121: j = 10;
122: for (i = 1; i < nstates; i++)
123: {
124: if (j < 10)
125: ++j;
126: else
127: {
128: ++outline;
129: putc('\n', output_file);
130: j = 1;
131: }
132:
133: fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0));
134: }
135:
136: outline += 2;
137: fprintf(output_file, "\n};\n");
138: }
139:
140:
141: output_actions()
142: {
143: nvectors = 2*nstates + nvars;
144:
145: froms = NEW2(nvectors, short *);
146: tos = NEW2(nvectors, short *);
147: tally = NEW2(nvectors, short);
148: width = NEW2(nvectors, short);
149:
150: token_actions();
151: FREE(lookaheads);
152: FREE(LA);
153: FREE(LAruleno);
154: FREE(accessing_symbol);
155:
156: goto_actions();
157: FREE(goto_map + ntokens);
158: FREE(from_state);
159: FREE(to_state);
160:
161: sort_actions();
162: pack_table();
163: output_base();
164: output_table();
165: output_check();
166: }
167:
168:
169: token_actions()
170: {
171: register int i, j;
172: register int shiftcount, reducecount;
173: register int max, min;
174: register short *actionrow, *r, *s;
175: register action *p;
176:
177: actionrow = NEW2(2*ntokens, short);
178: for (i = 0; i < nstates; ++i)
179: {
180: if (parser[i])
181: {
182: for (j = 0; j < 2*ntokens; ++j)
183: actionrow[j] = 0;
184:
185: shiftcount = 0;
186: reducecount = 0;
187: for (p = parser[i]; p; p = p->next)
188: {
189: if (p->suppressed == 0)
190: {
191: if (p->action_code == SHIFT)
192: {
193: ++shiftcount;
194: actionrow[p->symbol] = p->number;
195: }
196: else if (p->action_code == REDUCE && p->number != defred[i])
197: {
198: ++reducecount;
199: actionrow[p->symbol + ntokens] = p->number;
200: }
201: }
202: }
203:
204: tally[i] = shiftcount;
205: tally[nstates+i] = reducecount;
206: width[i] = 0;
207: width[nstates+i] = 0;
208: if (shiftcount > 0)
209: {
210: froms[i] = r = NEW2(shiftcount, short);
211: tos[i] = s = NEW2(shiftcount, short);
212: min = MAXSHORT;
213: max = 0;
214: for (j = 0; j < ntokens; ++j)
215: {
216: if (actionrow[j])
217: {
218: if (min > symbol_value[j])
219: min = symbol_value[j];
220: if (max < symbol_value[j])
221: max = symbol_value[j];
222: *r++ = symbol_value[j];
223: *s++ = actionrow[j];
224: }
225: }
226: width[i] = max - min + 1;
227: }
228: if (reducecount > 0)
229: {
230: froms[nstates+i] = r = NEW2(reducecount, short);
231: tos[nstates+i] = s = NEW2(reducecount, short);
232: min = MAXSHORT;
233: max = 0;
234: for (j = 0; j < ntokens; ++j)
235: {
236: if (actionrow[ntokens+j])
237: {
238: if (min > symbol_value[j])
239: min = symbol_value[j];
240: if (max < symbol_value[j])
241: max = symbol_value[j];
242: *r++ = symbol_value[j];
243: *s++ = actionrow[ntokens+j] - 2;
244: }
245: }
246: width[nstates+i] = max - min + 1;
247: }
248: }
249: }
250: FREE(actionrow);
251: }
252:
253: goto_actions()
254: {
255: register int i, j, k;
256:
257: state_count = NEW2(nstates, short);
258:
259: k = default_goto(start_symbol + 1);
260: fprintf(output_file, "short yydgoto[] = {%40d,", k);
261: save_column(start_symbol + 1, k);
262:
263: j = 10;
264: for (i = start_symbol + 2; i < nsyms; i++)
265: {
266: if (j >= 10)
267: {
268: ++outline;
269: putc('\n', output_file);
270: j = 1;
271: }
272: else
273: ++j;
274:
275: k = default_goto(i);
276: fprintf(output_file, "%5d,", k);
277: save_column(i, k);
278: }
279:
280: outline += 2;
281: fprintf(output_file, "\n};\n");
282: FREE(state_count);
283: }
284:
285: int
286: default_goto(symbol)
287: int symbol;
288: {
289: register int i;
290: register int m;
291: register int n;
292: register int default_state;
293: register int max;
294:
295: m = goto_map[symbol];
296: n = goto_map[symbol + 1];
297:
298: if (m == n) return (0);
299:
300: for (i = 0; i < nstates; i++)
301: state_count[i] = 0;
302:
303: for (i = m; i < n; i++)
304: state_count[to_state[i]]++;
305:
306: max = 0;
307: default_state = 0;
308: for (i = 0; i < nstates; i++)
309: {
310: if (state_count[i] > max)
311: {
312: max = state_count[i];
313: default_state = i;
314: }
315: }
316:
317: return (default_state);
318: }
319:
320:
321:
322: save_column(symbol, default_state)
323: int symbol;
324: int default_state;
325: {
326: register int i;
327: register int m;
328: register int n;
329: register short *sp;
330: register short *sp1;
331: register short *sp2;
332: register int count;
333: register int symno;
334:
335: m = goto_map[symbol];
336: n = goto_map[symbol + 1];
337:
338: count = 0;
339: for (i = m; i < n; i++)
340: {
341: if (to_state[i] != default_state)
342: ++count;
343: }
344: if (count == 0) return;
345:
346: symno = symbol_value[symbol] + 2*nstates;
347:
348: froms[symno] = sp1 = sp = NEW2(count, short);
349: tos[symno] = sp2 = NEW2(count, short);
350:
351: for (i = m; i < n; i++)
352: {
353: if (to_state[i] != default_state)
354: {
355: *sp1++ = from_state[i];
356: *sp2++ = to_state[i];
357: }
358: }
359:
360: tally[symno] = count;
361: width[symno] = sp1[-1] - sp[0] + 1;
362: }
363:
364: sort_actions()
365: {
366: register int i;
367: register int j;
368: register int k;
369: register int t;
370: register int w;
371:
372: order = NEW2(nvectors, short);
373: nentries = 0;
374:
375: for (i = 0; i < nvectors; i++)
376: {
377: if (tally[i] > 0)
378: {
379: t = tally[i];
380: w = width[i];
381: j = nentries - 1;
382:
383: while (j >= 0 && (width[order[j]] < w))
384: j--;
385:
386: while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
387: j--;
388:
389: for (k = nentries - 1; k > j; k--)
390: order[k + 1] = order[k];
391:
392: order[j + 1] = i;
393: nentries++;
394: }
395: }
396: }
397:
398:
399: pack_table()
400: {
401: register int i;
402: register int place;
403: register int state;
404:
405: base = NEW2(nvectors, short);
406: pos = NEW2(nentries, short);
407:
408: maxtable = 1000;
409: table = NEW2(maxtable, short);
410: check = NEW2(maxtable, short);
411:
412: lowzero = 0;
413: high = 0;
414:
415: for (i = 0; i < maxtable; i++)
416: check[i] = -1;
417:
418: for (i = 0; i < nentries; i++)
419: {
420: state = matching_vector(i);
421:
422: if (state < 0)
423: place = pack_vector(i);
424: else
425: place = base[state];
426:
427: pos[i] = place;
428: base[order[i]] = place;
429: }
430:
431: for (i = 0; i < nvectors; i++)
432: {
433: if (froms[i])
434: FREE(froms[i]);
435: if (tos[i])
436: FREE(tos[i]);
437: }
438:
439: FREE(froms);
440: FREE(tos);
441: FREE(pos);
442: }
443:
444:
445: /* The function matching_vector determines if the vector specified by */
446: /* the input parameter matches a previously considered vector. The */
447: /* test at the start of the function checks if the vector represents */
448: /* a row of shifts over terminal symbols or a row of reductions, or a */
449: /* column of shifts over a nonterminal symbol. Berkeley Yacc does not */
450: /* check if a column of shifts over a nonterminal symbols matches a */
451: /* previously considered vector. Because of the nature of LR parsing */
452: /* tables, no two columns can match. Therefore, the only possible */
453: /* match would be between a row and a column. Such matches are */
454: /* unlikely. Therefore, to save time, no attempt is made to see if a */
455: /* column matches a previously considered vector. */
456: /* */
457: /* Matching_vector is poorly designed. The test could easily be made */
458: /* faster. Also, it depends on the vectors being in a specific */
459: /* order. */
460:
461: int
462: matching_vector(vector)
463: int vector;
464: {
465: register int i;
466: register int j;
467: register int k;
468: register int t;
469: register int w;
470: register int match;
471: register int prev;
472:
473: i = order[vector];
474: if (i >= 2*nstates)
475: return (-1);
476:
477: t = tally[i];
478: w = width[i];
479:
480: for (prev = vector - 1; prev >= 0; prev--)
481: {
482: j = order[prev];
483: if (width[j] != w || tally[j] != t)
484: return (-1);
485:
486: match = 1;
487: for (k = 0; match && k < t; k++)
488: {
489: if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
490: match = 0;
491: }
492:
493: if (match)
494: return (j);
495: }
496:
497: return (-1);
498: }
499:
500:
501:
502: int
503: pack_vector(vector)
504: int vector;
505: {
506: register int i, j, k, l;
507: register int t;
508: register int loc;
509: register int ok;
510: register short *from;
511: register short *to;
512: int newmax;
513:
514: i = order[vector];
515: t = tally[i];
516: assert(t);
517:
518: from = froms[i];
519: to = tos[i];
520:
521: j = lowzero - from[0];
522: for (k = 1; k < t; ++k)
523: if (lowzero - from[k] > j)
524: j = lowzero - from[k];
525: for (;; ++j)
526: {
527: if (j == 0)
528: continue;
529: ok = 1;
530: for (k = 0; ok && k < t; k++)
531: {
532: loc = j + from[k];
533: if (loc >= maxtable)
534: {
535: if (loc >= MAXTABLE)
536: fatal("maximum table size exceeded");
537:
538: newmax = maxtable;
539: do { newmax += 200; } while (newmax <= loc);
540: table = (short *) realloc(table, newmax*sizeof(short));
541: if (table == 0) no_space();
542: check = (short *) realloc(check, newmax*sizeof(short));
543: if (check == 0) no_space();
544: for (l = maxtable; l < newmax; ++l)
545: {
546: table[l] = 0;
547: check[l] = -1;
548: }
549: maxtable = newmax;
550: }
551:
552: if (check[loc] != -1)
553: ok = 0;
554: }
555: for (k = 0; ok && k < vector; k++)
556: {
557: if (pos[k] == j)
558: ok = 0;
559: }
560: if (ok)
561: {
562: for (k = 0; k < t; k++)
563: {
564: loc = j + from[k];
565: table[loc] = to[k];
566: check[loc] = from[k];
567: if (loc > high) high = loc;
568: }
569:
570: while (check[lowzero] != -1)
571: ++lowzero;
572:
573: return (j);
574: }
575: }
576: }
577:
578:
579:
580: output_base()
581: {
582: register int i, j;
583:
584: fprintf(output_file, "short yysindex[] = {%39d,", base[0]);
585:
586: j = 10;
587: for (i = 1; i < nstates; i++)
588: {
589: if (j >= 10)
590: {
591: ++outline;
592: putc('\n', output_file);
593: j = 1;
594: }
595: else
596: ++j;
597:
598: fprintf(output_file, "%5d,", base[i]);
599: }
600:
601: outline += 2;
602: fprintf(output_file, "\n};\nshort yyrindex[] = {%39d,",
603: base[nstates]);
604:
605: j = 10;
606: for (i = nstates + 1; i < 2*nstates; i++)
607: {
608: if (j >= 10)
609: {
610: ++outline;
611: putc('\n', output_file);
612: j = 1;
613: }
614: else
615: ++j;
616:
617: fprintf(output_file, "%5d,", base[i]);
618: }
619:
620: outline += 2;
621: fprintf(output_file, "\n};\nshort yygindex[] = {%39d,",
622: base[2*nstates]);
623:
624: j = 10;
625: for (i = 2*nstates + 1; i < nvectors - 1; i++)
626: {
627: if (j >= 10)
628: {
629: ++outline;
630: putc('\n', output_file);
631: j = 1;
632: }
633: else
634: ++j;
635:
636: fprintf(output_file, "%5d,", base[i]);
637: }
638:
639: outline += 2;
640: fprintf(output_file, "\n};\n");
641: FREE(base);
642: }
643:
644:
645:
646: output_table()
647: {
648: register int i;
649: register int j;
650:
651: ++outline;
652: fprintf(output_file, "#define YYTABLESIZE %d\n", high);
653: fprintf(output_file, "short yytable[] = {%40d,", table[0]);
654:
655: j = 10;
656: for (i = 1; i <= high; i++)
657: {
658: if (j >= 10)
659: {
660: ++outline;
661: putc('\n', output_file);
662: j = 1;
663: }
664: else
665: ++j;
666:
667: fprintf(output_file, "%5d,", table[i]);
668: }
669:
670: outline += 2;
671: fprintf(output_file, "\n};\n");
672: FREE(table);
673: }
674:
675:
676:
677: output_check()
678: {
679: register int i;
680: register int j;
681:
682: fprintf(output_file, "short yycheck[] = {%40d,", check[0]);
683:
684: j = 10;
685: for (i = 1; i <= high; i++)
686: {
687: if (j >= 10)
688: {
689: ++outline;
690: putc('\n', output_file);
691: j = 1;
692: }
693: else
694: ++j;
695:
696: fprintf(output_file, "%5d,", check[i]);
697: }
698:
699: outline += 2;
700: fprintf(output_file, "\n};\n");
701: FREE(check);
702: }
703:
704:
705: int
706: is_C_identifier(name)
707: char *name;
708: {
709: register char *s;
710: register int c;
711:
712: s = name;
713: c = *s;
714: if (c == '"')
715: {
716: c = *++s;
717: if (!isalpha(c) && c != '_' && c != '$')
718: return (0);
719: while ((c = *++s) != '"')
720: {
721: if (!isalnum(c) && c != '_' && c != '$')
722: return (0);
723: }
724: return (1);
725: }
726:
727: if (!isalpha(c) && c != '_' && c != '$')
728: return (0);
729: while (c = *++s)
730: {
731: if (!isalnum(c) && c != '_' && c != '$')
732: return (0);
733: }
734: return (1);
735: }
736:
737:
738: output_defines()
739: {
740: register int c, i;
741: register char *s;
742:
743: for (i = 2; i < ntokens; ++i)
744: {
745: s = symbol_name[i];
746: if (is_C_identifier(s))
747: {
748: fprintf(output_file, "#define ");
749: if (dflag) fprintf(defines_file, "#define ");
750: c = *s;
751: if (c == '"')
752: {
753: while ((c = *++s) != '"')
754: {
755: putc(c, output_file);
756: if (dflag) putc(c, defines_file);
757: }
758: }
759: else
760: {
761: do
762: {
763: putc(c, output_file);
764: if (dflag) putc(c, defines_file);
765: }
766: while (c = *++s);
767: }
768: ++outline;
769: fprintf(output_file, " %d\n", symbol_value[i]);
770: if (dflag) fprintf(defines_file, " %d\n", symbol_value[i]);
771: }
772: }
773:
774: ++outline;
775: fprintf(output_file, "#define YYERRCODE %d\n", symbol_value[1]);
776:
777: if (dflag && unionized)
778: {
779: fclose(union_file);
780: union_file = fopen(union_file_name, "r");
781: if (union_file == NULL) open_error(union_file_name);
782: while ((c = getc(union_file)) != EOF)
783: putc(c, defines_file);
784: fprintf(defines_file, " YYSTYPE;\nextern YYSTYPE yylval;\n");
785: }
786: }
787:
788:
789: output_stored_text()
790: {
791: register int c;
792: register FILE *in, *out;
793:
794: fclose(text_file);
795: text_file = fopen(text_file_name, "r");
796: if (text_file == NULL) open_error(text_file_name);
797: in = text_file;
798: out = output_file;
799: if ((c = getc(in)) == EOF)
800: return;
801: if (c == '\n') ++outline;
802: putc(c, out);
803: while ((c = getc(in)) != EOF)
804: {
805: if (c == '\n') ++outline;
806: putc(c, out);
807: }
808: if (!lflag)
809: {
810: ++outline;
811: fprintf(out, line_format, outline + 1, output_file_name);
812: }
813: }
814:
815:
816: output_debug()
817: {
818: register int i, j, k, max;
819: char **symnam, *s;
820:
821: ++outline;
822: fprintf(output_file, "#define YYFINAL %d\n", final_state);
823: outline += 3;
824: fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
825: tflag);
826:
827: max = 0;
828: for (i = 2; i < ntokens; ++i)
829: if (symbol_value[i] > max)
830: max = symbol_value[i];
831: ++outline;
832: fprintf(output_file, "#define YYMAXTOKEN %d\n", max);
833:
834: symnam = (char **) MALLOC((max+1)*sizeof(char *));
835: if (symnam == 0) no_space();
836: for (i = 0; i < max; ++i)
837: symnam[i] = 0;
838: for (i = ntokens - 1; i >= 2; --i)
839: symnam[symbol_value[i]] = symbol_name[i];
840: symnam[0] = "end-of-file";
841:
842: ++outline;
843: fprintf(output_file, "#if YYDEBUG\nchar *yyname[] = {");
844: j = 80;
845: for (i = 0; i <= max; ++i)
846: {
847: if (s = symnam[i])
848: {
849: if (s[0] == '"')
850: {
851: k = 7;
852: while (*++s != '"')
853: {
854: if (*s == '\\')
855: {
856: k += 2;
857: if (*++s == '\\')
858: k += 2;
859: else
860: ++k;
861: }
862: else
863: ++k;
864: }
865: j += k;
866: if (j > 80)
867: {
868: ++outline;
869: putc('\n', output_file);
870: j = k;
871: }
872: fprintf(output_file, "\"\\\"");
873: s = symnam[i];
874: while (*++s != '"')
875: {
876: if (*s == '\\')
877: {
878: fprintf(output_file, "\\\\");
879: if (*++s == '\\')
880: fprintf(output_file, "\\\\");
881: else
882: putc(*s, output_file);
883: }
884: else
885: putc(*s, output_file);
886: }
887: fprintf(output_file, "\\\"\",");
888: }
889: else if (s[0] == '\'')
890: {
891: if (s[1] == '"')
892: {
893: j += 7;
894: if (j > 80)
895: {
896: ++outline;
897: putc('\n', output_file);
898: j = 7;
899: }
900: fprintf(output_file, "\"'\\\"'\",");
901: }
902: else
903: {
904: k = 5;
905: while (*++s != '\'')
906: {
907: if (*s == '\\')
908: {
909: k += 2;
910: ++s;
911: if (*++s == '\\')
912: k += 2;
913: else
914: ++k;
915: }
916: else
917: ++k;
918: }
919: j += k;
920: if (j > 80)
921: {
922: ++outline;
923: putc('\n', output_file);
924: j = k;
925: }
926: fprintf(output_file, "\"'");
927: s = symnam[i];
928: while (*++s != '\'')
929: {
930: if (*s == '\\')
931: {
932: fprintf(output_file, "\\\\");
933: if (*++s == '\\')
934: fprintf(output_file, "\\\\");
935: else
936: putc(*s, output_file);
937: }
938: else
939: putc(*s, output_file);
940: }
941: fprintf(output_file, "'\",");
942: }
943: }
944: else
945: {
946: k = strlen(s) + 3;
947: j += k;
948: if (j > 80)
949: {
950: ++outline;
951: putc('\n', output_file);
952: j = k;
953: }
954: putc('"', output_file);
955: do { putc(*s, output_file); } while (*++s);
956: fprintf(output_file, "\",");
957: }
958: }
959: else
960: {
961: j += 2;
962: if (j > 80)
963: {
964: ++outline;
965: putc('\n', output_file);
966: j = 2;
967: }
968: fprintf(output_file, "0,");
969: }
970: }
971: outline += 2;
972: fprintf(output_file, "\n};\n");
973: FREE(symnam);
974:
975: ++outline;
976: fprintf(output_file, "char *yyrule[] = {\n");
977: for (i = 2; i < nrules; ++i)
978: {
979: fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
980: for (j = rrhs[i]; ritem[j] > 0; ++j)
981: {
982: s = symbol_name[ritem[j]];
983: if (s[0] == '"')
984: {
985: fprintf(output_file, " \\\"");
986: while (*++s != '"')
987: {
988: if (*s == '\\')
989: {
990: if (s[1] == '\\')
991: fprintf(output_file, "\\\\\\\\");
992: else
993: fprintf(output_file, "\\\\%c", s[1]);
994: ++s;
995: }
996: else
997: putc(*s, output_file);
998: }
999: fprintf(output_file, "\\\"");
1000: }
1001: else if (s[0] == '\'')
1002: {
1003: if (s[1] == '"')
1004: fprintf(output_file, " '\\\"'");
1005: else if (s[1] == '\\')
1006: {
1007: if (s[2] == '\\')
1008: fprintf(output_file, " '\\\\\\\\");
1009: else
1010: fprintf(output_file, " '\\\\%c", s[2]);
1011: s += 2;
1012: while (*++s != '\'')
1013: putc(*s, output_file);
1014: putc('\'', output_file);
1015: }
1016: else
1017: fprintf(output_file, " '%c'", s[1]);
1018: }
1019: else
1020: fprintf(output_file, " %s", s);
1021: }
1022: ++outline;
1023: fprintf(output_file, "\",\n");
1024: }
1025:
1026: outline += 2;
1027: fprintf(output_file, "};\n#endif\n");
1028: }
1029:
1030:
1031: output_stype()
1032: {
1033: if (!unionized && ntags == 0)
1034: {
1035: outline += 3;
1036: fprintf(output_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
1037: }
1038: }
1039:
1040:
1041: output_trailing_text()
1042: {
1043: register int c, last;
1044:
1045: if (line == 0)
1046: return;
1047:
1048: c = *cptr;
1049: if (c == '\n')
1050: {
1051: ++lineno;
1052: if ((c = getc(input_file)) == EOF)
1053: return;
1054: if (!lflag)
1055: {
1056: ++outline;
1057: fprintf(output_file, line_format, lineno, input_file_name);
1058: }
1059: if (c == '\n') ++outline;
1060: putc(c, output_file);
1061: last = c;
1062: }
1063: else
1064: {
1065: if (!lflag)
1066: {
1067: ++outline;
1068: fprintf(output_file, line_format, lineno, input_file_name);
1069: }
1070: do { putc(c, output_file); } while ((c = *++cptr) != '\n');
1071: ++outline;
1072: putc('\n', output_file);
1073: last = '\n';
1074: }
1075:
1076: while ((c = getc(input_file)) != EOF)
1077: {
1078: if (c == '\n') ++outline;
1079: putc(c, output_file);
1080: last = c;
1081: }
1082:
1083: if (last != '\n')
1084: {
1085: ++outline;
1086: putc('\n', output_file);
1087: }
1088: if (!lflag)
1089: {
1090: ++outline;
1091: fprintf(output_file, line_format, outline + 1, output_file_name);
1092: }
1093: }
1094:
1095:
1096: output_semantic_actions()
1097: {
1098: register int c, last;
1099:
1100: fclose(action_file);
1101: action_file = fopen(action_file_name, "r");
1102: if (action_file == NULL) open_error(action_file_name);
1103:
1104: if ((c = getc(action_file)) == EOF)
1105: return;
1106: last = c;
1107: if (c == '\n') ++outline;
1108: putc(c, output_file);
1109: while ((c = getc(action_file)) != EOF)
1110: {
1111: if (c == '\n') ++outline;
1112: putc(c, output_file);
1113: last = c;
1114: }
1115:
1116: if (last != '\n')
1117: {
1118: ++outline;
1119: putc('\n', output_file);
1120: }
1121: if (!lflag)
1122: {
1123: ++outline;
1124: fprintf(output_file, line_format, outline + 1, output_file_name);
1125: }
1126: }
1127:
1128:
1129: free_itemsets()
1130: {
1131: register core *cp, *next;
1132:
1133: FREE(state_table);
1134: for (cp = first_state; cp; cp = next)
1135: {
1136: next = cp->next;
1137: FREE(cp);
1138: }
1139: }
1140:
1141:
1142: free_shifts()
1143: {
1144: register shifts *sp, *next;
1145:
1146: FREE(shift_table);
1147: for (sp = first_shift; sp; sp = next)
1148: {
1149: next = sp->next;
1150: FREE(sp);
1151: }
1152: }
1153:
1154:
1155:
1156: free_reductions()
1157: {
1158: register reductions *rp, *next;
1159:
1160: FREE(reduction_table);
1161: for (rp = first_reduction; rp; rp = next)
1162: {
1163: next = rp->next;
1164: FREE(rp);
1165: }
1166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.