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
36 * @(#)skeleton.c 5.8 (Berkeley) 4/29/95
38 * $FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28.2.1 2001/07/19 05:46:39 peter Exp $
39 * $DragonFly: src/usr.bin/yacc/skeleton.c,v 1.4 2004/04/07 20:43:24 cpressey Exp $
44 /* The definition of yysccsid in the banner should be replaced with */
45 /* a #pragma ident directive if the target C compiler supports */
46 /* #pragma ident directives. */
48 /* If the skeleton is changed, the banner should be changed so that */
49 /* the altered version can be easily distinguished from the original. */
51 /* The #defines included with the banner are there because they are */
52 /* useful in subsequent code. The macros #defined in the header or */
53 /* the body either are not useful outside of semantic actions or */
54 /* are conditional. */
58 "#include <stdlib.h>",
62 "#define YYLEX yylex()",
64 "#define yyclearin (yychar=(YYEMPTY))",
65 "#define yyerrok (yyerrflag=0)",
66 "#define YYRECOVERING() (yyerrflag!=0)",
67 "#if defined(__cplusplus) || __STDC__",
68 "static int yygrowstack(void);",
70 "static int yygrowstack();",
78 "extern const short yylhs[];",
79 "extern const short yylen[];",
80 "extern const short yydefred[];",
81 "extern const short yydgoto[];",
82 "extern const short yysindex[];",
83 "extern const short yyrindex[];",
84 "extern const short yygindex[];",
85 "extern const short yytable[];",
86 "extern const short yycheck[];",
88 "extern char *yyname[];",
89 "extern char *yyrule[];",
100 "#ifdef YYSTACKSIZE",
102 "#define YYMAXDEPTH YYSTACKSIZE",
105 "#define YYSTACKSIZE YYMAXDEPTH",
107 "#define YYSTACKSIZE 10000",
108 "#define YYMAXDEPTH 10000",
111 "#define YYINITSTACKSIZE 200",
130 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
131 "static int yygrowstack()",
137 " if ((newsize = yystacksize) == 0)",
138 " newsize = YYINITSTACKSIZE;",
139 " else if (newsize >= YYMAXDEPTH)",
141 " else if ((newsize *= 2) > YYMAXDEPTH)",
142 " newsize = YYMAXDEPTH;",
143 " i = yyssp - yyss;",
144 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
145 " (short *)malloc(newsize * sizeof *newss);",
146 " if (newss == NULL)",
149 " yyssp = newss + i;",
150 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
151 " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
152 " if (newvs == NULL)",
155 " yyvsp = newvs + i;",
156 " yystacksize = newsize;",
157 " yysslim = yyss + newsize - 1;",
161 "#define YYABORT goto yyabort",
162 "#define YYREJECT goto yyabort",
163 "#define YYACCEPT goto yyaccept",
164 "#define YYERROR goto yyerrlab",
166 "#ifndef YYPARSE_PARAM",
167 "#if defined(__cplusplus) || __STDC__",
168 "#define YYPARSE_PARAM_ARG void",
169 "#define YYPARSE_PARAM_DECL",
170 "#else /* ! ANSI-C/C++ */",
171 "#define YYPARSE_PARAM_ARG",
172 "#define YYPARSE_PARAM_DECL",
173 "#endif /* ANSI-C/C++ */",
174 "#else /* YYPARSE_PARAM */",
175 "#ifndef YYPARSE_PARAM_TYPE",
176 "#define YYPARSE_PARAM_TYPE void *",
178 "#if defined(__cplusplus) || __STDC__",
179 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
180 "#define YYPARSE_PARAM_DECL",
181 "#else /* ! ANSI-C/C++ */",
182 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
183 "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
184 "#endif /* ANSI-C/C++ */",
185 "#endif /* ! YYPARSE_PARAM */",
188 "yyparse (YYPARSE_PARAM_ARG)",
189 " YYPARSE_PARAM_DECL",
191 " int yym, yyn, yystate;",
195 " if ((yys = getenv(\"YYDEBUG\")))",
198 " if (yyn >= '0' && yyn <= '9')",
199 " yydebug = yyn - '0';",
207 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
210 " *yyssp = yystate = 0;",
213 " if ((yyn = yydefred[yystate])) goto yyreduce;",
216 " if ((yychar = yylex()) < 0) yychar = 0;",
221 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
222 " if (!yys) yys = \"illegal-symbol\";",
223 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
224 " YYPREFIX, yystate, yychar, yys);",
228 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
229 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
233 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
234 " YYPREFIX, yystate, yytable[yyn]);",
236 " if (yyssp >= yysslim && yygrowstack())",
240 " *++yyssp = yystate = yytable[yyn];",
241 " *++yyvsp = yylval;",
243 " if (yyerrflag > 0) --yyerrflag;",
246 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
247 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
249 " yyn = yytable[yyn];",
252 " if (yyerrflag) goto yyinrecovery;",
253 "#if defined(lint) || defined(__GNUC__)",
257 " yyerror(\"syntax error\");",
258 "#if defined(lint) || defined(__GNUC__)",
264 " if (yyerrflag < 3)",
269 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
270 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
274 " printf(\"%sdebug: state %d, error recovery shifting\\",
275 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
277 " if (yyssp >= yysslim && yygrowstack())",
281 " *++yyssp = yystate = yytable[yyn];",
282 " *++yyvsp = yylval;",
289 " printf(\"%sdebug: error recovery discarding state %d\
291 " YYPREFIX, *yyssp);",
293 " if (yyssp <= yyss) goto yyabort;",
301 " if (yychar == 0) goto yyabort;",
306 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
307 " if (!yys) yys = \"illegal-symbol\";",
308 " printf(\"%sdebug: state %d, error recovery discards token %d\
310 " YYPREFIX, yystate, yychar, yys);",
319 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
320 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
322 " yym = yylen[yyn];",
323 " yyval = yyvsp[1-yym];",
334 " yystate = *yyssp;",
336 " yym = yylhs[yyn];",
337 " if (yystate == 0 && yym == 0)",
341 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
342 " state %d\\n\", YYPREFIX, YYFINAL);",
344 " yystate = YYFINAL;",
345 " *++yyssp = YYFINAL;",
346 " *++yyvsp = yyval;",
349 " if ((yychar = yylex()) < 0) yychar = 0;",
354 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
355 " if (!yys) yys = \"illegal-symbol\";",
356 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
357 " YYPREFIX, YYFINAL, yychar, yys);",
361 " if (yychar == 0) goto yyaccept;",
364 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
365 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
366 " yystate = yytable[yyn];",
368 " yystate = yydgoto[yym];",
371 " printf(\"%sdebug: after reduction, shifting from state %d \\",
372 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
374 " if (yyssp >= yysslim && yygrowstack())",
378 " *++yyssp = yystate;",
379 " *++yyvsp = yyval;",
382 " yyerror(\"yacc stack overflow\");",
393 write_section(char **section)
401 for (i = 0; (s = section[i]); ++i)