1 /* $NetBSD: skeleton.c,v 1.5 2009/10/29 21:03:59 christos Exp $ */
2 /* Id: skeleton.c,v 1.19 2008/12/24 14:52:28 tom Exp */
7 __RCSID("$NetBSD: skeleton.c,v 1.5 2009/10/29 21:03:59 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 tables
[] =
50 "extern short yylhs[];",
51 "extern short yylen[];",
52 "extern short yydefred[];",
53 "extern short yydgoto[];",
54 "extern short yysindex[];",
55 "extern short yyrindex[];",
56 "extern short yygindex[];",
57 "extern short yytable[];",
58 "extern short yycheck[];",
61 "extern char *yyname[];",
62 "extern char *yyrule[];",
67 const char * const header
[] =
73 "extern int YYPARSE_DECL();",
74 "static int yygrowstack(short **, short **, short **,",
75 " YYSTYPE **, YYSTYPE **, unsigned *);",
77 "/* define the initial stack-sizes */",
80 "#define YYMAXDEPTH YYSTACKSIZE",
83 "#define YYSTACKSIZE YYMAXDEPTH",
85 "#define YYSTACKSIZE 500",
86 "#define YYMAXDEPTH 500",
90 "#define YYINITSTACKSIZE 500",
99 const char * const body
[] =
101 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
102 "static int yygrowstack(short **yyss, short **yyssp, short **yysslim,",
103 " YYSTYPE **yyvs, YYSTYPE **yyvsp, unsigned *yystacksize)",
106 " unsigned newsize;",
110 " if ((newsize = *yystacksize) == 0)",
111 " newsize = YYINITSTACKSIZE;",
112 " else if (newsize >= YYMAXDEPTH)",
114 " else if ((newsize *= 2) > YYMAXDEPTH)",
115 " newsize = YYMAXDEPTH;",
117 " i = *yyssp - *yyss;",
118 " newss = (short *)realloc(*yyss, newsize * sizeof(*newss));",
123 " *yyssp = newss + i;",
124 " newvs = (YYSTYPE *)realloc(*yyvs, newsize * sizeof(*newvs));",
129 " *yyvsp = newvs + i;",
130 " *yystacksize = newsize;",
131 " *yysslim = *yyss + newsize - 1;",
135 "#define YYABORT goto yyabort",
136 "#define YYREJECT goto yyabort",
137 "#define YYACCEPT goto yyaccept",
138 "#define YYERROR goto yyerrlab",
143 " int yym, yyn, yystate;",
146 " /* variables for the parser stack */",
152 " unsigned yystacksize;",
156 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
159 " if (yyn >= '0' && yyn <= '9')",
160 " yydebug = yyn - '0';",
166 " yychar = YYEMPTY;",
170 " yyvs = yyvsp = NULL;",
171 " yyss = yyssp = NULL;",
172 " if (yygrowstack(&yyss, &yyssp, &yysslim, &yyvs, &yyvsp, &yystacksize))",
178 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
181 " if ((yychar = yylex(\002)) < 0) yychar = 0;",
186 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
187 " if (!yys) yys = \"illegal-symbol\";",
188 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
189 " YYPREFIX, yystate, yychar, yys);",
193 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
194 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
198 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
199 " YYPREFIX, yystate, yytable[yyn]);",
201 " if (yyssp >= yysslim && yygrowstack(&yyss, &yyssp, &yysslim,",
202 " &yyvs, &yyvsp, &yystacksize))",
206 " yystate = yytable[yyn];",
207 " *++yyssp = yytable[yyn];",
208 " *++yyvsp = yylval;",
209 " yychar = YYEMPTY;",
210 " if (yyerrflag > 0) --yyerrflag;",
213 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
214 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
216 " yyn = yytable[yyn];",
219 " if (yyerrflag) goto yyinrecovery;",
221 " yyerror(\001\"syntax error\");",
229 " if (yyerrflag < 3)",
234 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
235 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
239 " printf(\"%sdebug: state %d, error recovery shifting\\",
240 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
242 " if (yyssp >= yysslim && yygrowstack(&yyss, &yyssp,",
243 " &yysslim, &yyvs, &yyvsp, &yystacksize))",
247 " yystate = yytable[yyn];",
248 " *++yyssp = yytable[yyn];",
249 " *++yyvsp = yylval;",
256 " printf(\"%sdebug: error recovery discarding state %d\
258 " YYPREFIX, *yyssp);",
260 " if (yyssp <= yyss) goto yyabort;",
268 " if (yychar == 0) goto yyabort;",
273 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
274 " if (!yys) yys = \"illegal-symbol\";",
275 " printf(\"%sdebug: state %d, error recovery discards token %d\
277 " YYPREFIX, yystate, yychar, yys);",
280 " yychar = YYEMPTY;",
287 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
288 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
290 " yym = yylen[yyn];",
292 " yyval = yyvsp[1-yym];",
294 " memset(&yyval, 0, sizeof yyval);",
300 const char * const trailer
[] =
304 " yystate = *yyssp;",
306 " yym = yylhs[yyn];",
307 " if (yystate == 0 && yym == 0)",
311 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
312 " state %d\\n\", YYPREFIX, YYFINAL);",
314 " yystate = YYFINAL;",
315 " *++yyssp = YYFINAL;",
316 " *++yyvsp = yyval;",
319 " if ((yychar = yylex(\002)) < 0) yychar = 0;",
324 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
325 " if (!yys) yys = \"illegal-symbol\";",
326 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
327 " YYPREFIX, YYFINAL, yychar, yys);",
331 " if (yychar == 0) goto yyaccept;",
334 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
335 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
336 " yystate = yytable[yyn];",
338 " yystate = yydgoto[yym];",
341 " printf(\"%sdebug: after reduction, shifting from state %d \\",
342 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
344 " if (yyssp >= yysslim && yygrowstack(&yyss, &yyssp,",
345 " &yysslim, &yyvs, &yyvsp, &yystacksize))",
349 " *++yyssp = (short) yystate;",
350 " *++yyvsp = yyval;",
354 " yyerror(\001\"yacc stack overflow\");",
370 write_section(const char * const section
[], int dodecls
)
380 for (i
= 0; (s
= section
[i
]) != 0; ++i
)
383 while ((c
= *s
) != 0)
388 for (; p
!= NULL
; p
= p
->next
)
389 fprintf(f
, "%s, ", p
->name
);
395 fprintf(f
, "&yylval");
399 for (; p
!= NULL
; p
= p
->next
) {
400 fprintf(f
, "%s%s", comma
, p
->name
);