Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / byacc / dist / skeleton.c
blobbeeb2487371de56c1028448351750fe69f16cbc4
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 */
4 #include "defs.h"
6 #include <sys/cdefs.h>
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. */
12 /* */
13 /* If the skeleton is changed, the banner should be changed so that */
14 /* the altered version can be easily distinguished from the original. */
15 /* */
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[] =
23 "#ifndef lint",
24 "static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
25 "#endif",
26 "",
27 "#ifdef _LIBC",
28 "#include \"namespace.h\"",
29 "#endif",
30 "#include <stdlib.h>",
31 "#include <string.h>",
32 "",
33 "#define YYBYACC 1",
34 CONCAT1("#define YYMAJOR ", YYMAJOR),
35 CONCAT1("#define YYMINOR ", YYMINOR),
36 #ifdef YYPATCH
37 CONCAT1("#define YYPATCH ", YYPATCH),
38 #endif
39 "",
40 "#define YYEMPTY (-1)",
41 "#define yyclearin (yychar = YYEMPTY)",
42 "#define yyerrok (yyerrflag = 0)",
43 "#define YYRECOVERING() (yyerrflag != 0)",
44 "",
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[];",
59 "",
60 "#if YYDEBUG",
61 "extern char *yyname[];",
62 "extern char *yyrule[];",
63 "#endif",
67 const char * const header[] =
69 "#if YYDEBUG",
70 "#include <stdio.h>",
71 "#endif",
72 "",
73 "extern int YYPARSE_DECL();",
74 "static int yygrowstack(short **, short **, short **,",
75 " YYSTYPE **, YYSTYPE **, unsigned *);",
76 "",
77 "/* define the initial stack-sizes */",
78 "#ifdef YYSTACKSIZE",
79 "#undef YYMAXDEPTH",
80 "#define YYMAXDEPTH YYSTACKSIZE",
81 "#else",
82 "#ifdef YYMAXDEPTH",
83 "#define YYSTACKSIZE YYMAXDEPTH",
84 "#else",
85 "#define YYSTACKSIZE 500",
86 "#define YYMAXDEPTH 500",
87 "#endif",
88 "#endif",
89 "",
90 "#define YYINITSTACKSIZE 500",
91 "",
92 "int yydebug;",
93 "int yyerrflag;",
94 "\003",
95 "",
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)",
104 "{",
105 " int i;",
106 " unsigned newsize;",
107 " short *newss;",
108 " YYSTYPE *newvs;",
110 " if ((newsize = *yystacksize) == 0)",
111 " newsize = YYINITSTACKSIZE;",
112 " else if (newsize >= YYMAXDEPTH)",
113 " return -1;",
114 " else if ((newsize *= 2) > YYMAXDEPTH)",
115 " newsize = YYMAXDEPTH;",
117 " i = *yyssp - *yyss;",
118 " newss = (short *)realloc(*yyss, newsize * sizeof(*newss));",
119 " if (newss == 0)",
120 " return -1;",
122 " *yyss = newss;",
123 " *yyssp = newss + i;",
124 " newvs = (YYSTYPE *)realloc(*yyvs, newsize * sizeof(*newvs));",
125 " if (newvs == 0)",
126 " return -1;",
128 " *yyvs = newvs;",
129 " *yyvsp = newvs + i;",
130 " *yystacksize = newsize;",
131 " *yysslim = *yyss + newsize - 1;",
132 " return 0;",
133 "}",
135 "#define YYABORT goto yyabort",
136 "#define YYREJECT goto yyabort",
137 "#define YYACCEPT goto yyaccept",
138 "#define YYERROR goto yyerrlab",
140 "int",
141 "YYPARSE_DECL()",
142 "{",
143 " int yym, yyn, yystate;",
144 "\003",
145 " YYSTYPE yyval;",
146 " /* variables for the parser stack */",
147 " short *yyssp;",
148 " short *yyss;",
149 " short *yysslim;",
150 " YYSTYPE *yyvs;",
151 " YYSTYPE *yyvsp;",
152 " unsigned yystacksize;",
153 "#if YYDEBUG",
154 " const char *yys;",
156 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
157 " {",
158 " yyn = *yys;",
159 " if (yyn >= '0' && yyn <= '9')",
160 " yydebug = yyn - '0';",
161 " }",
162 "#endif",
164 " yynerrs = 0;",
165 " yyerrflag = 0;",
166 " yychar = YYEMPTY;",
167 " yystate = 0;",
169 " yystacksize = 0;",
170 " yyvs = yyvsp = NULL;",
171 " yyss = yyssp = NULL;",
172 " if (yygrowstack(&yyss, &yyssp, &yysslim, &yyvs, &yyvsp, &yystacksize))",
173 " goto yyoverflow;",
174 " yystate = 0;",
175 " *yyssp = 0;",
177 "yyloop:",
178 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
179 " if (yychar < 0)",
180 " {",
181 " if ((yychar = yylex(\002)) < 0) yychar = 0;",
182 "#if YYDEBUG",
183 " if (yydebug)",
184 " {",
185 " yys = 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);",
190 " }",
191 "#endif",
192 " }",
193 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
194 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
195 " {",
196 "#if YYDEBUG",
197 " if (yydebug)",
198 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
199 " YYPREFIX, yystate, yytable[yyn]);",
200 "#endif",
201 " if (yyssp >= yysslim && yygrowstack(&yyss, &yyssp, &yysslim,",
202 " &yyvs, &yyvsp, &yystacksize))",
203 " {",
204 " goto yyoverflow;",
205 " }",
206 " yystate = yytable[yyn];",
207 " *++yyssp = yytable[yyn];",
208 " *++yyvsp = yylval;",
209 " yychar = YYEMPTY;",
210 " if (yyerrflag > 0) --yyerrflag;",
211 " goto yyloop;",
212 " }",
213 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
214 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
215 " {",
216 " yyn = yytable[yyn];",
217 " goto yyreduce;",
218 " }",
219 " if (yyerrflag) goto yyinrecovery;",
221 " yyerror(\001\"syntax error\");",
223 " goto yyerrlab;",
225 "yyerrlab:",
226 " ++yynerrs;",
228 "yyinrecovery:",
229 " if (yyerrflag < 3)",
230 " {",
231 " yyerrflag = 3;",
232 " for (;;)",
233 " {",
234 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
235 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
236 " {",
237 "#if YYDEBUG",
238 " if (yydebug)",
239 " printf(\"%sdebug: state %d, error recovery shifting\\",
240 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
241 "#endif",
242 " if (yyssp >= yysslim && yygrowstack(&yyss, &yyssp,",
243 " &yysslim, &yyvs, &yyvsp, &yystacksize))",
244 " {",
245 " goto yyoverflow;",
246 " }",
247 " yystate = yytable[yyn];",
248 " *++yyssp = yytable[yyn];",
249 " *++yyvsp = yylval;",
250 " goto yyloop;",
251 " }",
252 " else",
253 " {",
254 "#if YYDEBUG",
255 " if (yydebug)",
256 " printf(\"%sdebug: error recovery discarding state %d\
257 \\n\",",
258 " YYPREFIX, *yyssp);",
259 "#endif",
260 " if (yyssp <= yyss) goto yyabort;",
261 " --yyssp;",
262 " --yyvsp;",
263 " }",
264 " }",
265 " }",
266 " else",
267 " {",
268 " if (yychar == 0) goto yyabort;",
269 "#if YYDEBUG",
270 " if (yydebug)",
271 " {",
272 " yys = 0;",
273 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
274 " if (!yys) yys = \"illegal-symbol\";",
275 " printf(\"%sdebug: state %d, error recovery discards token %d\
276 (%s)\\n\",",
277 " YYPREFIX, yystate, yychar, yys);",
278 " }",
279 "#endif",
280 " yychar = YYEMPTY;",
281 " goto yyloop;",
282 " }",
284 "yyreduce:",
285 "#if YYDEBUG",
286 " if (yydebug)",
287 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
288 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
289 "#endif",
290 " yym = yylen[yyn];",
291 " if (yym)",
292 " yyval = yyvsp[1-yym];",
293 " else",
294 " memset(&yyval, 0, sizeof yyval);",
295 " switch (yyn)",
296 " {",
300 const char * const trailer[] =
302 " }",
303 " yyssp -= yym;",
304 " yystate = *yyssp;",
305 " yyvsp -= yym;",
306 " yym = yylhs[yyn];",
307 " if (yystate == 0 && yym == 0)",
308 " {",
309 "#if YYDEBUG",
310 " if (yydebug)",
311 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
312 " state %d\\n\", YYPREFIX, YYFINAL);",
313 "#endif",
314 " yystate = YYFINAL;",
315 " *++yyssp = YYFINAL;",
316 " *++yyvsp = yyval;",
317 " if (yychar < 0)",
318 " {",
319 " if ((yychar = yylex(\002)) < 0) yychar = 0;",
320 "#if YYDEBUG",
321 " if (yydebug)",
322 " {",
323 " yys = 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);",
328 " }",
329 "#endif",
330 " }",
331 " if (yychar == 0) goto yyaccept;",
332 " goto yyloop;",
333 " }",
334 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
335 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
336 " yystate = yytable[yyn];",
337 " else",
338 " yystate = yydgoto[yym];",
339 "#if YYDEBUG",
340 " if (yydebug)",
341 " printf(\"%sdebug: after reduction, shifting from state %d \\",
342 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
343 "#endif",
344 " if (yyssp >= yysslim && yygrowstack(&yyss, &yyssp,",
345 " &yysslim, &yyvs, &yyvsp, &yystacksize))",
346 " {",
347 " goto yyoverflow;",
348 " }",
349 " *++yyssp = (short) yystate;",
350 " *++yyvsp = yyval;",
351 " goto yyloop;",
353 "yyoverflow:",
354 " yyerror(\001\"yacc stack overflow\");",
356 "yyabort:",
357 " free(yyss);",
358 " free(yyvs);",
359 " return (1);",
361 "yyaccept:",
362 " free(yyss);",
363 " free(yyvs);",
364 " return (0);",
365 "}",
369 void
370 write_section(const char * const section[], int dodecls)
372 int c;
373 int i;
374 const char *s;
375 const char *comma;
376 param *p;
377 FILE *f;
379 f = code_file;
380 for (i = 0; (s = section[i]) != 0; ++i)
382 ++outline;
383 while ((c = *s) != 0)
385 switch (c) {
386 case '\001':
387 p = parse_param;
388 for (; p != NULL; p = p->next)
389 fprintf(f, "%s, ", p->name);
390 break;
392 case '\002':
393 p = lex_param;
394 if (pure_parser) {
395 fprintf(f, "&yylval");
396 comma = ", ";
397 } else
398 comma = "";
399 for (; p != NULL; p = p->next) {
400 fprintf(f, "%s%s", comma, p->name);
401 comma = ", ";
403 break;
405 case '\003':
406 if (!dodecls)
407 break;
408 fprintf(f,
409 " int yynerrs;\n"
410 " int yychar;\n"
411 " YYSTYPE yylval;");
412 break;
414 default:
415 putc(c, f);
416 break;
418 ++s;
420 putc('\n', f);