1 /* $Id: skeleton.c,v 1.23 2010/02/17 01:44:23 tom Exp $ */
5 /* The definition of yysccsid in the banner should be replaced with */
6 /* a #pragma ident directive if the target C compiler supports */
7 /* #pragma ident directives. */
9 /* If the skeleton is changed, the banner should be changed so that */
10 /* the altered version can be easily distinguished from the original. */
12 /* The #defines included with the banner are there because they are */
13 /* useful in subsequent code. The macros #defined in the header or */
14 /* the body either are not useful outside of semantic actions or */
15 /* are conditional. */
17 const char *banner[] =
20 "static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
23 "#include <stdlib.h>",
24 "#include <string.h>",
27 CONCAT1("#define YYMAJOR ", YYMAJOR),
28 CONCAT1("#define YYMINOR ", YYMINOR),
30 CONCAT1("#define YYPATCH ", YYPATCH),
33 "#define YYEMPTY (-1)",
34 "#define yyclearin (yychar = YYEMPTY)",
35 "#define yyerrok (yyerrflag = 0)",
36 "#define YYRECOVERING() (yyerrflag != 0)",
41 const char *xdecls[] =
44 "/* compatibility with bison */",
45 "#ifdef YYPARSE_PARAM",
46 "/* compatibility with FreeBSD */",
47 "#ifdef YYPARSE_PARAM_TYPE",
48 "#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)",
50 "#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)",
53 "#define YYPARSE_DECL() yyparse(void)",
54 "#endif /* YYPARSE_PARAM */",
56 "extern int YYPARSE_DECL();",
61 const char *tables[] =
63 "extern short yylhs[];",
64 "extern short yylen[];",
65 "extern short yydefred[];",
66 "extern short yydgoto[];",
67 "extern short yysindex[];",
68 "extern short yyrindex[];",
69 "extern short yygindex[];",
70 "extern short yytable[];",
71 "extern short yycheck[];",
74 "extern char *yyname[];",
75 "extern char *yyrule[];",
80 const char *hdr_defs[] =
86 "/* define the initial stack-sizes */",
89 "#define YYMAXDEPTH YYSTACKSIZE",
92 "#define YYSTACKSIZE YYMAXDEPTH",
94 "#define YYSTACKSIZE 500",
95 "#define YYMAXDEPTH 500",
99 "#define YYINITSTACKSIZE 500",
105 " unsigned stacksize;",
115 const char *hdr_vars[] =
122 "/* variables for the parser stack */",
123 "static YYSTACKDATA yystack;",
127 const char *body_vars[] =
134 " /* variables for the parser stack */",
135 " YYSTACKDATA yystack;",
139 const char *body_1[] =
141 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
142 "static int yygrowstack(YYSTACKDATA *data)",
145 " unsigned newsize;",
149 " if ((newsize = data->stacksize) == 0)",
150 " newsize = YYINITSTACKSIZE;",
151 " else if (newsize >= YYMAXDEPTH)",
153 " else if ((newsize *= 2) > YYMAXDEPTH)",
154 " newsize = YYMAXDEPTH;",
156 " i = data->s_mark - data->s_base;",
157 " newss = (data->s_base != 0)",
158 " ? (short *)realloc(data->s_base, newsize * sizeof(*newss))",
159 " : (short *)malloc(newsize * sizeof(*newss));",
163 " data->s_base = newss;",
164 " data->s_mark = newss + i;",
166 " newvs = (data->l_base != 0)",
167 " ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))",
168 " : (YYSTYPE *)malloc(newsize * sizeof(*newvs));",
172 " data->l_base = newvs;",
173 " data->l_mark = newvs + i;",
175 " data->stacksize = newsize;",
176 " data->s_last = data->s_base + newsize - 1;",
180 "#if YYPURE || defined(YY_NO_LEAKS)",
181 "static void yyfreestack(YYSTACKDATA *data)",
183 " free(data->s_base);",
184 " free(data->l_base);",
185 " memset(data, 0, sizeof(*data));",
188 "#define yyfreestack(data) /* nothing */",
191 "#define YYABORT goto yyabort",
192 "#define YYREJECT goto yyabort",
193 "#define YYACCEPT goto yyaccept",
194 "#define YYERROR goto yyerrlab",
202 const char *body_2[] =
204 " int yym, yyn, yystate;",
208 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
211 " if (yyn >= '0' && yyn <= '9')",
212 " yydebug = yyn - '0';",
218 " yychar = YYEMPTY;",
222 " memset(&yystack, 0, sizeof(yystack));",
225 " if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
226 " yystack.s_mark = yystack.s_base;",
227 " yystack.l_mark = yystack.l_base;",
229 " *yystack.s_mark = 0;",
232 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
235 " if ((yychar = yylex()) < 0) yychar = 0;",
240 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
241 " if (!yys) yys = \"illegal-symbol\";",
242 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
243 " YYPREFIX, yystate, yychar, yys);",
247 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
248 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
252 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
253 " YYPREFIX, yystate, yytable[yyn]);",
255 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
259 " yystate = yytable[yyn];",
260 " *++yystack.s_mark = yytable[yyn];",
261 " *++yystack.l_mark = yylval;",
262 " yychar = YYEMPTY;",
263 " if (yyerrflag > 0) --yyerrflag;",
266 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
267 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
269 " yyn = yytable[yyn];",
272 " if (yyerrflag) goto yyinrecovery;",
274 " yyerror(\"syntax error\");",
282 " if (yyerrflag < 3)",
287 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
288 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
292 " printf(\"%sdebug: state %d, error recovery shifting\\",
293 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
295 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
299 " yystate = yytable[yyn];",
300 " *++yystack.s_mark = yytable[yyn];",
301 " *++yystack.l_mark = yylval;",
308 " printf(\"%sdebug: error recovery discarding state %d\
310 " YYPREFIX, *yystack.s_mark);",
312 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
313 " --yystack.s_mark;",
314 " --yystack.l_mark;",
320 " if (yychar == 0) goto yyabort;",
325 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
326 " if (!yys) yys = \"illegal-symbol\";",
327 " printf(\"%sdebug: state %d, error recovery discards token %d\
329 " YYPREFIX, yystate, yychar, yys);",
332 " yychar = YYEMPTY;",
339 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
340 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
342 " yym = yylen[yyn];",
344 " yyval = yystack.l_mark[1-yym];",
346 " memset(&yyval, 0, sizeof yyval);",
352 const char *trailer[] =
355 " yystack.s_mark -= yym;",
356 " yystate = *yystack.s_mark;",
357 " yystack.l_mark -= yym;",
358 " yym = yylhs[yyn];",
359 " if (yystate == 0 && yym == 0)",
363 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
364 " state %d\\n\", YYPREFIX, YYFINAL);",
366 " yystate = YYFINAL;",
367 " *++yystack.s_mark = YYFINAL;",
368 " *++yystack.l_mark = yyval;",
371 " if ((yychar = yylex()) < 0) yychar = 0;",
376 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
377 " if (!yys) yys = \"illegal-symbol\";",
378 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
379 " YYPREFIX, YYFINAL, yychar, yys);",
383 " if (yychar == 0) goto yyaccept;",
386 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
387 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
388 " yystate = yytable[yyn];",
390 " yystate = yydgoto[yym];",
393 " printf(\"%sdebug: after reduction, shifting from state %d \\",
394 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
396 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
400 " *++yystack.s_mark = (short) yystate;",
401 " *++yystack.l_mark = yyval;",
405 " yyerror(\"yacc stack overflow\");",
408 " yyfreestack(&yystack);",
412 " yyfreestack(&yystack);",
419 write_section(const char *section[])
427 for (i = 0; (s = section[i]) != 0; ++i)
430 while ((c = *s) != 0)