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