tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / skeleton.c
blob21620ee6bc481459e56671c00a75afcbb2acd5a5
1 /* $NetBSD: skeleton.c,v 1.13 2013/09/13 18:53:29 joerg Exp $ */
3 /* Id: skeleton.c,v 1.32 2013/03/04 23:19:39 tom Exp */
5 #include "defs.h"
7 #include <sys/cdefs.h>
8 __RCSID("$NetBSD: skeleton.c,v 1.13 2013/09/13 18:53:29 joerg Exp $");
10 /* The definition of yysccsid in the banner should be replaced with */
11 /* a #pragma ident directive if the target C compiler supports */
12 /* #pragma ident directives. */
13 /* */
14 /* If the skeleton is changed, the banner should be changed so that */
15 /* the altered version can be easily distinguished from the original. */
16 /* */
17 /* The #defines included with the banner are there because they are */
18 /* useful in subsequent code. The macros #defined in the header or */
19 /* the body either are not useful outside of semantic actions or */
20 /* are conditional. */
22 const char *const banner[] =
24 "#ifndef lint",
25 "#if __GNUC__ - 0 >= 4 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ >= 1)",
26 "__attribute__((__used__))",
27 "#endif",
28 "static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
29 "#endif",
30 "",
31 "#ifdef _LIBC",
32 "#include \"namespace.h\"",
33 "#endif",
34 "#include <stdlib.h>",
35 "#include <string.h>",
36 "",
37 "#define YYBYACC 1",
38 CONCAT1("#define YYMAJOR ", YYMAJOR),
39 CONCAT1("#define YYMINOR ", YYMINOR),
40 #ifdef YYPATCH
41 CONCAT1("#define YYPATCH ", YYPATCH),
42 #endif
43 "",
44 "#define YYEMPTY (-1)",
45 "#define yyclearin (yychar = YYEMPTY)",
46 "#define yyerrok (yyerrflag = 0)",
47 "#define YYRECOVERING() (yyerrflag != 0)",
48 "",
52 const char *const xdecls[] =
54 "",
55 "extern int YYPARSE_DECL();",
56 #ifdef notdef
57 "extern int YYLEX_DECL();",
58 #endif
59 "",
63 const char *const tables[] =
65 "extern short yylhs[];",
66 "extern short yylen[];",
67 "extern short yydefred[];",
68 "extern short yydgoto[];",
69 "extern short yysindex[];",
70 "extern short yyrindex[];",
71 "extern short yygindex[];",
72 "extern short yytable[];",
73 "extern short yycheck[];",
74 "",
75 "#if YYDEBUG",
76 "extern char *yyname[];",
77 "extern char *yyrule[];",
78 "#endif",
82 const char *const global_vars[] =
84 "",
85 "int yydebug;",
86 "int yynerrs;",
90 const char *const impure_vars[] =
92 "",
93 "int yyerrflag;",
94 "int yychar;",
95 "YYSTYPE yyval;",
96 "YYSTYPE yylval;",
100 const char *const hdr_defs[] =
103 "/* define the initial stack-sizes */",
104 "#ifdef YYSTACKSIZE",
105 "#undef YYMAXDEPTH",
106 "#define YYMAXDEPTH YYSTACKSIZE",
107 "#else",
108 "#ifdef YYMAXDEPTH",
109 "#define YYSTACKSIZE YYMAXDEPTH",
110 "#else",
111 "#define YYSTACKSIZE 500",
112 "#define YYMAXDEPTH 500",
113 "#endif",
114 "#endif",
116 "#define YYINITSTACKSIZE 500",
118 "typedef struct {",
119 " unsigned stacksize;",
120 " short *s_base;",
121 " short *s_mark;",
122 " short *s_last;",
123 " YYSTYPE *l_base;",
124 " YYSTYPE *l_mark;",
125 "} YYSTACKDATA;",
129 const char *const hdr_vars[] =
131 "/* variables for the parser stack */",
132 "static YYSTACKDATA yystack;",
136 const char *const body_vars[] =
138 " int yyerrflag;",
139 " int yychar;",
140 " YYSTYPE yyval;",
141 " YYSTYPE yylval;",
143 " /* variables for the parser stack */",
144 " YYSTACKDATA yystack;",
148 const char *const body_1[] =
151 "#if YYDEBUG",
152 "#include <stdio.h> /* needed for printf */",
153 "#endif",
155 "#include <stdlib.h> /* needed for malloc, etc */",
156 "#include <string.h> /* needed for memset */",
158 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
159 "static int yygrowstack(YYSTACKDATA *data)",
160 "{",
161 " int i;",
162 " unsigned newsize;",
163 " short *newss;",
164 " YYSTYPE *newvs;",
166 " if ((newsize = data->stacksize) == 0)",
167 " newsize = YYINITSTACKSIZE;",
168 " else if (newsize >= YYMAXDEPTH)",
169 " return -1;",
170 " else if ((newsize *= 2) > YYMAXDEPTH)",
171 " newsize = YYMAXDEPTH;",
173 " i = (int) (data->s_mark - data->s_base);",
174 " newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
175 " if (newss == 0)",
176 " return -1;",
178 " data->s_base = newss;",
179 " data->s_mark = newss + i;",
181 " newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
182 " if (newvs == 0)",
183 " return -1;",
185 " data->l_base = newvs;",
186 " data->l_mark = newvs + i;",
188 " data->stacksize = newsize;",
189 " data->s_last = data->s_base + newsize - 1;",
190 " return 0;",
191 "}",
193 "#if YYPURE || defined(YY_NO_LEAKS)",
194 "static void yyfreestack(YYSTACKDATA *data)",
195 "{",
196 " free(data->s_base);",
197 " free(data->l_base);",
198 " memset(data, 0, sizeof(*data));",
199 "}",
200 "#else",
201 "#define yyfreestack(data) /* nothing */",
202 "#endif",
204 "#define YYABORT goto yyabort",
205 "#define YYREJECT goto yyabort",
206 "#define YYACCEPT goto yyaccept",
207 "#define YYERROR goto yyerrlab",
209 "int",
210 "YYPARSE_DECL()",
211 "{",
215 const char *const body_2[] =
217 " int yym, yyn, yystate;",
218 "#if YYDEBUG",
219 " const char *yys;",
221 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
222 " {",
223 " yyn = *yys;",
224 " if (yyn >= '0' && yyn <= '9')",
225 " yydebug = yyn - '0';",
226 " }",
227 "#endif",
229 " yynerrs = 0;",
230 " yyerrflag = 0;",
231 " yychar = YYEMPTY;",
232 " yystate = 0;",
234 "#if YYPURE",
235 " memset(&yystack, 0, sizeof(yystack));",
236 "#endif",
238 " if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
239 " yystack.s_mark = yystack.s_base;",
240 " yystack.l_mark = yystack.l_base;",
241 " yystate = 0;",
242 " *yystack.s_mark = 0;",
244 "yyloop:",
245 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
246 " if (yychar < 0)",
247 " {",
248 " if ((yychar = YYLEX) < 0) yychar = 0;",
249 "#if YYDEBUG",
250 " if (yydebug)",
251 " {",
252 " yys = 0;",
253 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
254 " if (!yys) yys = \"illegal-symbol\";",
255 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
256 " YYPREFIX, yystate, yychar, yys);",
257 " }",
258 "#endif",
259 " }",
260 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
261 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
262 " {",
263 "#if YYDEBUG",
264 " if (yydebug)",
265 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
266 " YYPREFIX, yystate, yytable[yyn]);",
267 "#endif",
268 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
269 " {",
270 " goto yyoverflow;",
271 " }",
272 " yystate = yytable[yyn];",
273 " *++yystack.s_mark = yytable[yyn];",
274 " *++yystack.l_mark = yylval;",
275 " yychar = YYEMPTY;",
276 " if (yyerrflag > 0) --yyerrflag;",
277 " goto yyloop;",
278 " }",
279 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
280 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
281 " {",
282 " yyn = yytable[yyn];",
283 " goto yyreduce;",
284 " }",
285 " if (yyerrflag) goto yyinrecovery;",
290 const char *const body_3[] =
293 " goto yyerrlab;",
295 "yyerrlab:",
296 " ++yynerrs;",
298 "yyinrecovery:",
299 " if (yyerrflag < 3)",
300 " {",
301 " yyerrflag = 3;",
302 " for (;;)",
303 " {",
304 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
305 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
306 " {",
307 "#if YYDEBUG",
308 " if (yydebug)",
309 " printf(\"%sdebug: state %d, error recovery shifting\\",
310 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
311 "#endif",
312 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
313 " {",
314 " goto yyoverflow;",
315 " }",
316 " yystate = yytable[yyn];",
317 " *++yystack.s_mark = yytable[yyn];",
318 " *++yystack.l_mark = yylval;",
319 " goto yyloop;",
320 " }",
321 " else",
322 " {",
323 "#if YYDEBUG",
324 " if (yydebug)",
325 " printf(\"%sdebug: error recovery discarding state %d\
326 \\n\",",
327 " YYPREFIX, *yystack.s_mark);",
328 "#endif",
329 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
330 " --yystack.s_mark;",
331 " --yystack.l_mark;",
332 " }",
333 " }",
334 " }",
335 " else",
336 " {",
337 " if (yychar == 0) goto yyabort;",
338 "#if YYDEBUG",
339 " if (yydebug)",
340 " {",
341 " yys = 0;",
342 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
343 " if (!yys) yys = \"illegal-symbol\";",
344 " printf(\"%sdebug: state %d, error recovery discards token %d\
345 (%s)\\n\",",
346 " YYPREFIX, yystate, yychar, yys);",
347 " }",
348 "#endif",
349 " yychar = YYEMPTY;",
350 " goto yyloop;",
351 " }",
353 "yyreduce:",
354 "#if YYDEBUG",
355 " if (yydebug)",
356 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
357 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
358 "#endif",
359 " yym = yylen[yyn];",
360 " if (yym)",
361 " yyval = yystack.l_mark[1-yym];",
362 " else",
363 " memset(&yyval, 0, sizeof yyval);",
364 " switch (yyn)",
365 " {",
369 const char *const trailer[] =
371 " }",
372 " yystack.s_mark -= yym;",
373 " yystate = *yystack.s_mark;",
374 " yystack.l_mark -= yym;",
375 " yym = yylhs[yyn];",
376 " if (yystate == 0 && yym == 0)",
377 " {",
378 "#if YYDEBUG",
379 " if (yydebug)",
380 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
381 " state %d\\n\", YYPREFIX, YYFINAL);",
382 "#endif",
383 " yystate = YYFINAL;",
384 " *++yystack.s_mark = YYFINAL;",
385 " *++yystack.l_mark = yyval;",
386 " if (yychar < 0)",
387 " {",
388 " if ((yychar = YYLEX) < 0) yychar = 0;",
389 "#if YYDEBUG",
390 " if (yydebug)",
391 " {",
392 " yys = 0;",
393 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
394 " if (!yys) yys = \"illegal-symbol\";",
395 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
396 " YYPREFIX, YYFINAL, yychar, yys);",
397 " }",
398 "#endif",
399 " }",
400 " if (yychar == 0) goto yyaccept;",
401 " goto yyloop;",
402 " }",
403 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
404 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
405 " yystate = yytable[yyn];",
406 " else",
407 " yystate = yydgoto[yym];",
408 "#if YYDEBUG",
409 " if (yydebug)",
410 " printf(\"%sdebug: after reduction, shifting from state %d \\",
411 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
412 "#endif",
413 " if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
414 " {",
415 " goto yyoverflow;",
416 " }",
417 " *++yystack.s_mark = (short) yystate;",
418 " *++yystack.l_mark = yyval;",
419 " goto yyloop;",
421 "yyoverflow:",
425 const char *const trailer_2[] =
428 "yyabort:",
429 " yyfreestack(&yystack);",
430 " return (1);",
432 "yyaccept:",
433 " yyfreestack(&yystack);",
434 " return (0);",
435 "}",
439 void
440 write_section(FILE * fp, const char *const section[])
442 int c;
443 int i;
444 const char *s;
446 for (i = 0; (s = section[i]) != 0; ++i)
448 while ((c = *s) != 0)
450 putc(c, fp);
451 ++s;
453 if (fp == code_file)
454 ++outline;
455 putc('\n', fp);