1 /* $Id: skeleton.c,v 1.30 2010/12/29 20:57:21 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 *const banner[] =
20 "static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
24 CONCAT1("#define YYMAJOR ", YYMAJOR),
25 CONCAT1("#define YYMINOR ", YYMINOR),
27 CONCAT1("#define YYPATCH ", YYPATCH),
30 "#define YYEMPTY (-1)",
31 "#define yyclearin (yychar = YYEMPTY)",
32 "#define yyerrok (yyerrflag = 0)",
33 "#define YYRECOVERING() (yyerrflag != 0)",
38 const char *const xdecls[] =
40 "extern int YYPARSE_DECL();",
45 const char *const tables[] =
47 "extern short yylhs[];",
48 "extern short yylen[];",
49 "extern short yydefred[];",
50 "extern short yydgoto[];",
51 "extern short yysindex[];",
52 "extern short yyrindex[];",
53 "extern short yygindex[];",
54 "extern short yytable[];",
55 "extern short yycheck[];",
58 "extern char *yyname[];",
59 "extern char *yyrule[];",
64 const char *const hdr_defs[] =
66 "/* define the initial stack-sizes */",
69 "#define YYMAXDEPTH YYSTACKSIZE",
72 "#define YYSTACKSIZE YYMAXDEPTH",
74 "#define YYSTACKSIZE 500",
75 "#define YYMAXDEPTH 500",
79 "#define YYINITSTACKSIZE 500",
85 " unsigned stacksize;",
95 const char *const hdr_vars[] =
102 "/* variables for the parser stack */",
103 "static YYSTACKDATA yystack;",
107 const char *const body_vars[] =
114 " /* variables for the parser stack */",
115 " YYSTACKDATA yystack;",
119 const char *const body_1[] =
123 "#include <stdio.h> /* needed for printf */",
126 "#include <stdlib.h> /* needed for malloc, etc */",
127 "#include <string.h> /* needed for memset */",
129 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
130 "static int yygrowstack(YYSTACKDATA *data)",
133 " unsigned newsize;",
137 " if ((newsize = data->stacksize) == 0)",
138 " newsize = YYINITSTACKSIZE;",
139 " else if (newsize >= YYMAXDEPTH)",
141 " else if ((newsize *= 2) > YYMAXDEPTH)",
142 " newsize = YYMAXDEPTH;",
144 " i = data->s_mark - data->s_base;",
145 " newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
149 " data->s_base = newss;",
150 " data->s_mark = newss + i;",
152 " newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
156 " data->l_base = newvs;",
157 " data->l_mark = newvs + i;",
159 " data->stacksize = newsize;",
160 " data->s_last = data->s_base + newsize - 1;",
164 "#if YYPURE || defined(YY_NO_LEAKS)",
165 "static void yyfreestack(YYSTACKDATA *data)",
167 " free(data->s_base);",
168 " free(data->l_base);",
169 " memset(data, 0, sizeof(*data));",
172 "#define yyfreestack(data) /* nothing */",
175 "#define YYABORT goto yyabort",
176 "#define YYREJECT goto yyabort",
177 "#define YYACCEPT goto yyaccept",
178 "#define YYERROR goto yyerrlab",
186 const char *const body_2[] =
188 " int yym, yyn, yystate;",
192 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
195 " if (yyn >= '0' && yyn <= '9')",
196 " yydebug = yyn - '0';",
202 " yychar = YYEMPTY;",
206 " memset(&yystack, 0, sizeof(yystack));",
209 " if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
210 " yystack.s_mark = yystack.s_base;",
211 " yystack.l_mark = yystack.l_base;",
213 " *yystack.s_mark = 0;",
216 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
219 " if ((yychar = YYLEX) < 0) yychar = 0;",
224 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
225 " if (!yys) yys = \"illegal-symbol\";",
226 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
227 " YYPREFIX, yystate, yychar, yys);",
231 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
232 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
236 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
237 " YYPREFIX, yystate, yytable[yyn]);",
239 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
243 " yystate = yytable[yyn];",
244 " *++yystack.s_mark = yytable[yyn];",
245 " *++yystack.l_mark = yylval;",
246 " yychar = YYEMPTY;",
247 " if (yyerrflag > 0) --yyerrflag;",
250 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
251 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
253 " yyn = yytable[yyn];",
256 " if (yyerrflag) goto yyinrecovery;",
261 const char *const body_3[] =
270 " if (yyerrflag < 3)",
275 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
276 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
280 " printf(\"%sdebug: state %d, error recovery shifting\\",
281 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
283 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
287 " yystate = yytable[yyn];",
288 " *++yystack.s_mark = yytable[yyn];",
289 " *++yystack.l_mark = yylval;",
296 " printf(\"%sdebug: error recovery discarding state %d\
298 " YYPREFIX, *yystack.s_mark);",
300 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
301 " --yystack.s_mark;",
302 " --yystack.l_mark;",
308 " if (yychar == 0) goto yyabort;",
313 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
314 " if (!yys) yys = \"illegal-symbol\";",
315 " printf(\"%sdebug: state %d, error recovery discards token %d\
317 " YYPREFIX, yystate, yychar, yys);",
320 " yychar = YYEMPTY;",
327 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
328 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
330 " yym = yylen[yyn];",
332 " yyval = yystack.l_mark[1-yym];",
334 " memset(&yyval, 0, sizeof yyval);",
340 const char *const trailer[] =
343 " yystack.s_mark -= yym;",
344 " yystate = *yystack.s_mark;",
345 " yystack.l_mark -= yym;",
346 " yym = yylhs[yyn];",
347 " if (yystate == 0 && yym == 0)",
351 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
352 " state %d\\n\", YYPREFIX, YYFINAL);",
354 " yystate = YYFINAL;",
355 " *++yystack.s_mark = YYFINAL;",
356 " *++yystack.l_mark = yyval;",
359 " if ((yychar = YYLEX) < 0) yychar = 0;",
364 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
365 " if (!yys) yys = \"illegal-symbol\";",
366 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
367 " YYPREFIX, YYFINAL, yychar, yys);",
371 " if (yychar == 0) goto yyaccept;",
374 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
375 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
376 " yystate = yytable[yyn];",
378 " yystate = yydgoto[yym];",
381 " printf(\"%sdebug: after reduction, shifting from state %d \\",
382 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
384 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
388 " *++yystack.s_mark = (short) yystate;",
389 " *++yystack.l_mark = yyval;",
396 const char *const trailer_2[] =
400 " yyfreestack(&yystack);",
404 " yyfreestack(&yystack);",
411 write_section(const char *const section[])
419 for (i = 0; (s = section[i]) != 0; ++i)
422 while ((c = *s) != 0)