1 /* $Id: skeleton.c,v 1.19 2008/12/24 14:52:28 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 *banner[] =
20 "static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
23 "#include <stdlib.h>",
24 "#include <string.h>",
27 CONCAT1("#define YYMAJOR ", YYMAJOR),
28 CONCAT1("#define YYMINOR ", YYMINOR),
30 CONCAT1("#define YYPATCH ", YYPATCH),
33 "#define YYEMPTY (-1)",
34 "#define yyclearin (yychar = YYEMPTY)",
35 "#define yyerrok (yyerrflag = 0)",
36 "#define YYRECOVERING() (yyerrflag != 0)",
38 "/* compatibility with bison */",
39 "#ifdef YYPARSE_PARAM",
40 "/* compatibility with FreeBSD */",
41 "#ifdef YYPARSE_PARAM_TYPE",
42 "#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)",
44 "#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)",
47 "#define YYPARSE_DECL() yyparse(void)",
48 "#endif /* YYPARSE_PARAM */",
50 "extern int YYPARSE_DECL();",
52 "static int yygrowstack(void);",
56 const char *tables[] =
58 "extern short yylhs[];",
59 "extern short yylen[];",
60 "extern short yydefred[];",
61 "extern short yydgoto[];",
62 "extern short yysindex[];",
63 "extern short yyrindex[];",
64 "extern short yygindex[];",
65 "extern short yytable[];",
66 "extern short yycheck[];",
69 "extern char *yyname[];",
70 "extern char *yyrule[];",
75 const char *header[] =
81 "/* define the initial stack-sizes */",
84 "#define YYMAXDEPTH YYSTACKSIZE",
87 "#define YYSTACKSIZE YYMAXDEPTH",
89 "#define YYSTACKSIZE 500",
90 "#define YYMAXDEPTH 500",
94 "#define YYINITSTACKSIZE 500",
105 "/* variables for the parser stack */",
106 "static short *yyss;",
107 "static short *yysslim;",
108 "static YYSTYPE *yyvs;",
109 "static unsigned yystacksize;",
115 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
116 "static int yygrowstack(void)",
119 " unsigned newsize;",
123 " if ((newsize = yystacksize) == 0)",
124 " newsize = YYINITSTACKSIZE;",
125 " else if (newsize >= YYMAXDEPTH)",
127 " else if ((newsize *= 2) > YYMAXDEPTH)",
128 " newsize = YYMAXDEPTH;",
130 " i = yyssp - yyss;",
131 " newss = (yyss != 0)",
132 " ? (short *)realloc(yyss, newsize * sizeof(*newss))",
133 " : (short *)malloc(newsize * sizeof(*newss));",
138 " yyssp = newss + i;",
139 " newvs = (yyvs != 0)",
140 " ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))",
141 " : (YYSTYPE *)malloc(newsize * sizeof(*newvs));",
146 " yyvsp = newvs + i;",
147 " yystacksize = newsize;",
148 " yysslim = yyss + newsize - 1;",
152 "#define YYABORT goto yyabort",
153 "#define YYREJECT goto yyabort",
154 "#define YYACCEPT goto yyaccept",
155 "#define YYERROR goto yyerrlab",
160 " int yym, yyn, yystate;",
164 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
167 " if (yyn >= '0' && yyn <= '9')",
168 " yydebug = yyn - '0';",
174 " yychar = YYEMPTY;",
177 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
184 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
187 " if ((yychar = yylex()) < 0) yychar = 0;",
192 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
193 " if (!yys) yys = \"illegal-symbol\";",
194 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
195 " YYPREFIX, yystate, yychar, yys);",
199 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
200 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
204 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
205 " YYPREFIX, yystate, yytable[yyn]);",
207 " if (yyssp >= yysslim && yygrowstack())",
211 " yystate = yytable[yyn];",
212 " *++yyssp = yytable[yyn];",
213 " *++yyvsp = yylval;",
214 " yychar = YYEMPTY;",
215 " if (yyerrflag > 0) --yyerrflag;",
218 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
219 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
221 " yyn = yytable[yyn];",
224 " if (yyerrflag) goto yyinrecovery;",
226 " yyerror(\"syntax error\");",
234 " if (yyerrflag < 3)",
239 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
240 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
244 " printf(\"%sdebug: state %d, error recovery shifting\\",
245 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
247 " if (yyssp >= yysslim && yygrowstack())",
251 " yystate = yytable[yyn];",
252 " *++yyssp = yytable[yyn];",
253 " *++yyvsp = yylval;",
260 " printf(\"%sdebug: error recovery discarding state %d\
262 " YYPREFIX, *yyssp);",
264 " if (yyssp <= yyss) goto yyabort;",
272 " if (yychar == 0) goto yyabort;",
277 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
278 " if (!yys) yys = \"illegal-symbol\";",
279 " printf(\"%sdebug: state %d, error recovery discards token %d\
281 " YYPREFIX, yystate, yychar, yys);",
284 " yychar = YYEMPTY;",
291 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
292 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
294 " yym = yylen[yyn];",
296 " yyval = yyvsp[1-yym];",
298 " memset(&yyval, 0, sizeof yyval);",
304 const char *trailer[] =
308 " yystate = *yyssp;",
310 " yym = yylhs[yyn];",
311 " if (yystate == 0 && yym == 0)",
315 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
316 " state %d\\n\", YYPREFIX, YYFINAL);",
318 " yystate = YYFINAL;",
319 " *++yyssp = YYFINAL;",
320 " *++yyvsp = yyval;",
323 " if ((yychar = yylex()) < 0) yychar = 0;",
328 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
329 " if (!yys) yys = \"illegal-symbol\";",
330 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
331 " YYPREFIX, YYFINAL, yychar, yys);",
335 " if (yychar == 0) goto yyaccept;",
338 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
339 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
340 " yystate = yytable[yyn];",
342 " yystate = yydgoto[yym];",
345 " printf(\"%sdebug: after reduction, shifting from state %d \\",
346 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
348 " if (yyssp >= yysslim && yygrowstack())",
352 " *++yyssp = (short) yystate;",
353 " *++yyvsp = yyval;",
357 " yyerror(\"yacc stack overflow\");",
369 write_section(const char *section[])
377 for (i = 0; (s = section[i]) != 0; ++i)
380 while ((c = *s) != 0)