1 /* $NetBSD: skeleton.c,v 1.10 2011/09/10 21:29:04 christos Exp $ */
2 /* Id: skeleton.c,v 1.31 2011/09/07 09:37:59 tom Exp */
7 __RCSID("$NetBSD: skeleton.c,v 1.10 2011/09/10 21:29:04 christos Exp $");
9 /* The definition of yysccsid in the banner should be replaced with */
10 /* a #pragma ident directive if the target C compiler supports */
11 /* #pragma ident directives. */
13 /* If the skeleton is changed, the banner should be changed so that */
14 /* the altered version can be easily distinguished from the original. */
16 /* The #defines included with the banner are there because they are */
17 /* useful in subsequent code. The macros #defined in the header or */
18 /* the body either are not useful outside of semantic actions or */
19 /* are conditional. */
21 const char *const banner
[] =
24 "static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
28 "#include \"namespace.h\"",
30 "#include <stdlib.h>",
31 "#include <string.h>",
34 CONCAT1("#define YYMAJOR ", YYMAJOR
),
35 CONCAT1("#define YYMINOR ", YYMINOR
),
37 CONCAT1("#define YYPATCH ", YYPATCH
),
40 "#define YYEMPTY (-1)",
41 "#define yyclearin (yychar = YYEMPTY)",
42 "#define yyerrok (yyerrflag = 0)",
43 "#define YYRECOVERING() (yyerrflag != 0)",
48 const char *const xdecls
[] =
51 "extern int YYPARSE_DECL();",
53 "extern int YYLEX_DECL();",
59 const char *const tables
[] =
61 "extern short yylhs[];",
62 "extern short yylen[];",
63 "extern short yydefred[];",
64 "extern short yydgoto[];",
65 "extern short yysindex[];",
66 "extern short yyrindex[];",
67 "extern short yygindex[];",
68 "extern short yytable[];",
69 "extern short yycheck[];",
72 "extern char *yyname[];",
73 "extern char *yyrule[];",
78 const char *const global_vars
[] =
86 const char *const impure_vars
[] =
96 const char *const hdr_defs
[] =
99 "/* define the initial stack-sizes */",
100 "#ifdef YYSTACKSIZE",
102 "#define YYMAXDEPTH YYSTACKSIZE",
105 "#define YYSTACKSIZE YYMAXDEPTH",
107 "#define YYSTACKSIZE 500",
108 "#define YYMAXDEPTH 500",
112 "#define YYINITSTACKSIZE 500",
115 " unsigned stacksize;",
125 const char *const hdr_vars
[] =
127 "/* variables for the parser stack */",
128 "static YYSTACKDATA yystack;",
132 const char *const body_vars
[] =
139 " /* variables for the parser stack */",
140 " YYSTACKDATA yystack;",
144 const char *const body_1
[] =
148 "#include <stdio.h> /* needed for printf */",
151 "#include <stdlib.h> /* needed for malloc, etc */",
152 "#include <string.h> /* needed for memset */",
154 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
155 "static int yygrowstack(YYSTACKDATA *data)",
158 " unsigned newsize;",
162 " if ((newsize = data->stacksize) == 0)",
163 " newsize = YYINITSTACKSIZE;",
164 " else if (newsize >= YYMAXDEPTH)",
166 " else if ((newsize *= 2) > YYMAXDEPTH)",
167 " newsize = YYMAXDEPTH;",
169 " i = data->s_mark - data->s_base;",
170 " newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
174 " data->s_base = newss;",
175 " data->s_mark = newss + i;",
177 " newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
181 " data->l_base = newvs;",
182 " data->l_mark = newvs + i;",
184 " data->stacksize = newsize;",
185 " data->s_last = data->s_base + newsize - 1;",
189 "#if YYPURE || defined(YY_NO_LEAKS)",
190 "static void yyfreestack(YYSTACKDATA *data)",
192 " free(data->s_base);",
193 " free(data->l_base);",
194 " memset(data, 0, sizeof(*data));",
197 "#define yyfreestack(data) /* nothing */",
200 "#define YYABORT goto yyabort",
201 "#define YYREJECT goto yyabort",
202 "#define YYACCEPT goto yyaccept",
203 "#define YYERROR goto yyerrlab",
211 const char *const body_2
[] =
213 " int yym, yyn, yystate;",
217 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
220 " if (yyn >= '0' && yyn <= '9')",
221 " yydebug = yyn - '0';",
227 " yychar = YYEMPTY;",
231 " memset(&yystack, 0, sizeof(yystack));",
234 " if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
235 " yystack.s_mark = yystack.s_base;",
236 " yystack.l_mark = yystack.l_base;",
238 " *yystack.s_mark = 0;",
241 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
244 " if ((yychar = YYLEX) < 0) yychar = 0;",
249 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
250 " if (!yys) yys = \"illegal-symbol\";",
251 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
252 " YYPREFIX, yystate, yychar, yys);",
256 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
257 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
261 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
262 " YYPREFIX, yystate, yytable[yyn]);",
264 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
268 " yystate = yytable[yyn];",
269 " *++yystack.s_mark = yytable[yyn];",
270 " *++yystack.l_mark = yylval;",
271 " yychar = YYEMPTY;",
272 " if (yyerrflag > 0) --yyerrflag;",
275 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
276 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
278 " yyn = yytable[yyn];",
281 " if (yyerrflag) goto yyinrecovery;",
286 const char *const body_3
[] =
295 " if (yyerrflag < 3)",
300 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
301 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
305 " printf(\"%sdebug: state %d, error recovery shifting\\",
306 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
308 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
312 " yystate = yytable[yyn];",
313 " *++yystack.s_mark = yytable[yyn];",
314 " *++yystack.l_mark = yylval;",
321 " printf(\"%sdebug: error recovery discarding state %d\
323 " YYPREFIX, *yystack.s_mark);",
325 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
326 " --yystack.s_mark;",
327 " --yystack.l_mark;",
333 " if (yychar == 0) goto yyabort;",
338 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
339 " if (!yys) yys = \"illegal-symbol\";",
340 " printf(\"%sdebug: state %d, error recovery discards token %d\
342 " YYPREFIX, yystate, yychar, yys);",
345 " yychar = YYEMPTY;",
352 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
353 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
355 " yym = yylen[yyn];",
357 " yyval = yystack.l_mark[1-yym];",
359 " memset(&yyval, 0, sizeof yyval);",
365 const char *const trailer
[] =
368 " yystack.s_mark -= yym;",
369 " yystate = *yystack.s_mark;",
370 " yystack.l_mark -= yym;",
371 " yym = yylhs[yyn];",
372 " if (yystate == 0 && yym == 0)",
376 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
377 " state %d\\n\", YYPREFIX, YYFINAL);",
379 " yystate = YYFINAL;",
380 " *++yystack.s_mark = YYFINAL;",
381 " *++yystack.l_mark = yyval;",
384 " if ((yychar = YYLEX) < 0) yychar = 0;",
389 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
390 " if (!yys) yys = \"illegal-symbol\";",
391 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
392 " YYPREFIX, YYFINAL, yychar, yys);",
396 " if (yychar == 0) goto yyaccept;",
399 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
400 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
401 " yystate = yytable[yyn];",
403 " yystate = yydgoto[yym];",
406 " printf(\"%sdebug: after reduction, shifting from state %d \\",
407 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
409 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
413 " *++yystack.s_mark = (short) yystate;",
414 " *++yystack.l_mark = yyval;",
421 const char *const trailer_2
[] =
425 " yyfreestack(&yystack);",
429 " yyfreestack(&yystack);",
436 write_section(FILE * fp
, const char *const section
[])
442 for (i
= 0; (s
= section
[i
]) != 0; ++i
)
444 while ((c
= *s
) != 0)