1 /* $NetBSD: skeleton.c,v 1.28 2008/07/18 09:57:15 dsl Exp $ */
4 * Copyright (c) 1989 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 #if defined(__RCSID) && !defined(lint)
38 static char sccsid
[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95";
40 __RCSID("$NetBSD: skeleton.c,v 1.28 2008/07/18 09:57:15 dsl Exp $");
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. */
50 /* If the skeleton is changed, the banner should be changed so that */
51 /* the altered version can be easily distinguished from the original. */
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. */
58 const char * const banner
[] =
60 "#include <stdlib.h>",
63 "static char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
65 "#if defined(__NetBSD__) && defined(__IDSTRING)",
66 "__IDSTRING(yyrcsid, \"$NetBSD: skeleton.c,v 1.28 2008/07/18 09:57:15 dsl Exp $\");",
67 "#endif /* __NetBSD__ && __IDSTRING */",
73 "#define YYLEX yylex()",
75 "#define yyclearin (yychar=(YYEMPTY))",
76 "#define yyerrok (yyerrflag=0)",
77 "#define YYRECOVERING (yyerrflag!=0)",
82 const char * const tables
[] =
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[];",
94 "extern const char * const yyname[];",
95 "extern const char * const yyrule[];",
101 const char * const header
[] =
103 "#ifdef YYSTACKSIZE",
105 "#define YYMAXDEPTH YYSTACKSIZE",
108 "#define YYSTACKSIZE YYMAXDEPTH",
110 "#define YYSTACKSIZE 10000",
111 "#define YYMAXDEPTH 10000",
114 "#define YYINITSTACKSIZE 200",
122 "static YYSTYPE yyvalzero;", /* no "const", must compile as C++ */
128 "int yyparse(void);",
133 const char * const body
[] =
135 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
136 "static int yygrowstack(void);",
137 "static int yygrowstack(void)",
143 " if ((newsize = yystacksize) == 0)",
144 " newsize = YYINITSTACKSIZE;",
145 " else if (newsize >= YYMAXDEPTH)",
147 " else if ((newsize *= 2) > YYMAXDEPTH)",
148 " newsize = YYMAXDEPTH;",
149 " i = yyssp - yyss;",
150 " if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)",
153 " yyssp = newss + i;",
154 " if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)",
157 " yyvsp = newvs + i;",
158 " yystacksize = newsize;",
159 " yysslim = yyss + newsize - 1;",
163 "#define YYABORT goto yyabort",
164 "#define YYREJECT goto yyabort",
165 "#define YYACCEPT goto yyaccept",
166 "#define YYERROR goto yyerrlab",
170 " int yym, yyn, yystate;",
174 " if ((yys = getenv(\"YYDEBUG\")) != NULL)",
177 " if (yyn >= '0' && yyn <= '9')",
178 " yydebug = yyn - '0';",
186 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
189 " *yyssp = yystate = 0;",
192 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
195 " if ((yychar = yylex()) < 0) yychar = 0;",
200 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
201 " if (!yys) yys = \"illegal-symbol\";",
202 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
203 " YYPREFIX, yystate, yychar, yys);",
207 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
208 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
212 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
213 " YYPREFIX, yystate, yytable[yyn]);",
215 " if (yyssp >= yysslim && yygrowstack())",
219 " *++yyssp = yystate = yytable[yyn];",
220 " *++yyvsp = yylval;",
222 " if (yyerrflag > 0) --yyerrflag;",
225 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
226 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
228 " yyn = yytable[yyn];",
231 " if (yyerrflag) goto yyinrecovery;",
234 " yyerror(\"syntax error\");",
239 " if (yyerrflag < 3)",
244 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
245 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
249 " printf(\"%sdebug: state %d, error recovery shifting\\",
250 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
252 " if (yyssp >= yysslim && yygrowstack())",
256 " *++yyssp = yystate = yytable[yyn];",
257 " *++yyvsp = yylval;",
264 " printf(\"%sdebug: error recovery discarding state %d\
266 " YYPREFIX, *yyssp);",
268 " if (yyssp <= yyss) goto yyabort;",
276 " if (yychar == 0) goto yyabort;",
281 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
282 " if (!yys) yys = \"illegal-symbol\";",
283 " printf(\"%sdebug: state %d, error recovery discards token %d\
285 " YYPREFIX, yystate, yychar, yys);",
294 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
295 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
297 " yym = yylen[yyn];",
299 " yyval = yyvsp[1-yym];",
301 " yyval = yyvalzero;",
308 const char * const trailer
[] =
312 " yystate = *yyssp;",
314 " yym = yylhs[yyn];",
315 " if (yystate == 0 && yym == 0)",
319 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
320 " state %d\\n\", YYPREFIX, YYFINAL);",
322 " yystate = YYFINAL;",
323 " *++yyssp = YYFINAL;",
324 " *++yyvsp = yyval;",
327 " if ((yychar = yylex()) < 0) yychar = 0;",
332 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
333 " if (!yys) yys = \"illegal-symbol\";",
334 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
335 " YYPREFIX, YYFINAL, yychar, yys);",
339 " if (yychar == 0) goto yyaccept;",
342 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
343 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
344 " yystate = yytable[yyn];",
346 " yystate = yydgoto[yym];",
349 " printf(\"%sdebug: after reduction, shifting from state %d \\",
350 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
352 " if (yyssp >= yysslim && yygrowstack())",
356 " *++yyssp = yystate;",
357 " *++yyvsp = yyval;",
360 " yyerror(\"yacc stack overflow\");",
371 write_section(const char * const section
[])
379 for (i
= 0; (s
= section
[i
]); ++i
)
382 while ((c
= *s
) != '\0')