Annotation of src/usr.bin/yacc/skeleton.c, Revision 1.10
1.10 ! millert 1: /* $OpenBSD: skeleton.c,v 1.9 1998/04/25 18:52:18 mickey 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.10 ! millert 66: "static char yyrcsid[] = \"$OpenBSD: skeleton.c,v 1.9 1998/04/25 18:52:18 mickey 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: {
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[];",
95: "#endif",
96: 0
97: };
98:
99:
100: char *header[] =
101: {
102: "#ifdef YYSTACKSIZE",
103: "#undef YYMAXDEPTH",
104: "#define YYMAXDEPTH YYSTACKSIZE",
105: "#else",
106: "#ifdef YYMAXDEPTH",
107: "#define YYSTACKSIZE YYMAXDEPTH",
108: "#else",
1.4 deraadt 109: "#define YYSTACKSIZE 10000",
110: "#define YYMAXDEPTH 10000",
1.1 deraadt 111: "#endif",
112: "#endif",
1.4 deraadt 113: "#define YYINITSTACKSIZE 200",
1.1 deraadt 114: "int yydebug;",
115: "int yynerrs;",
116: "int yyerrflag;",
117: "int yychar;",
118: "short *yyssp;",
119: "YYSTYPE *yyvsp;",
120: "YYSTYPE yyval;",
121: "YYSTYPE yylval;",
1.4 deraadt 122: "short *yyss;",
123: "short *yysslim;",
124: "YYSTYPE *yyvs;",
125: "int yystacksize;",
1.1 deraadt 126: 0
127: };
128:
129:
130: char *body[] =
131: {
1.4 deraadt 132: "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
1.5 tholo 133: "#if defined(__cplusplus) || __STDC__",
134: "static int yygrowstack(void)",
135: "#else",
1.4 deraadt 136: "static int yygrowstack()",
1.5 tholo 137: "#endif",
1.4 deraadt 138: "{",
139: " int newsize, i;",
140: " short *newss;",
141: " YYSTYPE *newvs;",
142: "",
143: " if ((newsize = yystacksize) == 0)",
144: " newsize = YYINITSTACKSIZE;",
145: " else if (newsize >= YYMAXDEPTH)",
146: " return -1;",
147: " else if ((newsize *= 2) > YYMAXDEPTH)",
148: " newsize = YYMAXDEPTH;",
149: " i = yyssp - yyss;",
1.10 ! millert 150: " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
! 151: " (short *)malloc(newsize * sizeof *newss);",
! 152: " if (newss == NULL)",
1.4 deraadt 153: " return -1;",
154: " yyss = newss;",
155: " yyssp = newss + i;",
1.10 ! millert 156: " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
! 157: " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
! 158: " if (newvs == NULL)",
1.4 deraadt 159: " return -1;",
160: " yyvs = newvs;",
161: " yyvsp = newvs + i;",
162: " yystacksize = newsize;",
163: " yysslim = yyss + newsize - 1;",
164: " return 0;",
165: "}",
166: "",
1.1 deraadt 167: "#define YYABORT goto yyabort",
168: "#define YYREJECT goto yyabort",
169: "#define YYACCEPT goto yyaccept",
170: "#define YYERROR goto yyerrlab",
171: "int",
1.5 tholo 172: "#if defined(__cplusplus) || __STDC__",
173: "yyparse(void)",
174: "#else",
1.1 deraadt 175: "yyparse()",
1.5 tholo 176: "#endif",
1.1 deraadt 177: "{",
178: " register int yym, yyn, yystate;",
179: "#if YYDEBUG",
180: " register char *yys;",
181: "",
1.6 deraadt 182: " if ((yys = getenv(\"YYDEBUG\")))",
1.1 deraadt 183: " {",
184: " yyn = *yys;",
185: " if (yyn >= '0' && yyn <= '9')",
186: " yydebug = yyn - '0';",
187: " }",
188: "#endif",
189: "",
190: " yynerrs = 0;",
191: " yyerrflag = 0;",
192: " yychar = (-1);",
193: "",
1.4 deraadt 194: " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
1.1 deraadt 195: " yyssp = yyss;",
196: " yyvsp = yyvs;",
197: " *yyssp = yystate = 0;",
198: "",
199: "yyloop:",
200: " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
201: " if (yychar < 0)",
202: " {",
203: " if ((yychar = yylex()) < 0) yychar = 0;",
204: "#if YYDEBUG",
205: " if (yydebug)",
206: " {",
207: " yys = 0;",
208: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
209: " if (!yys) yys = \"illegal-symbol\";",
210: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
211: " YYPREFIX, yystate, yychar, yys);",
212: " }",
213: "#endif",
214: " }",
215: " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
216: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
217: " {",
218: "#if YYDEBUG",
219: " if (yydebug)",
220: " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
221: " YYPREFIX, yystate, yytable[yyn]);",
222: "#endif",
1.4 deraadt 223: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 224: " {",
225: " goto yyoverflow;",
226: " }",
227: " *++yyssp = yystate = yytable[yyn];",
228: " *++yyvsp = yylval;",
229: " yychar = (-1);",
230: " if (yyerrflag > 0) --yyerrflag;",
231: " goto yyloop;",
232: " }",
233: " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
234: " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
235: " {",
236: " yyn = yytable[yyn];",
237: " goto yyreduce;",
238: " }",
239: " if (yyerrflag) goto yyinrecovery;",
1.7 tholo 240: "#if defined(lint) || defined(__GNUC__)",
1.4 deraadt 241: " goto yynewerror;",
242: "#endif",
243: "yynewerror:",
1.1 deraadt 244: " yyerror(\"syntax error\");",
1.7 tholo 245: "#if defined(lint) || defined(__GNUC__)",
1.1 deraadt 246: " goto yyerrlab;",
247: "#endif",
248: "yyerrlab:",
249: " ++yynerrs;",
250: "yyinrecovery:",
251: " if (yyerrflag < 3)",
252: " {",
253: " yyerrflag = 3;",
254: " for (;;)",
255: " {",
256: " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
257: " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
258: " {",
259: "#if YYDEBUG",
260: " if (yydebug)",
261: " printf(\"%sdebug: state %d, error recovery shifting\\",
262: " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
263: "#endif",
1.4 deraadt 264: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 265: " {",
266: " goto yyoverflow;",
267: " }",
268: " *++yyssp = yystate = yytable[yyn];",
269: " *++yyvsp = yylval;",
270: " goto yyloop;",
271: " }",
272: " else",
273: " {",
274: "#if YYDEBUG",
275: " if (yydebug)",
276: " printf(\"%sdebug: error recovery discarding state %d\
277: \\n\",",
278: " YYPREFIX, *yyssp);",
279: "#endif",
280: " if (yyssp <= yyss) goto yyabort;",
281: " --yyssp;",
282: " --yyvsp;",
283: " }",
284: " }",
285: " }",
286: " else",
287: " {",
288: " if (yychar == 0) goto yyabort;",
289: "#if YYDEBUG",
290: " if (yydebug)",
291: " {",
292: " yys = 0;",
293: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
294: " if (!yys) yys = \"illegal-symbol\";",
295: " printf(\"%sdebug: state %d, error recovery discards token %d\
296: (%s)\\n\",",
297: " YYPREFIX, yystate, yychar, yys);",
298: " }",
299: "#endif",
300: " yychar = (-1);",
301: " goto yyloop;",
302: " }",
303: "yyreduce:",
304: "#if YYDEBUG",
305: " if (yydebug)",
306: " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
307: " YYPREFIX, yystate, yyn, yyrule[yyn]);",
308: "#endif",
309: " yym = yylen[yyn];",
310: " yyval = yyvsp[1-yym];",
311: " switch (yyn)",
312: " {",
313: 0
314: };
315:
316:
317: char *trailer[] =
318: {
319: " }",
320: " yyssp -= yym;",
321: " yystate = *yyssp;",
322: " yyvsp -= yym;",
323: " yym = yylhs[yyn];",
324: " if (yystate == 0 && yym == 0)",
325: " {",
326: "#if YYDEBUG",
327: " if (yydebug)",
328: " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
329: " state %d\\n\", YYPREFIX, YYFINAL);",
330: "#endif",
331: " yystate = YYFINAL;",
332: " *++yyssp = YYFINAL;",
333: " *++yyvsp = yyval;",
334: " if (yychar < 0)",
335: " {",
336: " if ((yychar = yylex()) < 0) yychar = 0;",
337: "#if YYDEBUG",
338: " if (yydebug)",
339: " {",
340: " yys = 0;",
341: " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
342: " if (!yys) yys = \"illegal-symbol\";",
343: " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
344: " YYPREFIX, YYFINAL, yychar, yys);",
345: " }",
346: "#endif",
347: " }",
348: " if (yychar == 0) goto yyaccept;",
349: " goto yyloop;",
350: " }",
351: " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
352: " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
353: " yystate = yytable[yyn];",
354: " else",
355: " yystate = yydgoto[yym];",
356: "#if YYDEBUG",
357: " if (yydebug)",
358: " printf(\"%sdebug: after reduction, shifting from state %d \\",
359: "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
360: "#endif",
1.4 deraadt 361: " if (yyssp >= yysslim && yygrowstack())",
1.1 deraadt 362: " {",
363: " goto yyoverflow;",
364: " }",
365: " *++yyssp = yystate;",
366: " *++yyvsp = yyval;",
367: " goto yyloop;",
368: "yyoverflow:",
369: " yyerror(\"yacc stack overflow\");",
370: "yyabort:",
371: " return (1);",
372: "yyaccept:",
373: " return (0);",
374: "}",
375: 0
376: };
377:
378:
379: write_section(section)
380: char *section[];
381: {
382: register int c;
383: register int i;
384: register char *s;
385: register FILE *f;
386:
387: f = code_file;
388: for (i = 0; s = section[i]; ++i)
389: {
390: ++outline;
391: while (c = *s)
392: {
393: putc(c, f);
394: ++s;
395: }
396: putc('\n', f);
397: }
398: }