1 /* $Id: skeleton.c,v 1.31 2011/09/07 09:37:59 tom Exp $ */
5 /* The #defines included with the banner are there because they are */
6 /* useful in subsequent code. The macros #defined in the header or */
7 /* the body either are not useful outside of semantic actions or */
10 const char *const banner
[] =
13 CONCAT1("#define YYMAJOR ", YYMAJOR
),
14 CONCAT1("#define YYMINOR ", YYMINOR
),
16 CONCAT1("#define YYPATCH ", YYPATCH
),
19 "#define YYEMPTY (-1)",
20 "#define yyclearin (yychar = YYEMPTY)",
21 "#define yyerrok (yyerrflag = 0)",
22 "#define YYRECOVERING() (yyerrflag != 0)",
27 const char *const xdecls
[] =
30 "extern int YYPARSE_DECL();",
34 const char *const tables
[] =
36 "extern short yylhs[];",
37 "extern short yylen[];",
38 "extern short yydefred[];",
39 "extern short yydgoto[];",
40 "extern short yysindex[];",
41 "extern short yyrindex[];",
42 "extern short yygindex[];",
43 "extern short yytable[];",
44 "extern short yycheck[];",
47 "extern char *yyname[];",
48 "extern char *yyrule[];",
53 const char *const global_vars
[] =
61 const char *const impure_vars
[] =
71 const char *const hdr_defs
[] =
74 "/* define the initial stack-sizes */",
77 "#define YYMAXDEPTH YYSTACKSIZE",
80 "#define YYSTACKSIZE YYMAXDEPTH",
82 "#define YYSTACKSIZE 500",
83 "#define YYMAXDEPTH 500",
87 "#define YYINITSTACKSIZE 50",
90 " unsigned stacksize;",
100 const char *const hdr_vars
[] =
102 "/* variables for the parser stack */",
103 "static YYSTACKDATA yystack;",
107 const char *const body_vars
[] =
114 " /* variables for the parser stack */",
115 " YYSTACKDATA yystack;",
119 const char *const body_1
[] =
123 "#include <stdio.h> /* needed for printf */",
126 "#include <parser.h>",
128 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
129 "static int yygrowstack(struct parser *p, YYSTACKDATA *data)",
132 " unsigned newsize;",
136 " if ((newsize = data->stacksize) == 0)",
137 " newsize = YYINITSTACKSIZE;",
138 " else if (newsize >= YYMAXDEPTH)",
140 " else if ((newsize *= 2) > YYMAXDEPTH)",
141 " newsize = YYMAXDEPTH;",
143 " i = data->s_mark - data->s_base;",
144 " newss = (short *)p->realloc(data->s_base, newsize * sizeof(*newss));",
148 " data->s_base = newss;",
149 " data->s_mark = newss + i;",
151 " newvs = (YYSTYPE *)p->realloc(data->l_base, newsize * sizeof(*newvs));",
155 " data->l_base = newvs;",
156 " data->l_mark = newvs + i;",
158 " data->stacksize = newsize;",
159 " data->s_last = data->s_base + newsize - 1;",
163 "static void yyfreestack(struct parser *p, YYSTACKDATA *data)",
165 " p->free(data->s_base);",
166 " p->free(data->l_base);",
167 " memset(data, 0, sizeof(*data));",
170 "#define YYABORT goto yyabort",
171 "#define YYREJECT goto yyabort",
172 "#define YYACCEPT goto yyaccept",
173 "#define YYERROR goto yyerrlab",
176 "yyparse(struct parser *parser)",
181 const char *const body_2
[] =
183 " int yym, yyn, yystate;",
187 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
190 " if (yyn >= '0' && yyn <= '9')",
191 " yydebug = yyn - '0';",
197 " yychar = YYEMPTY;",
201 " memset(&yystack, 0, sizeof(yystack));",
204 " if (yystack.s_base == NULL && yygrowstack(parser, &yystack)) goto yyoverflow;",
205 " yystack.s_mark = yystack.s_base;",
206 " yystack.l_mark = yystack.l_base;",
208 " *yystack.s_mark = 0;",
211 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
214 " if ((yychar = YYLEX(parser)) < 0) yychar = 0;",
219 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
220 " if (!yys) yys = \"illegal-symbol\";",
221 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
222 " YYPREFIX, yystate, yychar, yys);",
226 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
227 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
231 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
232 " YYPREFIX, yystate, yytable[yyn]);",
234 " if (yystack.s_mark >= yystack.s_last && yygrowstack(parser, &yystack))",
238 " yystate = yytable[yyn];",
239 " *++yystack.s_mark = yytable[yyn];",
240 " *++yystack.l_mark = yylval;",
241 " yychar = YYEMPTY;",
242 " if (yyerrflag > 0) --yyerrflag;",
245 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
246 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
248 " yyn = yytable[yyn];",
251 " if (yyerrflag) goto yyinrecovery;",
256 const char *const body_3
[] =
265 " if (yyerrflag < 3)",
270 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
271 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
275 " printf(\"%sdebug: state %d, error recovery shifting\\",
276 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
278 " if (yystack.s_mark >= yystack.s_last && yygrowstack(parser, &yystack))",
282 " yystate = yytable[yyn];",
283 " *++yystack.s_mark = yytable[yyn];",
284 " *++yystack.l_mark = yylval;",
291 " printf(\"%sdebug: error recovery discarding state %d\
293 " YYPREFIX, *yystack.s_mark);",
295 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
296 " --yystack.s_mark;",
297 " --yystack.l_mark;",
303 " if (yychar == 0) goto yyabort;",
308 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
309 " if (!yys) yys = \"illegal-symbol\";",
310 " printf(\"%sdebug: state %d, error recovery discards token %d\
312 " YYPREFIX, yystate, yychar, yys);",
315 " yychar = YYEMPTY;",
322 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
323 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
325 " yym = yylen[yyn];",
327 " yyval = yystack.l_mark[1-yym];",
329 " memset(&yyval, 0, sizeof yyval);",
335 const char *const trailer
[] =
338 " yystack.s_mark -= yym;",
339 " yystate = *yystack.s_mark;",
340 " yystack.l_mark -= yym;",
341 " yym = yylhs[yyn];",
342 " if (yystate == 0 && yym == 0)",
346 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
347 " state %d\\n\", YYPREFIX, YYFINAL);",
349 " yystate = YYFINAL;",
350 " *++yystack.s_mark = YYFINAL;",
351 " *++yystack.l_mark = yyval;",
354 " if ((yychar = YYLEX(parser)) < 0) yychar = 0;",
359 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
360 " if (!yys) yys = \"illegal-symbol\";",
361 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
362 " YYPREFIX, YYFINAL, yychar, yys);",
366 " if (yychar == 0) goto yyaccept;",
369 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
370 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
371 " yystate = yytable[yyn];",
373 " yystate = yydgoto[yym];",
376 " printf(\"%sdebug: after reduction, shifting from state %d \\",
377 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
379 " if (yystack.s_mark >= yystack.s_last && yygrowstack(parser, &yystack))",
383 " *++yystack.s_mark = (short) yystate;",
384 " *++yystack.l_mark = yyval;",
391 const char *const trailer_2
[] =
395 " yyfreestack(parser, &yystack);",
399 " yyfreestack(parser, &yystack);",
406 write_section(FILE * fp
, const char *const section
[])
412 for (i
= 0; (s
= section
[i
]) != 0; ++i
)
414 while ((c
= *s
) != 0)