Change .Fx to .Dx where appropriate.
[dragonfly.git] / usr.bin / yacc / skeleton.c
blob8a6b97fe3303346b21bb6260615986569b347d52
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.6 2006/01/22 13:38:50 swildner 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 "#define YYBYACC 1",
59 "#define YYMAJOR 1",
60 "#define YYMINOR 9",
61 "#define YYLEX yylex()",
62 "#define YYEMPTY -1",
63 "#define yyclearin (yychar=(YYEMPTY))",
64 "#define yyerrok (yyerrflag=0)",
65 "#define YYRECOVERING() (yyerrflag!=0)",
66 "#if defined(__cplusplus) || __STDC__",
67 "static int yygrowstack(void);",
68 "#else",
69 "static int yygrowstack();",
70 "#endif",
71 NULL
74 const char *tables[] = {
75 "extern const short yylhs[];",
76 "extern const short yylen[];",
77 "extern const short yydefred[];",
78 "extern const short yydgoto[];",
79 "extern const short yysindex[];",
80 "extern const short yyrindex[];",
81 "extern const short yygindex[];",
82 "extern const short yytable[];",
83 "extern const short yycheck[];",
84 "#if YYDEBUG",
85 "extern char *yyname[];",
86 "extern char *yyrule[];",
87 "#endif",
88 NULL
91 const char *header[] = {
92 "#if YYDEBUG",
93 "#include <stdio.h>",
94 "#endif",
95 "#ifdef YYSTACKSIZE",
96 "#undef YYMAXDEPTH",
97 "#define YYMAXDEPTH YYSTACKSIZE",
98 "#else",
99 "#ifdef YYMAXDEPTH",
100 "#define YYSTACKSIZE YYMAXDEPTH",
101 "#else",
102 "#define YYSTACKSIZE 10000",
103 "#define YYMAXDEPTH 10000",
104 "#endif",
105 "#endif",
106 "#define YYINITSTACKSIZE 200",
107 "int yydebug;",
108 "int yynerrs;",
109 "int yyerrflag;",
110 "int yychar;",
111 "short *yyssp;",
112 "YYSTYPE *yyvsp;",
113 "YYSTYPE yyval;",
114 "YYSTYPE yylval;",
115 "short *yyss;",
116 "short *yysslim;",
117 "YYSTYPE *yyvs;",
118 "int yystacksize;",
119 NULL
122 const char *body[] = {
123 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
124 "static int yygrowstack(void)",
125 "{",
126 " int newsize, i;",
127 " short *newss;",
128 " YYSTYPE *newvs;",
130 " if ((newsize = yystacksize) == 0)",
131 " newsize = YYINITSTACKSIZE;",
132 " else if (newsize >= YYMAXDEPTH)",
133 " return -1;",
134 " else if ((newsize *= 2) > YYMAXDEPTH)",
135 " newsize = YYMAXDEPTH;",
136 " i = yyssp - yyss;",
137 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
138 " (short *)malloc(newsize * sizeof *newss);",
139 " if (newss == NULL)",
140 " return -1;",
141 " yyss = newss;",
142 " yyssp = newss + i;",
143 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
144 " (YYSTYPE *)malloc(newsize * sizeof *newvs);",
145 " if (newvs == NULL)",
146 " return -1;",
147 " yyvs = newvs;",
148 " yyvsp = newvs + i;",
149 " yystacksize = newsize;",
150 " yysslim = yyss + newsize - 1;",
151 " return 0;",
152 "}",
154 "#define YYABORT goto yyabort",
155 "#define YYREJECT goto yyabort",
156 "#define YYACCEPT goto yyaccept",
157 "#define YYERROR goto yyerrlab",
159 "#ifndef YYPARSE_PARAM",
160 "#if defined(__cplusplus) || __STDC__",
161 "#define YYPARSE_PARAM_ARG void",
162 "#define YYPARSE_PARAM_DECL",
163 "#else /* ! ANSI-C/C++ */",
164 "#define YYPARSE_PARAM_ARG",
165 "#define YYPARSE_PARAM_DECL",
166 "#endif /* ANSI-C/C++ */",
167 "#else /* YYPARSE_PARAM */",
168 "#ifndef YYPARSE_PARAM_TYPE",
169 "#define YYPARSE_PARAM_TYPE void *",
170 "#endif",
171 "#if defined(__cplusplus) || __STDC__",
172 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
173 "#define YYPARSE_PARAM_DECL",
174 "#else /* ! ANSI-C/C++ */",
175 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
176 "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
177 "#endif /* ANSI-C/C++ */",
178 "#endif /* ! YYPARSE_PARAM */",
180 "int",
181 "yyparse (YYPARSE_PARAM_ARG)",
182 " YYPARSE_PARAM_DECL",
183 "{",
184 " int yym, yyn, yystate;",
185 "#if YYDEBUG",
186 " const char *yys;",
188 " if ((yys = getenv(\"YYDEBUG\")))",
189 " {",
190 " yyn = *yys;",
191 " if (yyn >= '0' && yyn <= '9')",
192 " yydebug = yyn - '0';",
193 " }",
194 "#endif",
196 " yynerrs = 0;",
197 " yyerrflag = 0;",
198 " yychar = (-1);",
200 " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
201 " yyssp = yyss;",
202 " yyvsp = yyvs;",
203 " *yyssp = yystate = 0;",
205 "yyloop:",
206 " if ((yyn = yydefred[yystate])) goto yyreduce;",
207 " if (yychar < 0)",
208 " {",
209 " if ((yychar = yylex()) < 0) yychar = 0;",
210 "#if YYDEBUG",
211 " if (yydebug)",
212 " {",
213 " yys = 0;",
214 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
215 " if (!yys) yys = \"illegal-symbol\";",
216 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
217 " YYPREFIX, yystate, yychar, yys);",
218 " }",
219 "#endif",
220 " }",
221 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
222 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
223 " {",
224 "#if YYDEBUG",
225 " if (yydebug)",
226 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
227 " YYPREFIX, yystate, yytable[yyn]);",
228 "#endif",
229 " if (yyssp >= yysslim && yygrowstack())",
230 " {",
231 " goto yyoverflow;",
232 " }",
233 " *++yyssp = yystate = yytable[yyn];",
234 " *++yyvsp = yylval;",
235 " yychar = (-1);",
236 " if (yyerrflag > 0) --yyerrflag;",
237 " goto yyloop;",
238 " }",
239 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
240 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
241 " {",
242 " yyn = yytable[yyn];",
243 " goto yyreduce;",
244 " }",
245 " if (yyerrflag) goto yyinrecovery;",
246 "#if defined(lint) || defined(__GNUC__)",
247 " goto yynewerror;",
248 "#endif",
249 "yynewerror:",
250 " yyerror(\"syntax error\");",
251 "#if defined(lint) || defined(__GNUC__)",
252 " goto yyerrlab;",
253 "#endif",
254 "yyerrlab:",
255 " ++yynerrs;",
256 "yyinrecovery:",
257 " if (yyerrflag < 3)",
258 " {",
259 " yyerrflag = 3;",
260 " for (;;)",
261 " {",
262 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
263 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
264 " {",
265 "#if YYDEBUG",
266 " if (yydebug)",
267 " printf(\"%sdebug: state %d, error recovery shifting\\",
268 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
269 "#endif",
270 " if (yyssp >= yysslim && yygrowstack())",
271 " {",
272 " goto yyoverflow;",
273 " }",
274 " *++yyssp = yystate = yytable[yyn];",
275 " *++yyvsp = yylval;",
276 " goto yyloop;",
277 " }",
278 " else",
279 " {",
280 "#if YYDEBUG",
281 " if (yydebug)",
282 " printf(\"%sdebug: error recovery discarding state %d\
283 \\n\",",
284 " YYPREFIX, *yyssp);",
285 "#endif",
286 " if (yyssp <= yyss) goto yyabort;",
287 " --yyssp;",
288 " --yyvsp;",
289 " }",
290 " }",
291 " }",
292 " else",
293 " {",
294 " if (yychar == 0) goto yyabort;",
295 "#if YYDEBUG",
296 " if (yydebug)",
297 " {",
298 " yys = 0;",
299 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
300 " if (!yys) yys = \"illegal-symbol\";",
301 " printf(\"%sdebug: state %d, error recovery discards token %d\
302 (%s)\\n\",",
303 " YYPREFIX, yystate, yychar, yys);",
304 " }",
305 "#endif",
306 " yychar = (-1);",
307 " goto yyloop;",
308 " }",
309 "yyreduce:",
310 "#if YYDEBUG",
311 " if (yydebug)",
312 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
313 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
314 "#endif",
315 " yym = yylen[yyn];",
316 " yyval = yyvsp[1-yym];",
317 " switch (yyn)",
318 " {",
319 NULL
322 const char *trailer[] = {
323 " }",
324 " yyssp -= yym;",
325 " yystate = *yyssp;",
326 " yyvsp -= yym;",
327 " yym = yylhs[yyn];",
328 " if (yystate == 0 && yym == 0)",
329 " {",
330 "#if YYDEBUG",
331 " if (yydebug)",
332 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
333 " state %d\\n\", YYPREFIX, YYFINAL);",
334 "#endif",
335 " yystate = YYFINAL;",
336 " *++yyssp = YYFINAL;",
337 " *++yyvsp = yyval;",
338 " if (yychar < 0)",
339 " {",
340 " if ((yychar = yylex()) < 0) yychar = 0;",
341 "#if YYDEBUG",
342 " if (yydebug)",
343 " {",
344 " yys = 0;",
345 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
346 " if (!yys) yys = \"illegal-symbol\";",
347 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
348 " YYPREFIX, YYFINAL, yychar, yys);",
349 " }",
350 "#endif",
351 " }",
352 " if (yychar == 0) goto yyaccept;",
353 " goto yyloop;",
354 " }",
355 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
356 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
357 " yystate = yytable[yyn];",
358 " else",
359 " yystate = yydgoto[yym];",
360 "#if YYDEBUG",
361 " if (yydebug)",
362 " printf(\"%sdebug: after reduction, shifting from state %d \\",
363 "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
364 "#endif",
365 " if (yyssp >= yysslim && yygrowstack())",
366 " {",
367 " goto yyoverflow;",
368 " }",
369 " *++yyssp = yystate;",
370 " *++yyvsp = yyval;",
371 " goto yyloop;",
372 "yyoverflow:",
373 " yyerror(\"yacc stack overflow\");",
374 "yyabort:",
375 " return (1);",
376 "yyaccept:",
377 " return (0);",
378 "}",
379 NULL
383 void
384 write_section(const char **section)
386 int c;
387 int i;
388 const char *s;
389 FILE *f;
391 f = code_file;
392 for (i = 0; (s = section[i]); ++i)
394 ++outline;
395 while ((c = *s))
397 putc(c, f);
398 ++s;
400 putc('\n', f);