]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/yacc/skeleton.c
This commit was generated by cvs2svn to compensate for changes in r175790,
[FreeBSD/FreeBSD.git] / usr.bin / yacc / skeleton.c
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Robert Paul Corbett.
7  *
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.
23  *
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.
35  */
36
37 #if 0
38 #ifndef lint
39 static char sccsid[] = "@(#)skeleton.c  5.8 (Berkeley) 4/29/95";
40 #endif
41 #endif
42
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
45
46 #include "defs.h"
47
48 /*  The definition of yysccsid in the banner should be replaced with    */
49 /*  a #pragma ident directive if the target C compiler supports         */
50 /*  #pragma ident directives.                                           */
51 /*                                                                      */
52 /*  If the skeleton is changed, the banner should be changed so that    */
53 /*  the altered version can be easily distinguished from the original.  */
54 /*                                                                      */
55 /*  The #defines included with the banner are there because they are    */
56 /*  useful in subsequent code.  The macros #defined in the header or    */
57 /*  the body either are not useful outside of semantic actions or       */
58 /*  are conditional.                                                    */
59
60 const char *banner[] =
61 {
62     "#include <stdlib.h>",
63     "#ifndef lint",
64     "#ifdef __unused",
65     "__unused",
66     "#endif",
67     "static char const ",
68     "yyrcsid[] = \"$FreeBSD$\";",
69     "#endif",
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)",
78     "#if defined(__cplusplus) || __STDC__",
79     "static int yygrowstack(void);",
80     "#else",
81     "static int yygrowstack();",
82     "#endif",
83     0
84 };
85
86
87 const char *tables[] =
88 {
89     "extern const short yylhs[];",
90     "extern const short yylen[];",
91     "extern const short yydefred[];",
92     "extern const short yydgoto[];",
93     "extern const short yysindex[];",
94     "extern const short yyrindex[];",
95     "extern const short yygindex[];",
96     "extern const short yytable[];",
97     "extern const short yycheck[];",
98     "#if YYDEBUG",
99     "extern char *yyname[];",
100     "extern char *yyrule[];",
101     "#endif",
102     0
103 };
104
105
106 const char *header[] =
107 {
108     "#if YYDEBUG",
109     "#include <stdio.h>",
110     "#endif",
111     "#ifdef YYSTACKSIZE",
112     "#undef YYMAXDEPTH",
113     "#define YYMAXDEPTH YYSTACKSIZE",
114     "#else",
115     "#ifdef YYMAXDEPTH",
116     "#define YYSTACKSIZE YYMAXDEPTH",
117     "#else",
118     "#define YYSTACKSIZE 10000",
119     "#define YYMAXDEPTH 10000",
120     "#endif",
121     "#endif",
122     "#define YYINITSTACKSIZE 200",
123     "int yydebug;",
124     "int yynerrs;",
125     "int yyerrflag;",
126     "int yychar;",
127     "short *yyssp;",
128     "YYSTYPE *yyvsp;",
129     "YYSTYPE yyval;",
130     "YYSTYPE yylval;",
131     "short *yyss;",
132     "short *yysslim;",
133     "YYSTYPE *yyvs;",
134     "int yystacksize;",
135     0
136 };
137
138
139 const char *body[] =
140 {
141     "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
142     "static int yygrowstack()",
143     "{",
144     "    int newsize, i;",
145     "    short *newss;",
146     "    YYSTYPE *newvs;",
147     "",
148     "    if ((newsize = yystacksize) == 0)",
149     "        newsize = YYINITSTACKSIZE;",
150     "    else if (newsize >= YYMAXDEPTH)",
151     "        return -1;",
152     "    else if ((newsize *= 2) > YYMAXDEPTH)",
153     "        newsize = YYMAXDEPTH;",
154     "    i = yyssp - yyss;",
155     "    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
156     "      (short *)malloc(newsize * sizeof *newss);",
157     "    if (newss == NULL)",
158     "        return -1;",
159     "    yyss = newss;",
160     "    yyssp = newss + i;",
161     "    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
162     "      (YYSTYPE *)malloc(newsize * sizeof *newvs);",
163     "    if (newvs == NULL)",
164     "        return -1;",
165     "    yyvs = newvs;",
166     "    yyvsp = newvs + i;",
167     "    yystacksize = newsize;",
168     "    yysslim = yyss + newsize - 1;",
169     "    return 0;",
170     "}",
171     "",
172     "#define YYABORT goto yyabort",
173     "#define YYREJECT goto yyabort",
174     "#define YYACCEPT goto yyaccept",
175     "#define YYERROR goto yyerrlab",
176     "",
177     "#ifndef YYPARSE_PARAM",
178     "#if defined(__cplusplus) || __STDC__",
179     "#define YYPARSE_PARAM_ARG void",
180     "#define YYPARSE_PARAM_DECL",
181     "#else      /* ! ANSI-C/C++ */",
182     "#define YYPARSE_PARAM_ARG",
183     "#define YYPARSE_PARAM_DECL",
184     "#endif     /* ANSI-C/C++ */",
185     "#else      /* YYPARSE_PARAM */",
186     "#ifndef YYPARSE_PARAM_TYPE",
187     "#define YYPARSE_PARAM_TYPE void *",
188     "#endif",
189     "#if defined(__cplusplus) || __STDC__",
190     "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
191     "#define YYPARSE_PARAM_DECL",
192     "#else      /* ! ANSI-C/C++ */",
193     "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
194     "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
195     "#endif     /* ANSI-C/C++ */",
196     "#endif     /* ! YYPARSE_PARAM */",
197     "",
198     "int",
199     "yyparse (YYPARSE_PARAM_ARG)",
200     "    YYPARSE_PARAM_DECL",
201     "{",
202     "    int yym, yyn, yystate;",
203     "#if YYDEBUG",
204     "    const char *yys;",
205     "",
206     "    if ((yys = getenv(\"YYDEBUG\")))",
207     "    {",
208     "        yyn = *yys;",
209     "        if (yyn >= '0' && yyn <= '9')",
210     "            yydebug = yyn - '0';",
211     "    }",
212     "#endif",
213     "",
214     "    yynerrs = 0;",
215     "    yyerrflag = 0;",
216     "    yychar = (-1);",
217     "",
218     "    if (yyss == NULL && yygrowstack()) goto yyoverflow;",
219     "    yyssp = yyss;",
220     "    yyvsp = yyvs;",
221     "    *yyssp = yystate = 0;",
222     "",
223     "yyloop:",
224     "    if ((yyn = yydefred[yystate])) goto yyreduce;",
225     "    if (yychar < 0)",
226     "    {",
227     "        if ((yychar = yylex()) < 0) yychar = 0;",
228     "#if YYDEBUG",
229     "        if (yydebug)",
230     "        {",
231     "            yys = 0;",
232     "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
233     "            if (!yys) yys = \"illegal-symbol\";",
234     "            printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
235     "                    YYPREFIX, yystate, yychar, yys);",
236     "        }",
237     "#endif",
238     "    }",
239     "    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
240     "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
241     "    {",
242     "#if YYDEBUG",
243     "        if (yydebug)",
244     "            printf(\"%sdebug: state %d, shifting to state %d\\n\",",
245     "                    YYPREFIX, yystate, yytable[yyn]);",
246     "#endif",
247     "        if (yyssp >= yysslim && yygrowstack())",
248     "        {",
249     "            goto yyoverflow;",
250     "        }",
251     "        *++yyssp = yystate = yytable[yyn];",
252     "        *++yyvsp = yylval;",
253     "        yychar = (-1);",
254     "        if (yyerrflag > 0)  --yyerrflag;",
255     "        goto yyloop;",
256     "    }",
257     "    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
258     "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
259     "    {",
260     "        yyn = yytable[yyn];",
261     "        goto yyreduce;",
262     "    }",
263     "    if (yyerrflag) goto yyinrecovery;",
264     "#if defined(lint) || defined(__GNUC__)",
265     "    goto yynewerror;",
266     "#endif",
267     "yynewerror:",
268     "    yyerror(\"syntax error\");",
269     "#if defined(lint) || defined(__GNUC__)",
270     "    goto yyerrlab;",
271     "#endif",
272     "yyerrlab:",
273     "    ++yynerrs;",
274     "yyinrecovery:",
275     "    if (yyerrflag < 3)",
276     "    {",
277     "        yyerrflag = 3;",
278     "        for (;;)",
279     "        {",
280     "            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
281     "                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
282     "            {",
283     "#if YYDEBUG",
284     "                if (yydebug)",
285     "                    printf(\"%sdebug: state %d, error recovery shifting\\",
286     " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
287     "#endif",
288     "                if (yyssp >= yysslim && yygrowstack())",
289     "                {",
290     "                    goto yyoverflow;",
291     "                }",
292     "                *++yyssp = yystate = yytable[yyn];",
293     "                *++yyvsp = yylval;",
294     "                goto yyloop;",
295     "            }",
296     "            else",
297     "            {",
298     "#if YYDEBUG",
299     "                if (yydebug)",
300     "                    printf(\"%sdebug: error recovery discarding state %d\
301 \\n\",",
302     "                            YYPREFIX, *yyssp);",
303     "#endif",
304     "                if (yyssp <= yyss) goto yyabort;",
305     "                --yyssp;",
306     "                --yyvsp;",
307     "            }",
308     "        }",
309     "    }",
310     "    else",
311     "    {",
312     "        if (yychar == 0) goto yyabort;",
313     "#if YYDEBUG",
314     "        if (yydebug)",
315     "        {",
316     "            yys = 0;",
317     "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
318     "            if (!yys) yys = \"illegal-symbol\";",
319     "            printf(\"%sdebug: state %d, error recovery discards token %d\
320  (%s)\\n\",",
321     "                    YYPREFIX, yystate, yychar, yys);",
322     "        }",
323     "#endif",
324     "        yychar = (-1);",
325     "        goto yyloop;",
326     "    }",
327     "yyreduce:",
328     "#if YYDEBUG",
329     "    if (yydebug)",
330     "        printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
331     "                YYPREFIX, yystate, yyn, yyrule[yyn]);",
332     "#endif",
333     "    yym = yylen[yyn];",
334     "    yyval = yyvsp[1-yym];",
335     "    switch (yyn)",
336     "    {",
337     0
338 };
339
340
341 const char *trailer[] =
342 {
343     "    }",
344     "    yyssp -= yym;",
345     "    yystate = *yyssp;",
346     "    yyvsp -= yym;",
347     "    yym = yylhs[yyn];",
348     "    if (yystate == 0 && yym == 0)",
349     "    {",
350     "#if YYDEBUG",
351     "        if (yydebug)",
352     "            printf(\"%sdebug: after reduction, shifting from state 0 to\\",
353     " state %d\\n\", YYPREFIX, YYFINAL);",
354     "#endif",
355     "        yystate = YYFINAL;",
356     "        *++yyssp = YYFINAL;",
357     "        *++yyvsp = yyval;",
358     "        if (yychar < 0)",
359     "        {",
360     "            if ((yychar = yylex()) < 0) yychar = 0;",
361     "#if YYDEBUG",
362     "            if (yydebug)",
363     "            {",
364     "                yys = 0;",
365     "                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
366     "                if (!yys) yys = \"illegal-symbol\";",
367     "                printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
368     "                        YYPREFIX, YYFINAL, yychar, yys);",
369     "            }",
370     "#endif",
371     "        }",
372     "        if (yychar == 0) goto yyaccept;",
373     "        goto yyloop;",
374     "    }",
375     "    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
376     "            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
377     "        yystate = yytable[yyn];",
378     "    else",
379     "        yystate = yydgoto[yym];",
380     "#if YYDEBUG",
381     "    if (yydebug)",
382     "        printf(\"%sdebug: after reduction, shifting from state %d \\",
383     "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
384     "#endif",
385     "    if (yyssp >= yysslim && yygrowstack())",
386     "    {",
387     "        goto yyoverflow;",
388     "    }",
389     "    *++yyssp = yystate;",
390     "    *++yyvsp = yyval;",
391     "    goto yyloop;",
392     "yyoverflow:",
393     "    yyerror(\"yacc stack overflow\");",
394     "yyabort:",
395     "    return (1);",
396     "yyaccept:",
397     "    return (0);",
398     "}",
399     0
400 };
401
402
403 void
404 write_section(section)
405 const char *section[];
406 {
407     int c;
408     int i;
409     const char *s;
410     FILE *f;
411
412     f = code_file;
413     for (i = 0; (s = section[i]); ++i)
414     {
415         ++outline;
416         while ((c = *s))
417         {
418             putc(c, f);
419             ++s;
420         }
421         putc('\n', f);
422     }
423 }