1 /* $NetBSD: skeleton.c,v 1.13 2013/09/13 18:53:29 joerg Exp $ */
3 /* Id: skeleton.c,v 1.32 2013/03/04 23:19:39 tom Exp */
8 __RCSID("$NetBSD: skeleton.c,v 1.13 2013/09/13 18:53:29 joerg Exp $");
10 /* The definition of yysccsid in the banner should be replaced with */
11 /* a #pragma ident directive if the target C compiler supports */
12 /* #pragma ident directives. */
14 /* If the skeleton is changed, the banner should be changed so that */
15 /* the altered version can be easily distinguished from the original. */
17 /* The #defines included with the banner are there because they are */
18 /* useful in subsequent code. The macros #defined in the header or */
19 /* the body either are not useful outside of semantic actions or */
20 /* are conditional. */
22 const char *const banner
[] =
25 "#if __GNUC__ - 0 >= 4 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ >= 1)",
26 "__attribute__((__used__))",
28 "static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
32 "#include \"namespace.h\"",
34 "#include <stdlib.h>",
35 "#include <string.h>",
38 CONCAT1("#define YYMAJOR ", YYMAJOR
),
39 CONCAT1("#define YYMINOR ", YYMINOR
),
41 CONCAT1("#define YYPATCH ", YYPATCH
),
44 "#define YYEMPTY (-1)",
45 "#define yyclearin (yychar = YYEMPTY)",
46 "#define yyerrok (yyerrflag = 0)",
47 "#define YYRECOVERING() (yyerrflag != 0)",
52 const char *const xdecls
[] =
55 "extern int YYPARSE_DECL();",
57 "extern int YYLEX_DECL();",
63 const char *const tables
[] =
65 "extern short yylhs[];",
66 "extern short yylen[];",
67 "extern short yydefred[];",
68 "extern short yydgoto[];",
69 "extern short yysindex[];",
70 "extern short yyrindex[];",
71 "extern short yygindex[];",
72 "extern short yytable[];",
73 "extern short yycheck[];",
76 "extern char *yyname[];",
77 "extern char *yyrule[];",
82 const char *const global_vars
[] =
90 const char *const impure_vars
[] =
100 const char *const hdr_defs
[] =
103 "/* define the initial stack-sizes */",
104 "#ifdef YYSTACKSIZE",
106 "#define YYMAXDEPTH YYSTACKSIZE",
109 "#define YYSTACKSIZE YYMAXDEPTH",
111 "#define YYSTACKSIZE 500",
112 "#define YYMAXDEPTH 500",
116 "#define YYINITSTACKSIZE 500",
119 " unsigned stacksize;",
129 const char *const hdr_vars
[] =
131 "/* variables for the parser stack */",
132 "static YYSTACKDATA yystack;",
136 const char *const body_vars
[] =
143 " /* variables for the parser stack */",
144 " YYSTACKDATA yystack;",
148 const char *const body_1
[] =
152 "#include <stdio.h> /* needed for printf */",
155 "#include <stdlib.h> /* needed for malloc, etc */",
156 "#include <string.h> /* needed for memset */",
158 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
159 "static int yygrowstack(YYSTACKDATA *data)",
162 " unsigned newsize;",
166 " if ((newsize = data->stacksize) == 0)",
167 " newsize = YYINITSTACKSIZE;",
168 " else if (newsize >= YYMAXDEPTH)",
170 " else if ((newsize *= 2) > YYMAXDEPTH)",
171 " newsize = YYMAXDEPTH;",
173 " i = (int) (data->s_mark - data->s_base);",
174 " newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
178 " data->s_base = newss;",
179 " data->s_mark = newss + i;",
181 " newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
185 " data->l_base = newvs;",
186 " data->l_mark = newvs + i;",
188 " data->stacksize = newsize;",
189 " data->s_last = data->s_base + newsize - 1;",
193 "#if YYPURE || defined(YY_NO_LEAKS)",
194 "static void yyfreestack(YYSTACKDATA *data)",
196 " free(data->s_base);",
197 " free(data->l_base);",
198 " memset(data, 0, sizeof(*data));",
201 "#define yyfreestack(data) /* nothing */",
204 "#define YYABORT goto yyabort",
205 "#define YYREJECT goto yyabort",
206 "#define YYACCEPT goto yyaccept",
207 "#define YYERROR goto yyerrlab",
215 const char *const body_2
[] =
217 " int yym, yyn, yystate;",
221 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
224 " if (yyn >= '0' && yyn <= '9')",
225 " yydebug = yyn - '0';",
231 " yychar = YYEMPTY;",
235 " memset(&yystack, 0, sizeof(yystack));",
238 " if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
239 " yystack.s_mark = yystack.s_base;",
240 " yystack.l_mark = yystack.l_base;",
242 " *yystack.s_mark = 0;",
245 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
248 " if ((yychar = YYLEX) < 0) yychar = 0;",
253 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
254 " if (!yys) yys = \"illegal-symbol\";",
255 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
256 " YYPREFIX, yystate, yychar, yys);",
260 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
261 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
265 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
266 " YYPREFIX, yystate, yytable[yyn]);",
268 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
272 " yystate = yytable[yyn];",
273 " *++yystack.s_mark = yytable[yyn];",
274 " *++yystack.l_mark = yylval;",
275 " yychar = YYEMPTY;",
276 " if (yyerrflag > 0) --yyerrflag;",
279 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
280 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
282 " yyn = yytable[yyn];",
285 " if (yyerrflag) goto yyinrecovery;",
290 const char *const body_3
[] =
299 " if (yyerrflag < 3)",
304 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
305 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
309 " printf(\"%sdebug: state %d, error recovery shifting\\",
310 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
312 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
316 " yystate = yytable[yyn];",
317 " *++yystack.s_mark = yytable[yyn];",
318 " *++yystack.l_mark = yylval;",
325 " printf(\"%sdebug: error recovery discarding state %d\
327 " YYPREFIX, *yystack.s_mark);",
329 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
330 " --yystack.s_mark;",
331 " --yystack.l_mark;",
337 " if (yychar == 0) goto yyabort;",
342 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
343 " if (!yys) yys = \"illegal-symbol\";",
344 " printf(\"%sdebug: state %d, error recovery discards token %d\
346 " YYPREFIX, yystate, yychar, yys);",
349 " yychar = YYEMPTY;",
356 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
357 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
359 " yym = yylen[yyn];",
361 " yyval = yystack.l_mark[1-yym];",
363 " memset(&yyval, 0, sizeof yyval);",
369 const char *const trailer
[] =
372 " yystack.s_mark -= yym;",
373 " yystate = *yystack.s_mark;",
374 " yystack.l_mark -= yym;",
375 " yym = yylhs[yyn];",
376 " if (yystate == 0 && yym == 0)",
380 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
381 " state %d\\n\", YYPREFIX, YYFINAL);",
383 " yystate = YYFINAL;",
384 " *++yystack.s_mark = YYFINAL;",
385 " *++yystack.l_mark = yyval;",
388 " if ((yychar = YYLEX) < 0) yychar = 0;",
393 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
394 " if (!yys) yys = \"illegal-symbol\";",
395 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
396 " YYPREFIX, YYFINAL, yychar, yys);",
400 " if (yychar == 0) goto yyaccept;",
403 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
404 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
405 " yystate = yytable[yyn];",
407 " yystate = yydgoto[yym];",
410 " printf(\"%sdebug: after reduction, shifting from state %d \\",
411 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
413 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
417 " *++yystack.s_mark = (short) yystate;",
418 " *++yystack.l_mark = yyval;",
425 const char *const trailer_2
[] =
429 " yyfreestack(&yystack);",
433 " yyfreestack(&yystack);",
440 write_section(FILE * fp
, const char *const section
[])
446 for (i
= 0; (s
= section
[i
]) != 0; ++i
)
448 while ((c
= *s
) != 0)