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