updated with Tizen:Base source codes
[external/byacc.git] / skeleton.c
1 /* $Id: skeleton.c,v 1.19 2008/12/24 14:52:28 tom Exp $ */
2
3 #include "defs.h"
4
5 /*  The definition of yysccsid in the banner should be replaced with    */
6 /*  a #pragma ident directive if the target C compiler supports         */
7 /*  #pragma ident directives.                                           */
8 /*                                                                      */
9 /*  If the skeleton is changed, the banner should be changed so that    */
10 /*  the altered version can be easily distinguished from the original.  */
11 /*                                                                      */
12 /*  The #defines included with the banner are there because they are    */
13 /*  useful in subsequent code.  The macros #defined in the header or    */
14 /*  the body either are not useful outside of semantic actions or       */
15 /*  are conditional.                                                    */
16
17 const char *banner[] =
18 {
19     "#ifndef lint",
20     "static const char yysccsid[] = \"@(#)yaccpar       1.9 (Berkeley) 02/21/93\";",
21     "#endif",
22     "",
23     "#include <stdlib.h>",
24     "#include <string.h>",
25     "",
26     "#define YYBYACC 1",
27     CONCAT1("#define YYMAJOR ", YYMAJOR),
28     CONCAT1("#define YYMINOR ", YYMINOR),
29 #ifdef YYPATCH
30     CONCAT1("#define YYPATCH ", YYPATCH),
31 #endif
32     "",
33     "#define YYEMPTY        (-1)",
34     "#define yyclearin      (yychar = YYEMPTY)",
35     "#define yyerrok        (yyerrflag = 0)",
36     "#define YYRECOVERING() (yyerrflag != 0)",
37     "",
38     "/* compatibility with bison */",
39     "#ifdef YYPARSE_PARAM",
40     "/* compatibility with FreeBSD */",
41     "#ifdef YYPARSE_PARAM_TYPE",
42     "#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)",
43     "#else",
44     "#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)",
45     "#endif",
46     "#else",
47     "#define YYPARSE_DECL() yyparse(void)",
48     "#endif /* YYPARSE_PARAM */",
49     "",
50     "extern int YYPARSE_DECL();",
51     "",
52     "static int yygrowstack(void);",
53     0
54 };
55
56 const char *tables[] =
57 {
58     "extern short yylhs[];",
59     "extern short yylen[];",
60     "extern short yydefred[];",
61     "extern short yydgoto[];",
62     "extern short yysindex[];",
63     "extern short yyrindex[];",
64     "extern short yygindex[];",
65     "extern short yytable[];",
66     "extern short yycheck[];",
67     "",
68     "#if YYDEBUG",
69     "extern char *yyname[];",
70     "extern char *yyrule[];",
71     "#endif",
72     0
73 };
74
75 const char *header[] =
76 {
77     "#if YYDEBUG",
78     "#include <stdio.h>",
79     "#endif",
80     "",
81     "/* define the initial stack-sizes */",
82     "#ifdef YYSTACKSIZE",
83     "#undef YYMAXDEPTH",
84     "#define YYMAXDEPTH  YYSTACKSIZE",
85     "#else",
86     "#ifdef YYMAXDEPTH",
87     "#define YYSTACKSIZE YYMAXDEPTH",
88     "#else",
89     "#define YYSTACKSIZE 500",
90     "#define YYMAXDEPTH  500",
91     "#endif",
92     "#endif",
93     "",
94     "#define YYINITSTACKSIZE 500",
95     "",
96     "int      yydebug;",
97     "int      yynerrs;",
98     "int      yyerrflag;",
99     "int      yychar;",
100     "short   *yyssp;",
101     "YYSTYPE *yyvsp;",
102     "YYSTYPE  yyval;",
103     "YYSTYPE  yylval;",
104     "",
105     "/* variables for the parser stack */",
106     "static short   *yyss;",
107     "static short   *yysslim;",
108     "static YYSTYPE *yyvs;",
109     "static unsigned yystacksize;",
110     0
111 };
112
113 const char *body[] =
114 {
115     "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
116     "static int yygrowstack(void)",
117     "{",
118     "    int i;",
119     "    unsigned newsize;",
120     "    short *newss;",
121     "    YYSTYPE *newvs;",
122     "",
123     "    if ((newsize = yystacksize) == 0)",
124     "        newsize = YYINITSTACKSIZE;",
125     "    else if (newsize >= YYMAXDEPTH)",
126     "        return -1;",
127     "    else if ((newsize *= 2) > YYMAXDEPTH)",
128     "        newsize = YYMAXDEPTH;",
129     "",
130     "    i = yyssp - yyss;",
131     "    newss = (yyss != 0)",
132     "          ? (short *)realloc(yyss, newsize * sizeof(*newss))",
133     "          : (short *)malloc(newsize * sizeof(*newss));",
134     "    if (newss == 0)",
135     "        return -1;",
136     "",
137     "    yyss  = newss;",
138     "    yyssp = newss + i;",
139     "    newvs = (yyvs != 0)",
140     "          ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))",
141     "          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));",
142     "    if (newvs == 0)",
143     "        return -1;",
144     "",
145     "    yyvs = newvs;",
146     "    yyvsp = newvs + i;",
147     "    yystacksize = newsize;",
148     "    yysslim = yyss + newsize - 1;",
149     "    return 0;",
150     "}",
151     "",
152     "#define YYABORT  goto yyabort",
153     "#define YYREJECT goto yyabort",
154     "#define YYACCEPT goto yyaccept",
155     "#define YYERROR  goto yyerrlab",
156     "",
157     "int",
158     "YYPARSE_DECL()",
159     "{",
160     "    int yym, yyn, yystate;",
161     "#if YYDEBUG",
162     "    const char *yys;",
163     "",
164     "    if ((yys = getenv(\"YYDEBUG\")) != 0)",
165     "    {",
166     "        yyn = *yys;",
167     "        if (yyn >= '0' && yyn <= '9')",
168     "            yydebug = yyn - '0';",
169     "    }",
170     "#endif",
171     "",
172     "    yynerrs = 0;",
173     "    yyerrflag = 0;",
174     "    yychar = YYEMPTY;",
175     "    yystate = 0;",
176     "",
177     "    if (yyss == NULL && yygrowstack()) goto yyoverflow;",
178     "    yyssp = yyss;",
179     "    yyvsp = yyvs;",
180     "    yystate = 0;",
181     "    *yyssp = 0;",
182     "",
183     "yyloop:",
184     "    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
185     "    if (yychar < 0)",
186     "    {",
187     "        if ((yychar = yylex()) < 0) yychar = 0;",
188     "#if YYDEBUG",
189     "        if (yydebug)",
190     "        {",
191     "            yys = 0;",
192     "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
193     "            if (!yys) yys = \"illegal-symbol\";",
194     "            printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
195     "                    YYPREFIX, yystate, yychar, yys);",
196     "        }",
197     "#endif",
198     "    }",
199     "    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
200     "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
201     "    {",
202     "#if YYDEBUG",
203     "        if (yydebug)",
204     "            printf(\"%sdebug: state %d, shifting to state %d\\n\",",
205     "                    YYPREFIX, yystate, yytable[yyn]);",
206     "#endif",
207     "        if (yyssp >= yysslim && yygrowstack())",
208     "        {",
209     "            goto yyoverflow;",
210     "        }",
211     "        yystate = yytable[yyn];",
212     "        *++yyssp = yytable[yyn];",
213     "        *++yyvsp = yylval;",
214     "        yychar = YYEMPTY;",
215     "        if (yyerrflag > 0)  --yyerrflag;",
216     "        goto yyloop;",
217     "    }",
218     "    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
219     "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
220     "    {",
221     "        yyn = yytable[yyn];",
222     "        goto yyreduce;",
223     "    }",
224     "    if (yyerrflag) goto yyinrecovery;",
225     "",
226     "    yyerror(\"syntax error\");",
227     "",
228     "    goto yyerrlab;",
229     "",
230     "yyerrlab:",
231     "    ++yynerrs;",
232     "",
233     "yyinrecovery:",
234     "    if (yyerrflag < 3)",
235     "    {",
236     "        yyerrflag = 3;",
237     "        for (;;)",
238     "        {",
239     "            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
240     "                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
241     "            {",
242     "#if YYDEBUG",
243     "                if (yydebug)",
244     "                    printf(\"%sdebug: state %d, error recovery shifting\\",
245     " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
246     "#endif",
247     "                if (yyssp >= yysslim && yygrowstack())",
248     "                {",
249     "                    goto yyoverflow;",
250     "                }",
251     "                yystate = yytable[yyn];",
252     "                *++yyssp = yytable[yyn];",
253     "                *++yyvsp = yylval;",
254     "                goto yyloop;",
255     "            }",
256     "            else",
257     "            {",
258     "#if YYDEBUG",
259     "                if (yydebug)",
260     "                    printf(\"%sdebug: error recovery discarding state %d\
261 \\n\",",
262     "                            YYPREFIX, *yyssp);",
263     "#endif",
264     "                if (yyssp <= yyss) goto yyabort;",
265     "                --yyssp;",
266     "                --yyvsp;",
267     "            }",
268     "        }",
269     "    }",
270     "    else",
271     "    {",
272     "        if (yychar == 0) goto yyabort;",
273     "#if YYDEBUG",
274     "        if (yydebug)",
275     "        {",
276     "            yys = 0;",
277     "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
278     "            if (!yys) yys = \"illegal-symbol\";",
279     "            printf(\"%sdebug: state %d, error recovery discards token %d\
280  (%s)\\n\",",
281     "                    YYPREFIX, yystate, yychar, yys);",
282     "        }",
283     "#endif",
284     "        yychar = YYEMPTY;",
285     "        goto yyloop;",
286     "    }",
287     "",
288     "yyreduce:",
289     "#if YYDEBUG",
290     "    if (yydebug)",
291     "        printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
292     "                YYPREFIX, yystate, yyn, yyrule[yyn]);",
293     "#endif",
294     "    yym = yylen[yyn];",
295     "    if (yym)",
296     "        yyval = yyvsp[1-yym];",
297     "    else",
298     "        memset(&yyval, 0, sizeof yyval);",
299     "    switch (yyn)",
300     "    {",
301     0
302 };
303
304 const char *trailer[] =
305 {
306     "    }",
307     "    yyssp -= yym;",
308     "    yystate = *yyssp;",
309     "    yyvsp -= yym;",
310     "    yym = yylhs[yyn];",
311     "    if (yystate == 0 && yym == 0)",
312     "    {",
313     "#if YYDEBUG",
314     "        if (yydebug)",
315     "            printf(\"%sdebug: after reduction, shifting from state 0 to\\",
316     " state %d\\n\", YYPREFIX, YYFINAL);",
317     "#endif",
318     "        yystate = YYFINAL;",
319     "        *++yyssp = YYFINAL;",
320     "        *++yyvsp = yyval;",
321     "        if (yychar < 0)",
322     "        {",
323     "            if ((yychar = yylex()) < 0) yychar = 0;",
324     "#if YYDEBUG",
325     "            if (yydebug)",
326     "            {",
327     "                yys = 0;",
328     "                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
329     "                if (!yys) yys = \"illegal-symbol\";",
330     "                printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
331     "                        YYPREFIX, YYFINAL, yychar, yys);",
332     "            }",
333     "#endif",
334     "        }",
335     "        if (yychar == 0) goto yyaccept;",
336     "        goto yyloop;",
337     "    }",
338     "    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
339     "            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
340     "        yystate = yytable[yyn];",
341     "    else",
342     "        yystate = yydgoto[yym];",
343     "#if YYDEBUG",
344     "    if (yydebug)",
345     "        printf(\"%sdebug: after reduction, shifting from state %d \\",
346     "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
347     "#endif",
348     "    if (yyssp >= yysslim && yygrowstack())",
349     "    {",
350     "        goto yyoverflow;",
351     "    }",
352     "    *++yyssp = (short) yystate;",
353     "    *++yyvsp = yyval;",
354     "    goto yyloop;",
355     "",
356     "yyoverflow:",
357     "    yyerror(\"yacc stack overflow\");",
358     "",
359     "yyabort:",
360     "    return (1);",
361     "",
362     "yyaccept:",
363     "    return (0);",
364     "}",
365     0
366 };
367
368 void
369 write_section(const char *section[])
370 {
371     int c;
372     int i;
373     const char *s;
374     FILE *f;
375
376     f = code_file;
377     for (i = 0; (s = section[i]) != 0; ++i)
378     {
379         ++outline;
380         while ((c = *s) != 0)
381         {
382             putc(c, f);
383             ++s;
384         }
385         putc('\n', f);
386     }
387 }