Annotation of src/usr.bin/yacc/skeleton.c, Revision 1.1.1.1
1.1 deraadt 1: #include "defs.h"
2:
3: /* The definition of yysccsid in the banner should be replaced with */
4: /* a #pragma ident directive if the target C compiler supports */
5: /* #pragma ident directives. */
6: /* */
7: /* If the skeleton is changed, the banner should be changed so that */
8: /* the altered version can be easily distinguished from the original. */
9: /* */
10: /* The #defines included with the banner are there because they are */
11: /* useful in subsequent code. The macros #defined in the header or */
12: /* the body either are not useful outside of semantic actions or */
13: /* are conditional. */
14:
15: char *banner[] =
16: {
17: "#ifndef lint",
18: "/*static char yysccsid[] = \"from: @(#)yaccpar 1.9 (Berkeley) 02/21/93\";*/",
19: "static char yyrcsid[] = \"$Id: skeleton.c,v 1.6 1995/09/07 17:34:04 jtc Exp $\";",
20: "#endif",
21: "#define YYBYACC 1",
22: "#define YYMAJOR 1",
23: "#define YYMINOR 9",
24: "#define yyclearin (yychar=(-1))",
25: "#define yyerrok (yyerrflag=0)",
26: "#define YYRECOVERING (yyerrflag!=0)",
27: 0
28: };
29:
30:
31: char *tables[] =
32: {
33: "extern short yylhs[];",
34: "extern short yylen[];",
35: "extern short yydefred[];",
36: "extern short yydgoto[];",
37: "extern short yysindex[];",
38: "extern short yyrindex[];",
39: "extern short yygindex[];",
40: "extern short yytable[];",
41: "extern short yycheck[];",
42: "#if YYDEBUG",
43: "extern char *yyname[];",
44: "extern char *yyrule[];",
45: "#endif",
46: 0
47: };
48:
49:
50: char *header[] =
51: {
52: "#ifdef YYSTACKSIZE",
53: "#undef YYMAXDEPTH",
54: "#define YYMAXDEPTH YYSTACKSIZE",
55: "#else",
56: "#ifdef YYMAXDEPTH",
57: "#define YYSTACKSIZE YYMAXDEPTH",
58: "#else",
59: "#define YYSTACKSIZE 500",
60: "#define YYMAXDEPTH 500",
61: "#endif",
62: "#endif",
63: "int yydebug;",
64: "int yynerrs;",
65: "int yyerrflag;",
66: "int yychar;",
67: "short *yyssp;",
68: "YYSTYPE *yyvsp;",
69: "YYSTYPE yyval;",
70: "YYSTYPE yylval;",
71: "short yyss[YYSTACKSIZE];",
72: "YYSTYPE yyvs[YYSTACKSIZE];",
73: "#define yystacksize YYSTACKSIZE",
74: 0
75: };
76:
77:
78: char *body[] =
79: {
80: "#define YYABORT goto yyabort",
81: "#define YYREJECT goto yyabort",
82: "#define YYACCEPT goto yyaccept",
83: "#define YYERROR goto yyerrlab",
84: "int",
85: "#if defined(__STDC__)",
86: "yyparse(void)",
87: "#else",
88: "yyparse()",
89: "#endif",
90: "{",
91: " register int yym, yyn, yystate;",
92: "#if YYDEBUG",
93: " register char *yys;",
94: " extern char *getenv();",
95: "",
96: " if (yys = getenv(\"YYDEBUG\"))",
97: " {",
98: " yyn = *yys;",
99: " if (yyn >= '0' && yyn <= '9')",
100: " yydebug = yyn - '0';",
101: " }",
102: "#endif",
103: "",
104: " yynerrs = 0;",
105: " yyerrflag = 0;",
106: " yychar = (-1);",
107: "",
108: " yyssp = yyss;",
109: " yyvsp = yyvs;",
110: " *yyssp = yystate = 0;",
111: "",
112: "yyloop:",
113: " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
114: " if (yychar < 0)",
115: " {",
116: " if ((yychar = yylex()) < 0) yychar = 0;",
117: "#if YYDEBUG",
118: " if (yydebug)",
119: " {",
120: " yys = 0;",
121: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
122: " if (!yys) yys = \"illegal-symbol\";",
123: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
124: " YYPREFIX, yystate, yychar, yys);",
125: " }",
126: "#endif",
127: " }",
128: " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
129: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
130: " {",
131: "#if YYDEBUG",
132: " if (yydebug)",
133: " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
134: " YYPREFIX, yystate, yytable[yyn]);",
135: "#endif",
136: " if (yyssp >= yyss + yystacksize - 1)",
137: " {",
138: " goto yyoverflow;",
139: " }",
140: " *++yyssp = yystate = yytable[yyn];",
141: " *++yyvsp = yylval;",
142: " yychar = (-1);",
143: " if (yyerrflag > 0) --yyerrflag;",
144: " goto yyloop;",
145: " }",
146: " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
147: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
148: " {",
149: " yyn = yytable[yyn];",
150: " goto yyreduce;",
151: " }",
152: " if (yyerrflag) goto yyinrecovery;",
153: " yyerror(\"syntax error\");",
154: "#ifdef lint",
155: " goto yyerrlab;",
156: "#endif",
157: "yyerrlab:",
158: " ++yynerrs;",
159: "yyinrecovery:",
160: " if (yyerrflag < 3)",
161: " {",
162: " yyerrflag = 3;",
163: " for (;;)",
164: " {",
165: " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
166: " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
167: " {",
168: "#if YYDEBUG",
169: " if (yydebug)",
170: " printf(\"%sdebug: state %d, error recovery shifting\\",
171: " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
172: "#endif",
173: " if (yyssp >= yyss + yystacksize - 1)",
174: " {",
175: " goto yyoverflow;",
176: " }",
177: " *++yyssp = yystate = yytable[yyn];",
178: " *++yyvsp = yylval;",
179: " goto yyloop;",
180: " }",
181: " else",
182: " {",
183: "#if YYDEBUG",
184: " if (yydebug)",
185: " printf(\"%sdebug: error recovery discarding state %d\
186: \\n\",",
187: " YYPREFIX, *yyssp);",
188: "#endif",
189: " if (yyssp <= yyss) goto yyabort;",
190: " --yyssp;",
191: " --yyvsp;",
192: " }",
193: " }",
194: " }",
195: " else",
196: " {",
197: " if (yychar == 0) goto yyabort;",
198: "#if YYDEBUG",
199: " if (yydebug)",
200: " {",
201: " yys = 0;",
202: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
203: " if (!yys) yys = \"illegal-symbol\";",
204: " printf(\"%sdebug: state %d, error recovery discards token %d\
205: (%s)\\n\",",
206: " YYPREFIX, yystate, yychar, yys);",
207: " }",
208: "#endif",
209: " yychar = (-1);",
210: " goto yyloop;",
211: " }",
212: "yyreduce:",
213: "#if YYDEBUG",
214: " if (yydebug)",
215: " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
216: " YYPREFIX, yystate, yyn, yyrule[yyn]);",
217: "#endif",
218: " yym = yylen[yyn];",
219: " yyval = yyvsp[1-yym];",
220: " switch (yyn)",
221: " {",
222: 0
223: };
224:
225:
226: char *trailer[] =
227: {
228: " }",
229: " yyssp -= yym;",
230: " yystate = *yyssp;",
231: " yyvsp -= yym;",
232: " yym = yylhs[yyn];",
233: " if (yystate == 0 && yym == 0)",
234: " {",
235: "#if YYDEBUG",
236: " if (yydebug)",
237: " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
238: " state %d\\n\", YYPREFIX, YYFINAL);",
239: "#endif",
240: " yystate = YYFINAL;",
241: " *++yyssp = YYFINAL;",
242: " *++yyvsp = yyval;",
243: " if (yychar < 0)",
244: " {",
245: " if ((yychar = yylex()) < 0) yychar = 0;",
246: "#if YYDEBUG",
247: " if (yydebug)",
248: " {",
249: " yys = 0;",
250: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
251: " if (!yys) yys = \"illegal-symbol\";",
252: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
253: " YYPREFIX, YYFINAL, yychar, yys);",
254: " }",
255: "#endif",
256: " }",
257: " if (yychar == 0) goto yyaccept;",
258: " goto yyloop;",
259: " }",
260: " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
261: " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
262: " yystate = yytable[yyn];",
263: " else",
264: " yystate = yydgoto[yym];",
265: "#if YYDEBUG",
266: " if (yydebug)",
267: " printf(\"%sdebug: after reduction, shifting from state %d \\",
268: "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
269: "#endif",
270: " if (yyssp >= yyss + yystacksize - 1)",
271: " {",
272: " goto yyoverflow;",
273: " }",
274: " *++yyssp = yystate;",
275: " *++yyvsp = yyval;",
276: " goto yyloop;",
277: "yyoverflow:",
278: " yyerror(\"yacc stack overflow\");",
279: "yyabort:",
280: " return (1);",
281: "yyaccept:",
282: " return (0);",
283: "}",
284: 0
285: };
286:
287:
288: write_section(section)
289: char *section[];
290: {
291: register int c;
292: register int i;
293: register char *s;
294: register FILE *f;
295:
296: f = code_file;
297: for (i = 0; s = section[i]; ++i)
298: {
299: ++outline;
300: while (c = *s)
301: {
302: putc(c, f);
303: ++s;
304: }
305: putc('\n', f);
306: }
307: }