1 /* $OpenBSD: skeleton.c,v 1.39 2015/12/31 23:22:39 guenther Exp $ */
2 /* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */
5 * Copyright (c) 1989 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
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
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. */
42 /* If the skeleton is changed, the banner should be changed so that */
43 /* the altered version can be easily distinguished from the original. */
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. */
52 "#include <stdlib.h>",
53 "#include <string.h>",
57 "#define YYLEX yylex()",
59 "#define yyclearin (yychar=(YYEMPTY))",
60 "#define yyerrok (yyerrflag=0)",
61 "#define YYRECOVERING() (yyerrflag!=0)",
68 "extern const short yylhs[];",
69 "extern const short yylen[];",
70 "extern const short yydefred[];",
71 "extern const short yydgoto[];",
72 "extern const short yysindex[];",
73 "extern const short yyrindex[];",
74 "extern const short yygindex[];",
75 "extern const short yytable[];",
76 "extern const short yycheck[];",
78 "extern const char *const yyname[];",
79 "extern const char *const yyrule[];",
89 "#define YYMAXDEPTH YYSTACKSIZE",
92 "#define YYSTACKSIZE YYMAXDEPTH",
94 "#define YYSTACKSIZE 10000",
95 "#define YYMAXDEPTH 10000",
98 "#define YYINITSTACKSIZE 200",
111 "unsigned int yystacksize;",
112 "int yyparse(void);",
119 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
120 "static int yygrowstack(void)",
122 " unsigned int newsize;",
127 " if ((newsize = yystacksize) == 0)",
128 " newsize = YYINITSTACKSIZE;",
129 " else if (newsize >= YYMAXDEPTH)",
131 " else if ((newsize *= 2) > YYMAXDEPTH)",
132 " newsize = YYMAXDEPTH;",
133 " sslen = yyssp - yyss;",
135 "#define YY_SIZE_MAX SIZE_MAX",
137 "#define YY_SIZE_MAX 0xffffffffU",
139 " if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)",
141 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
142 " (short *)malloc(newsize * sizeof *newss); /* overflow check above */",
143 " if (newss == NULL)",
146 " yyssp = newss + sslen;",
147 " if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)",
149 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
150 " (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */",
151 " if (newvs == NULL)",
154 " yyvsp = newvs + sslen;",
155 " yystacksize = newsize;",
156 " yysslim = yyss + newsize - 1;",
163 " yyss = yyssp = NULL;",
164 " yyvs = yyvsp = NULL;",
169 "#define YYABORT goto yyabort",
170 "#define YYREJECT goto yyabort",
171 "#define YYACCEPT goto yyaccept",
172 "#define YYERROR goto yyerrlab",
176 " int yym, yyn, yystate;",
180 " if ((yys = getenv(\"YYDEBUG\")))",
183 " if (yyn >= '0' && yyn <= '9')",
184 " yydebug = yyn - '0';",
186 "#endif /* YYDEBUG */",
192 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
195 " *yyssp = yystate = 0;",
198 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
201 " if ((yychar = yylex()) < 0) yychar = 0;",
206 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
207 " if (!yys) yys = \"illegal-symbol\";",
208 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
209 " YYPREFIX, yystate, yychar, yys);",
213 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
214 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
218 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
219 " YYPREFIX, yystate, yytable[yyn]);",
221 " if (yyssp >= yysslim && yygrowstack())",
225 " *++yyssp = yystate = yytable[yyn];",
226 " *++yyvsp = yylval;",
228 " if (yyerrflag > 0) --yyerrflag;",
231 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
232 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
234 " yyn = yytable[yyn];",
237 " if (yyerrflag) goto yyinrecovery;",
238 "#if defined(__GNUC__)",
242 " yyerror(\"syntax error\");",
243 "#if defined(__GNUC__)",
249 " if (yyerrflag < 3)",
254 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
255 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
259 " printf(\"%sdebug: state %d, error recovery shifting\\",
260 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
262 " if (yyssp >= yysslim && yygrowstack())",
266 " *++yyssp = yystate = yytable[yyn];",
267 " *++yyvsp = yylval;",
274 " printf(\"%sdebug: error recovery discarding state %d\
276 " YYPREFIX, *yyssp);",
278 " if (yyssp <= yyss) goto yyabort;",
286 " if (yychar == 0) goto yyabort;",
291 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
292 " if (!yys) yys = \"illegal-symbol\";",
293 " printf(\"%sdebug: state %d, error recovery discards token %d\
295 " YYPREFIX, yystate, yychar, yys);",
304 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
305 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
307 " yym = yylen[yyn];",
309 " yyval = yyvsp[1-yym];",
311 " memset(&yyval, 0, sizeof yyval);",
322 " yystate = *yyssp;",
324 " yym = yylhs[yyn];",
325 " if (yystate == 0 && yym == 0)",
329 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
330 " state %d\\n\", YYPREFIX, YYFINAL);",
332 " yystate = YYFINAL;",
333 " *++yyssp = YYFINAL;",
334 " *++yyvsp = yyval;",
337 " if ((yychar = yylex()) < 0) yychar = 0;",
342 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
343 " if (!yys) yys = \"illegal-symbol\";",
344 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
345 " YYPREFIX, YYFINAL, yychar, yys);",
349 " if (yychar == 0) goto yyaccept;",
352 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
353 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
354 " yystate = yytable[yyn];",
356 " yystate = yydgoto[yym];",
359 " printf(\"%sdebug: after reduction, shifting from state %d \\",
360 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
362 " if (yyssp >= yysslim && yygrowstack())",
366 " *++yyssp = yystate;",
367 " *++yyvsp = yyval;",
370 " yyerror(\"yacc stack overflow\");",
376 " yyss = yyssp = NULL;",
377 " yyvs = yyvsp = NULL;",
385 " yyss = yyssp = NULL;",
386 " yyvs = yyvsp = NULL;",
395 write_section(char *section
[])
400 for (i
= 0; (s
= section
[i
]); ++i
) {
403 putc('\n', code_file
);