2 * Copyright (c) 1989 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static char sccsid[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95";
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
48 /* The definition of yysccsid in the banner should be replaced with */
49 /* a #pragma ident directive if the target C compiler supports */
50 /* #pragma ident directives. */
52 /* If the skeleton is changed, the banner should be changed so that */
53 /* the altered version can be easily distinguished from the original. */
55 /* The #defines included with the banner are there because they are */
56 /* useful in subsequent code. The macros #defined in the header or */
57 /* the body either are not useful outside of semantic actions or */
58 /* are conditional. */
60 const char *banner[] =
62 "#include <stdlib.h>",
68 "yyrcsid[] = \"$FreeBSD$\";",
73 "#define YYLEX yylex()",
75 "#define yyclearin (yychar=(YYEMPTY))",
76 "#define yyerrok (yyerrflag=0)",
77 "#define YYRECOVERING() (yyerrflag!=0)",
78 "#if defined(__cplusplus) || __STDC__",
79 "static int yygrowstack(void);",
81 "static int yygrowstack();",
87 const char *tables[] =
89 "extern const short yylhs[];",
90 "extern const short yylen[];",
91 "extern const short yydefred[];",
92 "extern const short yydgoto[];",
93 "extern const short yysindex[];",
94 "extern const short yyrindex[];",
95 "extern const short yygindex[];",
96 "extern const short yytable[];",
97 "extern const short yycheck[];",
99 "extern char *yyname[];",
100 "extern char *yyrule[];",
106 const char *header[] =
109 "#include <stdio.h>",
111 "#ifdef YYSTACKSIZE",
113 "#define YYMAXDEPTH YYSTACKSIZE",
116 "#define YYSTACKSIZE YYMAXDEPTH",
118 "#define YYSTACKSIZE 10000",
119 "#define YYMAXDEPTH 10000",
122 "#define YYINITSTACKSIZE 200",
141 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
142 "static int yygrowstack()",
148 " if ((newsize = yystacksize) == 0)",
149 " newsize = YYINITSTACKSIZE;",
150 " else if (newsize >= YYMAXDEPTH)",
152 " else if ((newsize *= 2) > YYMAXDEPTH)",
153 " newsize = YYMAXDEPTH;",
154 " i = yyssp - yyss;",
155 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
156 " (short *)malloc(newsize * sizeof *newss);",
157 " if (newss == NULL)",
160 " yyssp = newss + i;",
161 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
162 " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
163 " if (newvs == NULL)",
166 " yyvsp = newvs + i;",
167 " yystacksize = newsize;",
168 " yysslim = yyss + newsize - 1;",
172 "#define YYABORT goto yyabort",
173 "#define YYREJECT goto yyabort",
174 "#define YYACCEPT goto yyaccept",
175 "#define YYERROR goto yyerrlab",
177 "#ifndef YYPARSE_PARAM",
178 "#if defined(__cplusplus) || __STDC__",
179 "#define YYPARSE_PARAM_ARG void",
180 "#define YYPARSE_PARAM_DECL",
181 "#else /* ! ANSI-C/C++ */",
182 "#define YYPARSE_PARAM_ARG",
183 "#define YYPARSE_PARAM_DECL",
184 "#endif /* ANSI-C/C++ */",
185 "#else /* YYPARSE_PARAM */",
186 "#ifndef YYPARSE_PARAM_TYPE",
187 "#define YYPARSE_PARAM_TYPE void *",
189 "#if defined(__cplusplus) || __STDC__",
190 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
191 "#define YYPARSE_PARAM_DECL",
192 "#else /* ! ANSI-C/C++ */",
193 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
194 "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
195 "#endif /* ANSI-C/C++ */",
196 "#endif /* ! YYPARSE_PARAM */",
199 "yyparse (YYPARSE_PARAM_ARG)",
200 " YYPARSE_PARAM_DECL",
202 " int yym, yyn, yystate;",
206 " if ((yys = getenv(\"YYDEBUG\")))",
209 " if (yyn >= '0' && yyn <= '9')",
210 " yydebug = yyn - '0';",
218 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
221 " *yyssp = yystate = 0;",
224 " if ((yyn = yydefred[yystate])) goto yyreduce;",
227 " if ((yychar = yylex()) < 0) yychar = 0;",
232 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
233 " if (!yys) yys = \"illegal-symbol\";",
234 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
235 " YYPREFIX, yystate, yychar, yys);",
239 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
240 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
244 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
245 " YYPREFIX, yystate, yytable[yyn]);",
247 " if (yyssp >= yysslim && yygrowstack())",
251 " *++yyssp = yystate = yytable[yyn];",
252 " *++yyvsp = yylval;",
254 " if (yyerrflag > 0) --yyerrflag;",
257 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
258 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
260 " yyn = yytable[yyn];",
263 " if (yyerrflag) goto yyinrecovery;",
264 "#if defined(lint) || defined(__GNUC__)",
268 " yyerror(\"syntax error\");",
269 "#if defined(lint) || defined(__GNUC__)",
275 " if (yyerrflag < 3)",
280 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
281 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
285 " printf(\"%sdebug: state %d, error recovery shifting\\",
286 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
288 " if (yyssp >= yysslim && yygrowstack())",
292 " *++yyssp = yystate = yytable[yyn];",
293 " *++yyvsp = yylval;",
300 " printf(\"%sdebug: error recovery discarding state %d\
302 " YYPREFIX, *yyssp);",
304 " if (yyssp <= yyss) goto yyabort;",
312 " if (yychar == 0) goto yyabort;",
317 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
318 " if (!yys) yys = \"illegal-symbol\";",
319 " printf(\"%sdebug: state %d, error recovery discards token %d\
321 " YYPREFIX, yystate, yychar, yys);",
330 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
331 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
333 " yym = yylen[yyn];",
334 " yyval = yyvsp[1-yym];",
341 const char *trailer[] =
345 " yystate = *yyssp;",
347 " yym = yylhs[yyn];",
348 " if (yystate == 0 && yym == 0)",
352 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
353 " state %d\\n\", YYPREFIX, YYFINAL);",
355 " yystate = YYFINAL;",
356 " *++yyssp = YYFINAL;",
357 " *++yyvsp = yyval;",
360 " if ((yychar = yylex()) < 0) yychar = 0;",
365 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
366 " if (!yys) yys = \"illegal-symbol\";",
367 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
368 " YYPREFIX, YYFINAL, yychar, yys);",
372 " if (yychar == 0) goto yyaccept;",
375 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
376 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
377 " yystate = yytable[yyn];",
379 " yystate = yydgoto[yym];",
382 " printf(\"%sdebug: after reduction, shifting from state %d \\",
383 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
385 " if (yyssp >= yysslim && yygrowstack())",
389 " *++yyssp = yystate;",
390 " *++yyvsp = yyval;",
393 " yyerror(\"yacc stack overflow\");",
404 write_section(section)
405 const char *section[];
413 for (i = 0; (s = section[i]); ++i)