Annotation of src/usr.bin/yacc/skeleton.c, Revision 1.13
1.12 dm 1: /* $OpenBSD: skeleton.c,v 1.11 1998/11/17 06:13:43 dm Exp $ */
1.4 deraadt 2: /* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */
3:
4: /*
5: * Copyright (c) 1989 The Regents of the University of California.
6: * All rights reserved.
7: *
8: * This code is derived from software contributed to Berkeley by
9: * Robert Paul Corbett.
10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions and the following disclaimer.
16: * 2. Redistributions in binary form must reproduce the above copyright
17: * notice, this list of conditions and the following disclaimer in the
18: * documentation and/or other materials provided with the distribution.
19: * 3. All advertising materials mentioning features or use of this software
20: * must display the following acknowledgement:
21: * This product includes software developed by the University of
22: * California, Berkeley and its contributors.
23: * 4. Neither the name of the University nor the names of its contributors
24: * may be used to endorse or promote products derived from this software
25: * without specific prior written permission.
26: *
27: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37: * SUCH DAMAGE.
38: */
39:
40: #ifndef lint
41: #if 0
42: static char sccsid[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95";
43: #else
44: static char rcsid[] = "$NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $";
45: #endif
46: #endif /* not lint */
1.3 niklas 47:
1.1 deraadt 48: #include "defs.h"
49:
50: /* The definition of yysccsid in the banner should be replaced with */
51: /* a #pragma ident directive if the target C compiler supports */
52: /* #pragma ident directives. */
53: /* */
54: /* If the skeleton is changed, the banner should be changed so that */
55: /* the altered version can be easily distinguished from the original. */
56: /* */
57: /* The #defines included with the banner are there because they are */
58: /* useful in subsequent code. The macros #defined in the header or */
59: /* the body either are not useful outside of semantic actions or */
60: /* are conditional. */
61:
62: char *banner[] =
63: {
64: "#ifndef lint",
65: "/*static char yysccsid[] = \"from: @(#)yaccpar 1.9 (Berkeley) 02/21/93\";*/",
1.13 ! dm 66: "static char yyrcsid[]",
! 67: "#if __GNUC__ == 2",
! 68: " __attribute__ ((unused))",
! 69: "#endif /* __GNUC__ == 2 */",
! 70: " = \"$OpenBSD: skeleton.c,v 1.11 1998/11/17 06:13:43 dm Exp $\";",
1.1 deraadt 71: "#endif",
1.4 deraadt 72: "#include <stdlib.h>",
1.1 deraadt 73: "#define YYBYACC 1",
74: "#define YYMAJOR 1",
75: "#define YYMINOR 9",
1.2 niklas 76: "#define YYLEX yylex()",
77: "#define YYEMPTY -1",
78: "#define yyclearin (yychar=(YYEMPTY))",
1.1 deraadt 79: "#define yyerrok (yyerrflag=0)",
1.8 tholo 80: "#define YYRECOVERING() (yyerrflag!=0)",
1.1 deraadt 81: 0
82: };
83:
84:
85: char *tables[] =
86: {
87: "extern short yylhs[];",
88: "extern short yylen[];",
89: "extern short yydefred[];",
90: "extern short yydgoto[];",
91: "extern short yysindex[];",
92: "extern short yyrindex[];",
93: "extern short yygindex[];",
94: "extern short yytable[];",
95: "extern short yycheck[];",
96: "#if YYDEBUG",
97: "extern char *yyname[];",
98: "extern char *yyrule[];",
99: "#endif",
100: 0
101: };
102:
103:
104: char *header[] =
105: {
106: "#ifdef YYSTACKSIZE",
107: "#undef YYMAXDEPTH",
108: "#define YYMAXDEPTH YYSTACKSIZE",
109: "#else",
110: "#ifdef YYMAXDEPTH",
111: "#define YYSTACKSIZE YYMAXDEPTH",
112: "#else",
1.4 deraadt 113: "#define YYSTACKSIZE 10000",
114: "#define YYMAXDEPTH 10000",
1.1 deraadt 115: "#endif",
116: "#endif",
1.4 deraadt 117: "#define YYINITSTACKSIZE 200",
1.1 deraadt 118: "int yydebug;",
119: "int yynerrs;",
120: "int yyerrflag;",
121: "int yychar;",
122: "short *yyssp;",
123: "YYSTYPE *yyvsp;",
124: "YYSTYPE yyval;",
125: "YYSTYPE yylval;",
1.4 deraadt 126: "short *yyss;",
127: "short *yysslim;",
128: "YYSTYPE *yyvs;",
129: "int yystacksize;",
1.1 deraadt 130: 0
131: };
132:
133:
134: char *body[] =
135: {
1.4 deraadt 136: "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
1.5 tholo 137: "#if defined(__cplusplus) || __STDC__",
138: "static int yygrowstack(void)",
139: "#else",
1.4 deraadt 140: "static int yygrowstack()",
1.5 tholo 141: "#endif",
1.4 deraadt 142: "{",
143: " int newsize, i;",
144: " short *newss;",
145: " YYSTYPE *newvs;",
146: "",
147: " if ((newsize = yystacksize) == 0)",
148: " newsize = YYINITSTACKSIZE;",
149: " else if (newsize >= YYMAXDEPTH)",
150: " return -1;",
151: " else if ((newsize *= 2) > YYMAXDEPTH)",
152: " newsize = YYMAXDEPTH;",
153: " i = yyssp - yyss;",
1.10 millert 154: " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
155: " (short *)malloc(newsize * sizeof *newss);",
156: " if (newss == NULL)",
1.4 deraadt 157: " return -1;",
158: " yyss = newss;",
159: " yyssp = newss + i;",
1.10 millert 160: " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
161: " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
162: " if (newvs == NULL)",
1.4 deraadt 163: " return -1;",
164: " yyvs = newvs;",
165: " yyvsp = newvs + i;",
166: " yystacksize = newsize;",
167: " yysslim = yyss + newsize - 1;",
168: " return 0;",
169: "}",
170: "",
1.1 deraadt 171: "#define YYABORT goto yyabort",
172: "#define YYREJECT goto yyabort",
173: "#define YYACCEPT goto yyaccept",
174: "#define YYERROR goto yyerrlab",
175: "int",
1.5 tholo 176: "#if defined(__cplusplus) || __STDC__",
177: "yyparse(void)",
178: "#else",
1.1 deraadt 179: "yyparse()",
1.5 tholo 180: "#endif",
1.1 deraadt 181: "{",
182: " register int yym, yyn, yystate;",
183: "#if YYDEBUG",
184: " register char *yys;",
185: "",
1.6 deraadt 186: " if ((yys = getenv(\"YYDEBUG\")))",
1.1 deraadt 187: " {",
188: " yyn = *yys;",
189: " if (yyn >= '0' && yyn <= '9')",
190: " yydebug = yyn - '0';",
191: " }",
192: "#endif",
193: "",
194: " yynerrs = 0;",
195: " yyerrflag = 0;",
196: " yychar = (-1);",
197: "",
1.4 deraadt 198: " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
1.1 deraadt 199: " yyssp = yyss;",
200: " yyvsp = yyvs;",
201: " *yyssp = yystate = 0;",
202: "",
203: "yyloop:",
204: " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
205: " if (yychar < 0)",
206: " {",
207: " if ((yychar = yylex()) < 0) yychar = 0;",
208: "#if YYDEBUG",
209: " if (yydebug)",
210: " {",
211: " yys = 0;",
212: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
213: " if (!yys) yys = \"illegal-symbol\";",
214: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
215: " YYPREFIX, yystate, yychar, yys);",
216: " }",
217: "#endif",
218: " }",
219: " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
220: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
221: " {",
222: "#if YYDEBUG",
223: " if (yydebug)",
224: " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
225: " YYPREFIX, yystate, yytable[yyn]);",
226: "#endif",
1.4 deraadt 227: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 228: " {",
229: " goto yyoverflow;",
230: " }",
231: " *++yyssp = yystate = yytable[yyn];",
232: " *++yyvsp = yylval;",
233: " yychar = (-1);",
234: " if (yyerrflag > 0) --yyerrflag;",
235: " goto yyloop;",
236: " }",
237: " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
238: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
239: " {",
240: " yyn = yytable[yyn];",
241: " goto yyreduce;",
242: " }",
243: " if (yyerrflag) goto yyinrecovery;",
1.7 tholo 244: "#if defined(lint) || defined(__GNUC__)",
1.4 deraadt 245: " goto yynewerror;",
246: "#endif",
247: "yynewerror:",
1.1 deraadt 248: " yyerror(\"syntax error\");",
1.7 tholo 249: "#if defined(lint) || defined(__GNUC__)",
1.1 deraadt 250: " goto yyerrlab;",
251: "#endif",
252: "yyerrlab:",
253: " ++yynerrs;",
254: "yyinrecovery:",
255: " if (yyerrflag < 3)",
256: " {",
257: " yyerrflag = 3;",
258: " for (;;)",
259: " {",
260: " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
261: " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
262: " {",
263: "#if YYDEBUG",
264: " if (yydebug)",
265: " printf(\"%sdebug: state %d, error recovery shifting\\",
266: " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
267: "#endif",
1.4 deraadt 268: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 269: " {",
270: " goto yyoverflow;",
271: " }",
272: " *++yyssp = yystate = yytable[yyn];",
273: " *++yyvsp = yylval;",
274: " goto yyloop;",
275: " }",
276: " else",
277: " {",
278: "#if YYDEBUG",
279: " if (yydebug)",
280: " printf(\"%sdebug: error recovery discarding state %d\
281: \\n\",",
282: " YYPREFIX, *yyssp);",
283: "#endif",
284: " if (yyssp <= yyss) goto yyabort;",
285: " --yyssp;",
286: " --yyvsp;",
287: " }",
288: " }",
289: " }",
290: " else",
291: " {",
292: " if (yychar == 0) goto yyabort;",
293: "#if YYDEBUG",
294: " if (yydebug)",
295: " {",
296: " yys = 0;",
297: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
298: " if (!yys) yys = \"illegal-symbol\";",
299: " printf(\"%sdebug: state %d, error recovery discards token %d\
300: (%s)\\n\",",
301: " YYPREFIX, yystate, yychar, yys);",
302: " }",
303: "#endif",
304: " yychar = (-1);",
305: " goto yyloop;",
306: " }",
307: "yyreduce:",
308: "#if YYDEBUG",
309: " if (yydebug)",
310: " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
311: " YYPREFIX, yystate, yyn, yyrule[yyn]);",
312: "#endif",
313: " yym = yylen[yyn];",
314: " yyval = yyvsp[1-yym];",
315: " switch (yyn)",
316: " {",
317: 0
318: };
319:
320:
321: char *trailer[] =
322: {
323: " }",
324: " yyssp -= yym;",
325: " yystate = *yyssp;",
326: " yyvsp -= yym;",
327: " yym = yylhs[yyn];",
328: " if (yystate == 0 && yym == 0)",
329: " {",
330: "#if YYDEBUG",
331: " if (yydebug)",
332: " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
333: " state %d\\n\", YYPREFIX, YYFINAL);",
334: "#endif",
335: " yystate = YYFINAL;",
336: " *++yyssp = YYFINAL;",
337: " *++yyvsp = yyval;",
338: " if (yychar < 0)",
339: " {",
340: " if ((yychar = yylex()) < 0) yychar = 0;",
341: "#if YYDEBUG",
342: " if (yydebug)",
343: " {",
344: " yys = 0;",
345: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
346: " if (!yys) yys = \"illegal-symbol\";",
347: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
348: " YYPREFIX, YYFINAL, yychar, yys);",
349: " }",
350: "#endif",
351: " }",
352: " if (yychar == 0) goto yyaccept;",
353: " goto yyloop;",
354: " }",
355: " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
356: " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
357: " yystate = yytable[yyn];",
358: " else",
359: " yystate = yydgoto[yym];",
360: "#if YYDEBUG",
361: " if (yydebug)",
362: " printf(\"%sdebug: after reduction, shifting from state %d \\",
363: "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
364: "#endif",
1.4 deraadt 365: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 366: " {",
367: " goto yyoverflow;",
368: " }",
369: " *++yyssp = yystate;",
370: " *++yyvsp = yyval;",
371: " goto yyloop;",
372: "yyoverflow:",
373: " yyerror(\"yacc stack overflow\");",
374: "yyabort:",
375: " return (1);",
376: "yyaccept:",
377: " return (0);",
378: "}",
379: 0
380: };
381:
382:
383: write_section(section)
384: char *section[];
385: {
386: register int c;
387: register int i;
388: register char *s;
389: register FILE *f;
390:
391: f = code_file;
392: for (i = 0; s = section[i]; ++i)
393: {
394: ++outline;
395: while (c = *s)
396: {
397: putc(c, f);
398: ++s;
399: }
400: putc('\n', f);
401: }
402: }