1 /* $Id: skeleton.c,v 1.31 2011/09/07 09:37:59 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[] =
41 "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 global_vars[] =
72 const char *const impure_vars[] =
82 const char *const hdr_defs[] =
85 "/* define the initial stack-sizes */",
88 "#define YYMAXDEPTH YYSTACKSIZE",
91 "#define YYSTACKSIZE YYMAXDEPTH",
93 "#define YYSTACKSIZE 500",
94 "#define YYMAXDEPTH 500",
98 "#define YYINITSTACKSIZE 500",
101 " unsigned stacksize;",
111 const char *const hdr_vars[] =
113 "/* variables for the parser stack */",
114 "static YYSTACKDATA yystack;",
118 const char *const body_vars[] =
125 " /* variables for the parser stack */",
126 " YYSTACKDATA yystack;",
130 const char *const body_1[] =
134 "#include <stdio.h> /* needed for printf */",
137 "#include <stdlib.h> /* needed for malloc, etc */",
138 "#include <string.h> /* needed for memset */",
140 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
141 "static int yygrowstack(YYSTACKDATA *data)",
144 " unsigned newsize;",
148 " if ((newsize = data->stacksize) == 0)",
149 " newsize = YYINITSTACKSIZE;",
150 " else if (newsize >= YYMAXDEPTH)",
152 " else if ((newsize *= 2) > YYMAXDEPTH)",
153 " newsize = YYMAXDEPTH;",
155 " i = data->s_mark - data->s_base;",
156 " newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
160 " data->s_base = newss;",
161 " data->s_mark = newss + i;",
163 " newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
167 " data->l_base = newvs;",
168 " data->l_mark = newvs + i;",
170 " data->stacksize = newsize;",
171 " data->s_last = data->s_base + newsize - 1;",
175 "#if YYPURE || defined(YY_NO_LEAKS)",
176 "static void yyfreestack(YYSTACKDATA *data)",
178 " free(data->s_base);",
179 " free(data->l_base);",
180 " memset(data, 0, sizeof(*data));",
183 "#define yyfreestack(data) /* nothing */",
186 "#define YYABORT goto yyabort",
187 "#define YYREJECT goto yyabort",
188 "#define YYACCEPT goto yyaccept",
189 "#define YYERROR goto yyerrlab",
197 const char *const body_2[] =
199 " int yym, yyn, yystate;",
203 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
206 " if (yyn >= '0' && yyn <= '9')",
207 " yydebug = yyn - '0';",
213 " yychar = YYEMPTY;",
217 " memset(&yystack, 0, sizeof(yystack));",
220 " if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
221 " yystack.s_mark = yystack.s_base;",
222 " yystack.l_mark = yystack.l_base;",
224 " *yystack.s_mark = 0;",
227 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
230 " if ((yychar = YYLEX) < 0) yychar = 0;",
235 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
236 " if (!yys) yys = \"illegal-symbol\";",
237 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
238 " YYPREFIX, yystate, yychar, yys);",
242 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
243 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
247 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
248 " YYPREFIX, yystate, yytable[yyn]);",
250 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
254 " yystate = yytable[yyn];",
255 " *++yystack.s_mark = yytable[yyn];",
256 " *++yystack.l_mark = yylval;",
257 " yychar = YYEMPTY;",
258 " if (yyerrflag > 0) --yyerrflag;",
261 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
262 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
264 " yyn = yytable[yyn];",
267 " if (yyerrflag) goto yyinrecovery;",
272 const char *const body_3[] =
281 " if (yyerrflag < 3)",
286 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
287 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
291 " printf(\"%sdebug: state %d, error recovery shifting\\",
292 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
294 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
298 " yystate = yytable[yyn];",
299 " *++yystack.s_mark = yytable[yyn];",
300 " *++yystack.l_mark = yylval;",
307 " printf(\"%sdebug: error recovery discarding state %d\
309 " YYPREFIX, *yystack.s_mark);",
311 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
312 " --yystack.s_mark;",
313 " --yystack.l_mark;",
319 " if (yychar == 0) goto yyabort;",
324 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
325 " if (!yys) yys = \"illegal-symbol\";",
326 " printf(\"%sdebug: state %d, error recovery discards token %d\
328 " YYPREFIX, yystate, yychar, yys);",
331 " yychar = YYEMPTY;",
338 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
339 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
341 " yym = yylen[yyn];",
343 " yyval = yystack.l_mark[1-yym];",
345 " memset(&yyval, 0, sizeof yyval);",
351 const char *const trailer[] =
354 " yystack.s_mark -= yym;",
355 " yystate = *yystack.s_mark;",
356 " yystack.l_mark -= yym;",
357 " yym = yylhs[yyn];",
358 " if (yystate == 0 && yym == 0)",
362 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
363 " state %d\\n\", YYPREFIX, YYFINAL);",
365 " yystate = YYFINAL;",
366 " *++yystack.s_mark = YYFINAL;",
367 " *++yystack.l_mark = yyval;",
370 " if ((yychar = YYLEX) < 0) yychar = 0;",
375 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
376 " if (!yys) yys = \"illegal-symbol\";",
377 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
378 " YYPREFIX, YYFINAL, yychar, yys);",
382 " if (yychar == 0) goto yyaccept;",
385 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
386 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
387 " yystate = yytable[yyn];",
389 " yystate = yydgoto[yym];",
392 " printf(\"%sdebug: after reduction, shifting from state %d \\",
393 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
395 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
399 " *++yystack.s_mark = (short) yystate;",
400 " *++yystack.l_mark = yyval;",
407 const char *const trailer_2[] =
411 " yyfreestack(&yystack);",
415 " yyfreestack(&yystack);",
422 write_section(FILE * fp, const char *const section[])
428 for (i = 0; (s = section[i]) != 0; ++i)
430 while ((c = *s) != 0)