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 $
43 /* The definition of yysccsid in the banner should be replaced with */
44 /* a #pragma ident directive if the target C compiler supports */
45 /* #pragma ident directives. */
47 /* If the skeleton is changed, the banner should be changed so that */
48 /* the altered version can be easily distinguished from the original. */
50 /* The #defines included with the banner are there because they are */
51 /* useful in subsequent code. The macros #defined in the header or */
52 /* the body either are not useful outside of semantic actions or */
53 /* are conditional. */
55 const char *banner[] = {
56 "#include <stdlib.h>",
57 "#include <string.h>",
61 "#define YYLEX yylex()",
63 "#define yyclearin (yychar=(YYEMPTY))",
64 "#define yyerrok (yyerrflag=0)",
65 "#define YYRECOVERING() (yyerrflag!=0)",
66 "static int yygrowstack(void);",
70 const char *tables[] = {
71 "extern const short yylhs[];",
72 "extern const short yylen[];",
73 "extern const short yydefred[];",
74 "extern const short yydgoto[];",
75 "extern const short yysindex[];",
76 "extern const short yyrindex[];",
77 "extern const short yygindex[];",
78 "extern const short yytable[];",
79 "extern const short yycheck[];",
81 "extern char *yyname[];",
82 "extern char *yyrule[];",
87 const char *header[] = {
93 "#define YYMAXDEPTH YYSTACKSIZE",
96 "#define YYSTACKSIZE YYMAXDEPTH",
98 "#define YYSTACKSIZE 10000",
99 "#define YYMAXDEPTH 10000",
102 "#define YYINITSTACKSIZE 200",
118 const char *body[] = {
119 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
120 "static int yygrowstack(void)",
126 " if ((newsize = yystacksize) == 0)",
127 " newsize = YYINITSTACKSIZE;",
128 " else if (newsize >= YYMAXDEPTH)",
130 " else if ((newsize *= 2) > YYMAXDEPTH)",
131 " newsize = YYMAXDEPTH;",
132 " i = yyssp - yyss;",
133 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
134 " (short *)malloc(newsize * sizeof *newss);",
135 " if (newss == NULL)",
138 " yyssp = newss + i;",
139 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
140 " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
141 " if (newvs == NULL)",
144 " yyvsp = newvs + i;",
145 " yystacksize = newsize;",
146 " yysslim = yyss + newsize - 1;",
150 "#define YYABORT goto yyabort",
151 "#define YYREJECT goto yyabort",
152 "#define YYACCEPT goto yyaccept",
153 "#define YYERROR goto yyerrlab",
155 "#ifndef YYPARSE_PARAM",
156 "#define YYPARSE_PARAM_ARG void",
157 "#define YYPARSE_PARAM_DECL",
158 "#else /* YYPARSE_PARAM */",
159 "#ifndef YYPARSE_PARAM_TYPE",
160 "#define YYPARSE_PARAM_TYPE void *",
162 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
163 "#define YYPARSE_PARAM_DECL",
164 "#endif /* ! YYPARSE_PARAM */",
167 "yyparse (YYPARSE_PARAM_ARG)",
168 " YYPARSE_PARAM_DECL",
170 " int yym, yyn, yystate;",
174 " if ((yys = getenv(\"YYDEBUG\")))",
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])) 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;",
232 "#if defined(lint) || defined(__GNUC__)",
236 " yyerror(\"syntax error\");",
237 "#if defined(lint) || defined(__GNUC__)",
243 " if (yyerrflag < 3)",
248 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
249 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
253 " printf(\"%sdebug: state %d, error recovery shifting\\",
254 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
256 " if (yyssp >= yysslim && yygrowstack())",
260 " *++yyssp = yystate = yytable[yyn];",
261 " *++yyvsp = yylval;",
268 " printf(\"%sdebug: error recovery discarding state %d\
270 " YYPREFIX, *yyssp);",
272 " if (yyssp <= yyss) goto yyabort;",
280 " if (yychar == 0) goto yyabort;",
285 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
286 " if (!yys) yys = \"illegal-symbol\";",
287 " printf(\"%sdebug: state %d, error recovery discards token %d\
289 " YYPREFIX, yystate, yychar, yys);",
298 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
299 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
301 " yym = yylen[yyn];",
303 " yyval = yyvsp[1-yym];",
305 " memset(&yyval, 0, sizeof yyval);",
306 " yyval = yyvsp[1-yym];",
312 const char *trailer[] = {
315 " yystate = *yyssp;",
317 " yym = yylhs[yyn];",
318 " if (yystate == 0 && yym == 0)",
322 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
323 " state %d\\n\", YYPREFIX, YYFINAL);",
325 " yystate = YYFINAL;",
326 " *++yyssp = YYFINAL;",
327 " *++yyvsp = yyval;",
330 " if ((yychar = yylex()) < 0) yychar = 0;",
335 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
336 " if (!yys) yys = \"illegal-symbol\";",
337 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
338 " YYPREFIX, YYFINAL, yychar, yys);",
342 " if (yychar == 0) goto yyaccept;",
345 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
346 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
347 " yystate = yytable[yyn];",
349 " yystate = yydgoto[yym];",
352 " printf(\"%sdebug: after reduction, shifting from state %d \\",
353 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
355 " if (yyssp >= yysslim && yygrowstack())",
359 " *++yyssp = yystate;",
360 " *++yyvsp = yyval;",
363 " yyerror(\"yacc stack overflow\");",
374 write_section(const char **section)
382 for (i = 0; (s = section[i]); ++i)