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