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>",
63 "#include <string.h>",
69 "yyrcsid[] = \"$FreeBSD$\";",
74 "#define YYLEX yylex()",
76 "#define yyclearin (yychar=(YYEMPTY))",
77 "#define yyerrok (yyerrflag=0)",
78 "#define YYRECOVERING() (yyerrflag!=0)",
79 "#if defined(__cplusplus) || __STDC__",
80 "static int yygrowstack(void);",
82 "static int yygrowstack();",
88 const char *tables[] =
90 "extern const short yylhs[];",
91 "extern const short yylen[];",
92 "extern const short yydefred[];",
93 "extern const short yydgoto[];",
94 "extern const short yysindex[];",
95 "extern const short yyrindex[];",
96 "extern const short yygindex[];",
97 "extern const short yytable[];",
98 "extern const short yycheck[];",
100 "extern char *yyname[];",
101 "extern char *yyrule[];",
107 const char *header[] =
110 "#include <stdio.h>",
112 "#ifdef YYSTACKSIZE",
114 "#define YYMAXDEPTH YYSTACKSIZE",
117 "#define YYSTACKSIZE YYMAXDEPTH",
119 "#define YYSTACKSIZE 10000",
120 "#define YYMAXDEPTH 10000",
123 "#define YYINITSTACKSIZE 200",
142 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
143 "#if defined(__cplusplus) || __STDC__",
144 "static int yygrowstack(void)",
146 "static int yygrowstack()",
153 " if ((newsize = yystacksize) == 0)",
154 " newsize = YYINITSTACKSIZE;",
155 " else if (newsize >= YYMAXDEPTH)",
157 " else if ((newsize *= 2) > YYMAXDEPTH)",
158 " newsize = YYMAXDEPTH;",
159 " i = yyssp - yyss;",
160 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
161 " (short *)malloc(newsize * sizeof *newss);",
162 " if (newss == NULL)",
165 " yyssp = newss + i;",
166 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
167 " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
168 " if (newvs == NULL)",
171 " yyvsp = newvs + i;",
172 " yystacksize = newsize;",
173 " yysslim = yyss + newsize - 1;",
177 "#define YYABORT goto yyabort",
178 "#define YYREJECT goto yyabort",
179 "#define YYACCEPT goto yyaccept",
180 "#define YYERROR goto yyerrlab",
182 "#ifndef YYPARSE_PARAM",
183 "#if defined(__cplusplus) || __STDC__",
184 "#define YYPARSE_PARAM_ARG void",
185 "#define YYPARSE_PARAM_DECL",
186 "#else /* ! ANSI-C/C++ */",
187 "#define YYPARSE_PARAM_ARG",
188 "#define YYPARSE_PARAM_DECL",
189 "#endif /* ANSI-C/C++ */",
190 "#else /* YYPARSE_PARAM */",
191 "#ifndef YYPARSE_PARAM_TYPE",
192 "#define YYPARSE_PARAM_TYPE void *",
194 "#if defined(__cplusplus) || __STDC__",
195 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
196 "#define YYPARSE_PARAM_DECL",
197 "#else /* ! ANSI-C/C++ */",
198 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
199 "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
200 "#endif /* ANSI-C/C++ */",
201 "#endif /* ! YYPARSE_PARAM */",
204 "yyparse (YYPARSE_PARAM_ARG)",
205 " YYPARSE_PARAM_DECL",
207 " int yym, yyn, yystate;",
211 " if ((yys = getenv(\"YYDEBUG\")))",
214 " if (yyn >= '0' && yyn <= '9')",
215 " yydebug = yyn - '0';",
223 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
226 " *yyssp = yystate = 0;",
229 " if ((yyn = yydefred[yystate])) goto yyreduce;",
232 " if ((yychar = yylex()) < 0) yychar = 0;",
237 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
238 " if (!yys) yys = \"illegal-symbol\";",
239 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
240 " YYPREFIX, yystate, yychar, yys);",
244 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
245 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
249 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
250 " YYPREFIX, yystate, yytable[yyn]);",
252 " if (yyssp >= yysslim && yygrowstack())",
256 " *++yyssp = yystate = yytable[yyn];",
257 " *++yyvsp = yylval;",
259 " if (yyerrflag > 0) --yyerrflag;",
262 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
263 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
265 " yyn = yytable[yyn];",
268 " if (yyerrflag) goto yyinrecovery;",
269 "#if defined(lint) || defined(__GNUC__)",
273 " yyerror(\"syntax error\");",
274 "#if defined(lint) || defined(__GNUC__)",
280 " if (yyerrflag < 3)",
285 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
286 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
290 " printf(\"%sdebug: state %d, error recovery shifting\\",
291 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
293 " if (yyssp >= yysslim && yygrowstack())",
297 " *++yyssp = yystate = yytable[yyn];",
298 " *++yyvsp = yylval;",
305 " printf(\"%sdebug: error recovery discarding state %d\
307 " YYPREFIX, *yyssp);",
309 " if (yyssp <= yyss) goto yyabort;",
317 " if (yychar == 0) goto yyabort;",
322 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
323 " if (!yys) yys = \"illegal-symbol\";",
324 " printf(\"%sdebug: state %d, error recovery discards token %d\
326 " YYPREFIX, yystate, yychar, yys);",
335 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
336 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
338 " yym = yylen[yyn];",
340 " yyval = yyvsp[1-yym];",
342 " memset(&yyval, 0, sizeof yyval);",
349 const char *trailer[] =
353 " yystate = *yyssp;",
355 " yym = yylhs[yyn];",
356 " if (yystate == 0 && yym == 0)",
360 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
361 " state %d\\n\", YYPREFIX, YYFINAL);",
363 " yystate = YYFINAL;",
364 " *++yyssp = YYFINAL;",
365 " *++yyvsp = yyval;",
368 " if ((yychar = yylex()) < 0) yychar = 0;",
373 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
374 " if (!yys) yys = \"illegal-symbol\";",
375 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
376 " YYPREFIX, YYFINAL, yychar, yys);",
380 " if (yychar == 0) goto yyaccept;",
383 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
384 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
385 " yystate = yytable[yyn];",
387 " yystate = yydgoto[yym];",
390 " printf(\"%sdebug: after reduction, shifting from state %d \\",
391 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
393 " if (yyssp >= yysslim && yygrowstack())",
397 " *++yyssp = yystate;",
398 " *++yyvsp = yyval;",
401 " yyerror(\"yacc stack overflow\");",
412 write_section(section)
413 const char *section[];
421 for (i = 0; (s = section[i]); ++i)