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 "static int yygrowstack()",
149 " if ((newsize = yystacksize) == 0)",
150 " newsize = YYINITSTACKSIZE;",
151 " else if (newsize >= YYMAXDEPTH)",
153 " else if ((newsize *= 2) > YYMAXDEPTH)",
154 " newsize = YYMAXDEPTH;",
155 " i = yyssp - yyss;",
156 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
157 " (short *)malloc(newsize * sizeof *newss);",
158 " if (newss == NULL)",
161 " yyssp = newss + i;",
162 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
163 " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
164 " if (newvs == NULL)",
167 " yyvsp = newvs + i;",
168 " yystacksize = newsize;",
169 " yysslim = yyss + newsize - 1;",
173 "#define YYABORT goto yyabort",
174 "#define YYREJECT goto yyabort",
175 "#define YYACCEPT goto yyaccept",
176 "#define YYERROR goto yyerrlab",
178 "#ifndef YYPARSE_PARAM",
179 "#if defined(__cplusplus) || __STDC__",
180 "#define YYPARSE_PARAM_ARG void",
181 "#define YYPARSE_PARAM_DECL",
182 "#else /* ! ANSI-C/C++ */",
183 "#define YYPARSE_PARAM_ARG",
184 "#define YYPARSE_PARAM_DECL",
185 "#endif /* ANSI-C/C++ */",
186 "#else /* YYPARSE_PARAM */",
187 "#ifndef YYPARSE_PARAM_TYPE",
188 "#define YYPARSE_PARAM_TYPE void *",
190 "#if defined(__cplusplus) || __STDC__",
191 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
192 "#define YYPARSE_PARAM_DECL",
193 "#else /* ! ANSI-C/C++ */",
194 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
195 "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
196 "#endif /* ANSI-C/C++ */",
197 "#endif /* ! YYPARSE_PARAM */",
200 "yyparse (YYPARSE_PARAM_ARG)",
201 " YYPARSE_PARAM_DECL",
203 " int yym, yyn, yystate;",
207 " if ((yys = getenv(\"YYDEBUG\")))",
210 " if (yyn >= '0' && yyn <= '9')",
211 " yydebug = yyn - '0';",
219 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
222 " *yyssp = yystate = 0;",
225 " if ((yyn = yydefred[yystate])) goto yyreduce;",
228 " if ((yychar = yylex()) < 0) yychar = 0;",
233 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
234 " if (!yys) yys = \"illegal-symbol\";",
235 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
236 " YYPREFIX, yystate, yychar, yys);",
240 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
241 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
245 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
246 " YYPREFIX, yystate, yytable[yyn]);",
248 " if (yyssp >= yysslim && yygrowstack())",
252 " *++yyssp = yystate = yytable[yyn];",
253 " *++yyvsp = yylval;",
255 " if (yyerrflag > 0) --yyerrflag;",
258 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
259 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
261 " yyn = yytable[yyn];",
264 " if (yyerrflag) goto yyinrecovery;",
265 "#if defined(lint) || defined(__GNUC__)",
269 " yyerror(\"syntax error\");",
270 "#if defined(lint) || defined(__GNUC__)",
276 " if (yyerrflag < 3)",
281 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
282 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
286 " printf(\"%sdebug: state %d, error recovery shifting\\",
287 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
289 " if (yyssp >= yysslim && yygrowstack())",
293 " *++yyssp = yystate = yytable[yyn];",
294 " *++yyvsp = yylval;",
301 " printf(\"%sdebug: error recovery discarding state %d\
303 " YYPREFIX, *yyssp);",
305 " if (yyssp <= yyss) goto yyabort;",
313 " if (yychar == 0) goto yyabort;",
318 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
319 " if (!yys) yys = \"illegal-symbol\";",
320 " printf(\"%sdebug: state %d, error recovery discards token %d\
322 " YYPREFIX, yystate, yychar, yys);",
331 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
332 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
334 " yym = yylen[yyn];",
336 " yyval = yyvsp[1-yym];",
338 " memset(&yyval, 0, sizeof yyval);",
345 const char *trailer[] =
349 " yystate = *yyssp;",
351 " yym = yylhs[yyn];",
352 " if (yystate == 0 && yym == 0)",
356 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
357 " state %d\\n\", YYPREFIX, YYFINAL);",
359 " yystate = YYFINAL;",
360 " *++yyssp = YYFINAL;",
361 " *++yyvsp = yyval;",
364 " if ((yychar = yylex()) < 0) yychar = 0;",
369 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
370 " if (!yys) yys = \"illegal-symbol\";",
371 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
372 " YYPREFIX, YYFINAL, yychar, yys);",
376 " if (yychar == 0) goto yyaccept;",
379 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
380 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
381 " yystate = yytable[yyn];",
383 " yystate = yydgoto[yym];",
386 " printf(\"%sdebug: after reduction, shifting from state %d \\",
387 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
389 " if (yyssp >= yysslim && yygrowstack())",
393 " *++yyssp = yystate;",
394 " *++yyvsp = yyval;",
397 " yyerror(\"yacc stack overflow\");",
408 write_section(section)
409 const char *section[];
417 for (i = 0; (s = section[i]); ++i)