vm: merge i386 and arm pagetable code
[minix.git] / external / bsd / byacc / dist / skeleton.c
blob18443093c5f0aa097d593d5d2219452c5da9a364
1 /* $NetBSD: skeleton.c,v 1.10 2011/09/10 21:29:04 christos Exp $ */
2 /* Id: skeleton.c,v 1.31 2011/09/07 09:37:59 tom Exp */
4 #include "defs.h"
6 #include <sys/cdefs.h>
7 __RCSID("$NetBSD: skeleton.c,v 1.10 2011/09/10 21:29:04 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 xdecls[] =
50 "",
51 "extern int YYPARSE_DECL();",
52 #ifdef notdef
53 "extern int YYLEX_DECL();",
54 #endif
55 "",
59 const char *const tables[] =
61 "extern short yylhs[];",
62 "extern short yylen[];",
63 "extern short yydefred[];",
64 "extern short yydgoto[];",
65 "extern short yysindex[];",
66 "extern short yyrindex[];",
67 "extern short yygindex[];",
68 "extern short yytable[];",
69 "extern short yycheck[];",
70 "",
71 "#if YYDEBUG",
72 "extern char *yyname[];",
73 "extern char *yyrule[];",
74 "#endif",
78 const char *const global_vars[] =
80 "",
81 "int yydebug;",
82 "int yynerrs;",
86 const char *const impure_vars[] =
88 "",
89 "int yyerrflag;",
90 "int yychar;",
91 "YYSTYPE yyval;",
92 "YYSTYPE yylval;",
96 const char *const hdr_defs[] =
98 "",
99 "/* define the initial stack-sizes */",
100 "#ifdef YYSTACKSIZE",
101 "#undef YYMAXDEPTH",
102 "#define YYMAXDEPTH YYSTACKSIZE",
103 "#else",
104 "#ifdef YYMAXDEPTH",
105 "#define YYSTACKSIZE YYMAXDEPTH",
106 "#else",
107 "#define YYSTACKSIZE 500",
108 "#define YYMAXDEPTH 500",
109 "#endif",
110 "#endif",
112 "#define YYINITSTACKSIZE 500",
114 "typedef struct {",
115 " unsigned stacksize;",
116 " short *s_base;",
117 " short *s_mark;",
118 " short *s_last;",
119 " YYSTYPE *l_base;",
120 " YYSTYPE *l_mark;",
121 "} YYSTACKDATA;",
125 const char *const hdr_vars[] =
127 "/* variables for the parser stack */",
128 "static YYSTACKDATA yystack;",
132 const char *const body_vars[] =
134 " int yyerrflag;",
135 " int yychar;",
136 " YYSTYPE yyval;",
137 " YYSTYPE yylval;",
139 " /* variables for the parser stack */",
140 " YYSTACKDATA yystack;",
144 const char *const body_1[] =
147 "#if YYDEBUG",
148 "#include <stdio.h> /* needed for printf */",
149 "#endif",
151 "#include <stdlib.h> /* needed for malloc, etc */",
152 "#include <string.h> /* needed for memset */",
154 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
155 "static int yygrowstack(YYSTACKDATA *data)",
156 "{",
157 " int i;",
158 " unsigned newsize;",
159 " short *newss;",
160 " YYSTYPE *newvs;",
162 " if ((newsize = data->stacksize) == 0)",
163 " newsize = YYINITSTACKSIZE;",
164 " else if (newsize >= YYMAXDEPTH)",
165 " return -1;",
166 " else if ((newsize *= 2) > YYMAXDEPTH)",
167 " newsize = YYMAXDEPTH;",
169 " i = data->s_mark - data->s_base;",
170 " newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
171 " if (newss == 0)",
172 " return -1;",
174 " data->s_base = newss;",
175 " data->s_mark = newss + i;",
177 " newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
178 " if (newvs == 0)",
179 " return -1;",
181 " data->l_base = newvs;",
182 " data->l_mark = newvs + i;",
184 " data->stacksize = newsize;",
185 " data->s_last = data->s_base + newsize - 1;",
186 " return 0;",
187 "}",
189 "#if YYPURE || defined(YY_NO_LEAKS)",
190 "static void yyfreestack(YYSTACKDATA *data)",
191 "{",
192 " free(data->s_base);",
193 " free(data->l_base);",
194 " memset(data, 0, sizeof(*data));",
195 "}",
196 "#else",
197 "#define yyfreestack(data) /* nothing */",
198 "#endif",
200 "#define YYABORT goto yyabort",
201 "#define YYREJECT goto yyabort",
202 "#define YYACCEPT goto yyaccept",
203 "#define YYERROR goto yyerrlab",
205 "int",
206 "YYPARSE_DECL()",
207 "{",
211 const char *const body_2[] =
213 " int yym, yyn, yystate;",
214 "#if YYDEBUG",
215 " const char *yys;",
217 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
218 " {",
219 " yyn = *yys;",
220 " if (yyn >= '0' && yyn <= '9')",
221 " yydebug = yyn - '0';",
222 " }",
223 "#endif",
225 " yynerrs = 0;",
226 " yyerrflag = 0;",
227 " yychar = YYEMPTY;",
228 " yystate = 0;",
230 "#if YYPURE",
231 " memset(&yystack, 0, sizeof(yystack));",
232 "#endif",
234 " if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
235 " yystack.s_mark = yystack.s_base;",
236 " yystack.l_mark = yystack.l_base;",
237 " yystate = 0;",
238 " *yystack.s_mark = 0;",
240 "yyloop:",
241 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
242 " if (yychar < 0)",
243 " {",
244 " if ((yychar = YYLEX) < 0) yychar = 0;",
245 "#if YYDEBUG",
246 " if (yydebug)",
247 " {",
248 " yys = 0;",
249 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
250 " if (!yys) yys = \"illegal-symbol\";",
251 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
252 " YYPREFIX, yystate, yychar, yys);",
253 " }",
254 "#endif",
255 " }",
256 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
257 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
258 " {",
259 "#if YYDEBUG",
260 " if (yydebug)",
261 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
262 " YYPREFIX, yystate, yytable[yyn]);",
263 "#endif",
264 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
265 " {",
266 " goto yyoverflow;",
267 " }",
268 " yystate = yytable[yyn];",
269 " *++yystack.s_mark = yytable[yyn];",
270 " *++yystack.l_mark = yylval;",
271 " yychar = YYEMPTY;",
272 " if (yyerrflag > 0) --yyerrflag;",
273 " goto yyloop;",
274 " }",
275 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
276 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
277 " {",
278 " yyn = yytable[yyn];",
279 " goto yyreduce;",
280 " }",
281 " if (yyerrflag) goto yyinrecovery;",
286 const char *const body_3[] =
289 " goto yyerrlab;",
291 "yyerrlab:",
292 " ++yynerrs;",
294 "yyinrecovery:",
295 " if (yyerrflag < 3)",
296 " {",
297 " yyerrflag = 3;",
298 " for (;;)",
299 " {",
300 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
301 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
302 " {",
303 "#if YYDEBUG",
304 " if (yydebug)",
305 " printf(\"%sdebug: state %d, error recovery shifting\\",
306 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
307 "#endif",
308 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
309 " {",
310 " goto yyoverflow;",
311 " }",
312 " yystate = yytable[yyn];",
313 " *++yystack.s_mark = yytable[yyn];",
314 " *++yystack.l_mark = yylval;",
315 " goto yyloop;",
316 " }",
317 " else",
318 " {",
319 "#if YYDEBUG",
320 " if (yydebug)",
321 " printf(\"%sdebug: error recovery discarding state %d\
322 \\n\",",
323 " YYPREFIX, *yystack.s_mark);",
324 "#endif",
325 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
326 " --yystack.s_mark;",
327 " --yystack.l_mark;",
328 " }",
329 " }",
330 " }",
331 " else",
332 " {",
333 " if (yychar == 0) goto yyabort;",
334 "#if YYDEBUG",
335 " if (yydebug)",
336 " {",
337 " yys = 0;",
338 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
339 " if (!yys) yys = \"illegal-symbol\";",
340 " printf(\"%sdebug: state %d, error recovery discards token %d\
341 (%s)\\n\",",
342 " YYPREFIX, yystate, yychar, yys);",
343 " }",
344 "#endif",
345 " yychar = YYEMPTY;",
346 " goto yyloop;",
347 " }",
349 "yyreduce:",
350 "#if YYDEBUG",
351 " if (yydebug)",
352 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
353 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
354 "#endif",
355 " yym = yylen[yyn];",
356 " if (yym)",
357 " yyval = yystack.l_mark[1-yym];",
358 " else",
359 " memset(&yyval, 0, sizeof yyval);",
360 " switch (yyn)",
361 " {",
365 const char *const trailer[] =
367 " }",
368 " yystack.s_mark -= yym;",
369 " yystate = *yystack.s_mark;",
370 " yystack.l_mark -= yym;",
371 " yym = yylhs[yyn];",
372 " if (yystate == 0 && yym == 0)",
373 " {",
374 "#if YYDEBUG",
375 " if (yydebug)",
376 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
377 " state %d\\n\", YYPREFIX, YYFINAL);",
378 "#endif",
379 " yystate = YYFINAL;",
380 " *++yystack.s_mark = YYFINAL;",
381 " *++yystack.l_mark = yyval;",
382 " if (yychar < 0)",
383 " {",
384 " if ((yychar = YYLEX) < 0) yychar = 0;",
385 "#if YYDEBUG",
386 " if (yydebug)",
387 " {",
388 " yys = 0;",
389 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
390 " if (!yys) yys = \"illegal-symbol\";",
391 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
392 " YYPREFIX, YYFINAL, yychar, yys);",
393 " }",
394 "#endif",
395 " }",
396 " if (yychar == 0) goto yyaccept;",
397 " goto yyloop;",
398 " }",
399 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
400 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
401 " yystate = yytable[yyn];",
402 " else",
403 " yystate = yydgoto[yym];",
404 "#if YYDEBUG",
405 " if (yydebug)",
406 " printf(\"%sdebug: after reduction, shifting from state %d \\",
407 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
408 "#endif",
409 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
410 " {",
411 " goto yyoverflow;",
412 " }",
413 " *++yystack.s_mark = (short) yystate;",
414 " *++yystack.l_mark = yyval;",
415 " goto yyloop;",
417 "yyoverflow:",
421 const char *const trailer_2[] =
424 "yyabort:",
425 " yyfreestack(&yystack);",
426 " return (1);",
428 "yyaccept:",
429 " yyfreestack(&yystack);",
430 " return (0);",
431 "}",
435 void
436 write_section(FILE * fp, const char *const section[])
438 int c;
439 int i;
440 const char *s;
442 for (i = 0; (s = section[i]) != 0; ++i)
444 while ((c = *s) != 0)
446 putc(c, fp);
447 ++s;
449 if (fp == code_file)
450 ++outline;
451 putc('\n', fp);