Pre-2.0 release, synchronize with HAMMER 61H
[dragonfly.git] / usr.bin / yacc / skeleton.c
blobf089c8a113539ed8b1f832bc389ac692c70da73f
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Robert Paul Corbett.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
36 * @(#)skeleton.c 5.8 (Berkeley) 4/29/95
38 * $FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28.2.1 2001/07/19 05:46:39 peter Exp $
39 * $DragonFly: src/usr.bin/yacc/skeleton.c,v 1.7 2008/07/12 16:52:48 mneumann Exp $
42 #include "defs.h"
44 /* The definition of yysccsid in the banner should be replaced with */
45 /* a #pragma ident directive if the target C compiler supports */
46 /* #pragma ident directives. */
47 /* */
48 /* If the skeleton is changed, the banner should be changed so that */
49 /* the altered version can be easily distinguished from the original. */
50 /* */
51 /* The #defines included with the banner are there because they are */
52 /* useful in subsequent code. The macros #defined in the header or */
53 /* the body either are not useful outside of semantic actions or */
54 /* are conditional. */
56 const char *banner[] = {
57 "#include <stdlib.h>",
58 "#include <string.h>",
59 "#define YYBYACC 1",
60 "#define YYMAJOR 1",
61 "#define YYMINOR 9",
62 "#define YYLEX yylex()",
63 "#define YYEMPTY -1",
64 "#define yyclearin (yychar=(YYEMPTY))",
65 "#define yyerrok (yyerrflag=0)",
66 "#define YYRECOVERING() (yyerrflag!=0)",
67 "#if defined(__cplusplus) || __STDC__",
68 "static int yygrowstack(void);",
69 "#else",
70 "static int yygrowstack();",
71 "#endif",
72 NULL
75 const char *tables[] = {
76 "extern const short yylhs[];",
77 "extern const short yylen[];",
78 "extern const short yydefred[];",
79 "extern const short yydgoto[];",
80 "extern const short yysindex[];",
81 "extern const short yyrindex[];",
82 "extern const short yygindex[];",
83 "extern const short yytable[];",
84 "extern const short yycheck[];",
85 "#if YYDEBUG",
86 "extern char *yyname[];",
87 "extern char *yyrule[];",
88 "#endif",
89 NULL
92 const char *header[] = {
93 "#if YYDEBUG",
94 "#include <stdio.h>",
95 "#endif",
96 "#ifdef YYSTACKSIZE",
97 "#undef YYMAXDEPTH",
98 "#define YYMAXDEPTH YYSTACKSIZE",
99 "#else",
100 "#ifdef YYMAXDEPTH",
101 "#define YYSTACKSIZE YYMAXDEPTH",
102 "#else",
103 "#define YYSTACKSIZE 10000",
104 "#define YYMAXDEPTH 10000",
105 "#endif",
106 "#endif",
107 "#define YYINITSTACKSIZE 200",
108 "int yydebug;",
109 "int yynerrs;",
110 "int yyerrflag;",
111 "int yychar;",
112 "short *yyssp;",
113 "YYSTYPE *yyvsp;",
114 "YYSTYPE yyval;",
115 "YYSTYPE yylval;",
116 "short *yyss;",
117 "short *yysslim;",
118 "YYSTYPE *yyvs;",
119 "int yystacksize;",
120 NULL
123 const char *body[] = {
124 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
125 "static int yygrowstack(void)",
126 "{",
127 " int newsize, i;",
128 " short *newss;",
129 " YYSTYPE *newvs;",
131 " if ((newsize = yystacksize) == 0)",
132 " newsize = YYINITSTACKSIZE;",
133 " else if (newsize >= YYMAXDEPTH)",
134 " return -1;",
135 " else if ((newsize *= 2) > YYMAXDEPTH)",
136 " newsize = YYMAXDEPTH;",
137 " i = yyssp - yyss;",
138 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
139 " (short *)malloc(newsize * sizeof *newss);",
140 " if (newss == NULL)",
141 " return -1;",
142 " yyss = newss;",
143 " yyssp = newss + i;",
144 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
145 " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
146 " if (newvs == NULL)",
147 " return -1;",
148 " yyvs = newvs;",
149 " yyvsp = newvs + i;",
150 " yystacksize = newsize;",
151 " yysslim = yyss + newsize - 1;",
152 " return 0;",
153 "}",
155 "#define YYABORT goto yyabort",
156 "#define YYREJECT goto yyabort",
157 "#define YYACCEPT goto yyaccept",
158 "#define YYERROR goto yyerrlab",
160 "#ifndef YYPARSE_PARAM",
161 "#if defined(__cplusplus) || __STDC__",
162 "#define YYPARSE_PARAM_ARG void",
163 "#define YYPARSE_PARAM_DECL",
164 "#else /* ! ANSI-C/C++ */",
165 "#define YYPARSE_PARAM_ARG",
166 "#define YYPARSE_PARAM_DECL",
167 "#endif /* ANSI-C/C++ */",
168 "#else /* YYPARSE_PARAM */",
169 "#ifndef YYPARSE_PARAM_TYPE",
170 "#define YYPARSE_PARAM_TYPE void *",
171 "#endif",
172 "#if defined(__cplusplus) || __STDC__",
173 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
174 "#define YYPARSE_PARAM_DECL",
175 "#else /* ! ANSI-C/C++ */",
176 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
177 "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
178 "#endif /* ANSI-C/C++ */",
179 "#endif /* ! YYPARSE_PARAM */",
181 "int",
182 "yyparse (YYPARSE_PARAM_ARG)",
183 " YYPARSE_PARAM_DECL",
184 "{",
185 " int yym, yyn, yystate;",
186 "#if YYDEBUG",
187 " const char *yys;",
189 " if ((yys = getenv(\"YYDEBUG\")))",
190 " {",
191 " yyn = *yys;",
192 " if (yyn >= '0' && yyn <= '9')",
193 " yydebug = yyn - '0';",
194 " }",
195 "#endif",
197 " yynerrs = 0;",
198 " yyerrflag = 0;",
199 " yychar = (-1);",
201 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
202 " yyssp = yyss;",
203 " yyvsp = yyvs;",
204 " *yyssp = yystate = 0;",
206 "yyloop:",
207 " if ((yyn = yydefred[yystate])) goto yyreduce;",
208 " if (yychar < 0)",
209 " {",
210 " if ((yychar = yylex()) < 0) yychar = 0;",
211 "#if YYDEBUG",
212 " if (yydebug)",
213 " {",
214 " yys = 0;",
215 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
216 " if (!yys) yys = \"illegal-symbol\";",
217 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
218 " YYPREFIX, yystate, yychar, yys);",
219 " }",
220 "#endif",
221 " }",
222 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
223 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
224 " {",
225 "#if YYDEBUG",
226 " if (yydebug)",
227 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
228 " YYPREFIX, yystate, yytable[yyn]);",
229 "#endif",
230 " if (yyssp >= yysslim && yygrowstack())",
231 " {",
232 " goto yyoverflow;",
233 " }",
234 " *++yyssp = yystate = yytable[yyn];",
235 " *++yyvsp = yylval;",
236 " yychar = (-1);",
237 " if (yyerrflag > 0) --yyerrflag;",
238 " goto yyloop;",
239 " }",
240 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
241 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
242 " {",
243 " yyn = yytable[yyn];",
244 " goto yyreduce;",
245 " }",
246 " if (yyerrflag) goto yyinrecovery;",
247 "#if defined(lint) || defined(__GNUC__)",
248 " goto yynewerror;",
249 "#endif",
250 "yynewerror:",
251 " yyerror(\"syntax error\");",
252 "#if defined(lint) || defined(__GNUC__)",
253 " goto yyerrlab;",
254 "#endif",
255 "yyerrlab:",
256 " ++yynerrs;",
257 "yyinrecovery:",
258 " if (yyerrflag < 3)",
259 " {",
260 " yyerrflag = 3;",
261 " for (;;)",
262 " {",
263 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
264 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
265 " {",
266 "#if YYDEBUG",
267 " if (yydebug)",
268 " printf(\"%sdebug: state %d, error recovery shifting\\",
269 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
270 "#endif",
271 " if (yyssp >= yysslim && yygrowstack())",
272 " {",
273 " goto yyoverflow;",
274 " }",
275 " *++yyssp = yystate = yytable[yyn];",
276 " *++yyvsp = yylval;",
277 " goto yyloop;",
278 " }",
279 " else",
280 " {",
281 "#if YYDEBUG",
282 " if (yydebug)",
283 " printf(\"%sdebug: error recovery discarding state %d\
284 \\n\",",
285 " YYPREFIX, *yyssp);",
286 "#endif",
287 " if (yyssp <= yyss) goto yyabort;",
288 " --yyssp;",
289 " --yyvsp;",
290 " }",
291 " }",
292 " }",
293 " else",
294 " {",
295 " if (yychar == 0) goto yyabort;",
296 "#if YYDEBUG",
297 " if (yydebug)",
298 " {",
299 " yys = 0;",
300 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
301 " if (!yys) yys = \"illegal-symbol\";",
302 " printf(\"%sdebug: state %d, error recovery discards token %d\
303 (%s)\\n\",",
304 " YYPREFIX, yystate, yychar, yys);",
305 " }",
306 "#endif",
307 " yychar = (-1);",
308 " goto yyloop;",
309 " }",
310 "yyreduce:",
311 "#if YYDEBUG",
312 " if (yydebug)",
313 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
314 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
315 "#endif",
316 " yym = yylen[yyn];",
317 " if (yym)",
318 " yyval = yyvsp[1-yym];",
319 " else",
320 " memset(&yyval, 0, sizeof yyval);",
321 " yyval = yyvsp[1-yym];",
322 " switch (yyn)",
323 " {",
324 NULL
327 const char *trailer[] = {
328 " }",
329 " yyssp -= yym;",
330 " yystate = *yyssp;",
331 " yyvsp -= yym;",
332 " yym = yylhs[yyn];",
333 " if (yystate == 0 && yym == 0)",
334 " {",
335 "#if YYDEBUG",
336 " if (yydebug)",
337 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
338 " state %d\\n\", YYPREFIX, YYFINAL);",
339 "#endif",
340 " yystate = YYFINAL;",
341 " *++yyssp = YYFINAL;",
342 " *++yyvsp = yyval;",
343 " if (yychar < 0)",
344 " {",
345 " if ((yychar = yylex()) < 0) yychar = 0;",
346 "#if YYDEBUG",
347 " if (yydebug)",
348 " {",
349 " yys = 0;",
350 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
351 " if (!yys) yys = \"illegal-symbol\";",
352 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
353 " YYPREFIX, YYFINAL, yychar, yys);",
354 " }",
355 "#endif",
356 " }",
357 " if (yychar == 0) goto yyaccept;",
358 " goto yyloop;",
359 " }",
360 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
361 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
362 " yystate = yytable[yyn];",
363 " else",
364 " yystate = yydgoto[yym];",
365 "#if YYDEBUG",
366 " if (yydebug)",
367 " printf(\"%sdebug: after reduction, shifting from state %d \\",
368 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
369 "#endif",
370 " if (yyssp >= yysslim && yygrowstack())",
371 " {",
372 " goto yyoverflow;",
373 " }",
374 " *++yyssp = yystate;",
375 " *++yyvsp = yyval;",
376 " goto yyloop;",
377 "yyoverflow:",
378 " yyerror(\"yacc stack overflow\");",
379 "yyabort:",
380 " return (1);",
381 "yyaccept:",
382 " return (0);",
383 "}",
384 NULL
388 void
389 write_section(const char **section)
391 int c;
392 int i;
393 const char *s;
394 FILE *f;
396 f = code_file;
397 for (i = 0; (s = section[i]); ++i)
399 ++outline;
400 while ((c = *s))
402 putc(c, f);
403 ++s;
405 putc('\n', f);