Annotation of src/usr.bin/yacc/skeleton.c, Revision 1.14
1.14 ! deraadt 1: /* $OpenBSD: skeleton.c,v 1.13 1998/11/18 15:45:12 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 */",
1.14 ! deraadt 70: " = \"$OpenBSD: skeleton.c,v 1.13 1998/11/18 15:45:12 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.14 ! deraadt 157: " goto bail;",
1.4 deraadt 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.14 ! deraadt 163: " goto bail;",
1.4 deraadt 164: " yyvs = newvs;",
165: " yyvsp = newvs + i;",
166: " yystacksize = newsize;",
167: " yysslim = yyss + newsize - 1;",
168: " return 0;",
1.14 ! deraadt 169: "bail:",
! 170: " if (yyss)",
! 171: " free(yyss);",
! 172: " if (yyvs)",
! 173: " free(yyvs);",
! 174: " yyss = yyssp = yyvs = yyvsp = NULL;",
! 175: " yystacksize = 0;",
! 176: " return -1;",
1.4 deraadt 177: "}",
178: "",
1.1 deraadt 179: "#define YYABORT goto yyabort",
180: "#define YYREJECT goto yyabort",
181: "#define YYACCEPT goto yyaccept",
182: "#define YYERROR goto yyerrlab",
183: "int",
1.5 tholo 184: "#if defined(__cplusplus) || __STDC__",
185: "yyparse(void)",
186: "#else",
1.1 deraadt 187: "yyparse()",
1.5 tholo 188: "#endif",
1.1 deraadt 189: "{",
190: " register int yym, yyn, yystate;",
191: "#if YYDEBUG",
192: " register char *yys;",
193: "",
1.6 deraadt 194: " if ((yys = getenv(\"YYDEBUG\")))",
1.1 deraadt 195: " {",
196: " yyn = *yys;",
197: " if (yyn >= '0' && yyn <= '9')",
198: " yydebug = yyn - '0';",
199: " }",
200: "#endif",
201: "",
202: " yynerrs = 0;",
203: " yyerrflag = 0;",
204: " yychar = (-1);",
205: "",
1.4 deraadt 206: " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
1.1 deraadt 207: " yyssp = yyss;",
208: " yyvsp = yyvs;",
209: " *yyssp = yystate = 0;",
210: "",
211: "yyloop:",
212: " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
213: " if (yychar < 0)",
214: " {",
215: " if ((yychar = yylex()) < 0) yychar = 0;",
216: "#if YYDEBUG",
217: " if (yydebug)",
218: " {",
219: " yys = 0;",
220: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
221: " if (!yys) yys = \"illegal-symbol\";",
222: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
223: " YYPREFIX, yystate, yychar, yys);",
224: " }",
225: "#endif",
226: " }",
227: " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
228: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
229: " {",
230: "#if YYDEBUG",
231: " if (yydebug)",
232: " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
233: " YYPREFIX, yystate, yytable[yyn]);",
234: "#endif",
1.4 deraadt 235: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 236: " {",
237: " goto yyoverflow;",
238: " }",
239: " *++yyssp = yystate = yytable[yyn];",
240: " *++yyvsp = yylval;",
241: " yychar = (-1);",
242: " if (yyerrflag > 0) --yyerrflag;",
243: " goto yyloop;",
244: " }",
245: " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
246: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
247: " {",
248: " yyn = yytable[yyn];",
249: " goto yyreduce;",
250: " }",
251: " if (yyerrflag) goto yyinrecovery;",
1.7 tholo 252: "#if defined(lint) || defined(__GNUC__)",
1.4 deraadt 253: " goto yynewerror;",
254: "#endif",
255: "yynewerror:",
1.1 deraadt 256: " yyerror(\"syntax error\");",
1.7 tholo 257: "#if defined(lint) || defined(__GNUC__)",
1.1 deraadt 258: " goto yyerrlab;",
259: "#endif",
260: "yyerrlab:",
261: " ++yynerrs;",
262: "yyinrecovery:",
263: " if (yyerrflag < 3)",
264: " {",
265: " yyerrflag = 3;",
266: " for (;;)",
267: " {",
268: " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
269: " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
270: " {",
271: "#if YYDEBUG",
272: " if (yydebug)",
273: " printf(\"%sdebug: state %d, error recovery shifting\\",
274: " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
275: "#endif",
1.4 deraadt 276: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 277: " {",
278: " goto yyoverflow;",
279: " }",
280: " *++yyssp = yystate = yytable[yyn];",
281: " *++yyvsp = yylval;",
282: " goto yyloop;",
283: " }",
284: " else",
285: " {",
286: "#if YYDEBUG",
287: " if (yydebug)",
288: " printf(\"%sdebug: error recovery discarding state %d\
289: \\n\",",
290: " YYPREFIX, *yyssp);",
291: "#endif",
292: " if (yyssp <= yyss) goto yyabort;",
293: " --yyssp;",
294: " --yyvsp;",
295: " }",
296: " }",
297: " }",
298: " else",
299: " {",
300: " if (yychar == 0) goto yyabort;",
301: "#if YYDEBUG",
302: " if (yydebug)",
303: " {",
304: " yys = 0;",
305: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
306: " if (!yys) yys = \"illegal-symbol\";",
307: " printf(\"%sdebug: state %d, error recovery discards token %d\
308: (%s)\\n\",",
309: " YYPREFIX, yystate, yychar, yys);",
310: " }",
311: "#endif",
312: " yychar = (-1);",
313: " goto yyloop;",
314: " }",
315: "yyreduce:",
316: "#if YYDEBUG",
317: " if (yydebug)",
318: " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
319: " YYPREFIX, yystate, yyn, yyrule[yyn]);",
320: "#endif",
321: " yym = yylen[yyn];",
322: " yyval = yyvsp[1-yym];",
323: " switch (yyn)",
324: " {",
325: 0
326: };
327:
328:
329: char *trailer[] =
330: {
331: " }",
332: " yyssp -= yym;",
333: " yystate = *yyssp;",
334: " yyvsp -= yym;",
335: " yym = yylhs[yyn];",
336: " if (yystate == 0 && yym == 0)",
337: " {",
338: "#if YYDEBUG",
339: " if (yydebug)",
340: " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
341: " state %d\\n\", YYPREFIX, YYFINAL);",
342: "#endif",
343: " yystate = YYFINAL;",
344: " *++yyssp = YYFINAL;",
345: " *++yyvsp = yyval;",
346: " if (yychar < 0)",
347: " {",
348: " if ((yychar = yylex()) < 0) yychar = 0;",
349: "#if YYDEBUG",
350: " if (yydebug)",
351: " {",
352: " yys = 0;",
353: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
354: " if (!yys) yys = \"illegal-symbol\";",
355: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
356: " YYPREFIX, YYFINAL, yychar, yys);",
357: " }",
358: "#endif",
359: " }",
360: " if (yychar == 0) goto yyaccept;",
361: " goto yyloop;",
362: " }",
363: " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
364: " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
365: " yystate = yytable[yyn];",
366: " else",
367: " yystate = yydgoto[yym];",
368: "#if YYDEBUG",
369: " if (yydebug)",
370: " printf(\"%sdebug: after reduction, shifting from state %d \\",
371: "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
372: "#endif",
1.4 deraadt 373: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 374: " {",
375: " goto yyoverflow;",
376: " }",
377: " *++yyssp = yystate;",
378: " *++yyvsp = yyval;",
379: " goto yyloop;",
380: "yyoverflow:",
381: " yyerror(\"yacc stack overflow\");",
382: "yyabort:",
383: " return (1);",
384: "yyaccept:",
385: " return (0);",
386: "}",
387: 0
388: };
389:
390:
391: write_section(section)
392: char *section[];
393: {
394: register int c;
395: register int i;
396: register char *s;
397: register FILE *f;
398:
399: f = code_file;
400: for (i = 0; s = section[i]; ++i)
401: {
402: ++outline;
403: while (c = *s)
404: {
405: putc(c, f);
406: ++s;
407: }
408: putc('\n', f);
409: }
410: }