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