xref: /freebsd/contrib/byacc/test/yacc/error.tab.c (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
1 /* original parser id follows */
2 /* yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93" */
3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
4 
5 #define YYBYACC 1
6 #define YYMAJOR 2
7 #define YYMINOR 0
8 #define YYCHECK "yyyymmdd"
9 
10 #define YYEMPTY        (-1)
11 #define yyclearin      (yychar = YYEMPTY)
12 #define yyerrok        (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
14 #define YYENOMEM       (-2)
15 #define YYEOF          0
16 
17 #ifndef yyparse
18 #define yyparse    error_parse
19 #endif /* yyparse */
20 
21 #ifndef yylex
22 #define yylex      error_lex
23 #endif /* yylex */
24 
25 #ifndef yyerror
26 #define yyerror    error_error
27 #endif /* yyerror */
28 
29 #ifndef yychar
30 #define yychar     error_char
31 #endif /* yychar */
32 
33 #ifndef yyval
34 #define yyval      error_val
35 #endif /* yyval */
36 
37 #ifndef yylval
38 #define yylval     error_lval
39 #endif /* yylval */
40 
41 #ifndef yydebug
42 #define yydebug    error_debug
43 #endif /* yydebug */
44 
45 #ifndef yynerrs
46 #define yynerrs    error_nerrs
47 #endif /* yynerrs */
48 
49 #ifndef yyerrflag
50 #define yyerrflag  error_errflag
51 #endif /* yyerrflag */
52 
53 #ifndef yylhs
54 #define yylhs      error_lhs
55 #endif /* yylhs */
56 
57 #ifndef yylen
58 #define yylen      error_len
59 #endif /* yylen */
60 
61 #ifndef yydefred
62 #define yydefred   error_defred
63 #endif /* yydefred */
64 
65 #ifndef yydgoto
66 #define yydgoto    error_dgoto
67 #endif /* yydgoto */
68 
69 #ifndef yysindex
70 #define yysindex   error_sindex
71 #endif /* yysindex */
72 
73 #ifndef yyrindex
74 #define yyrindex   error_rindex
75 #endif /* yyrindex */
76 
77 #ifndef yygindex
78 #define yygindex   error_gindex
79 #endif /* yygindex */
80 
81 #ifndef yytable
82 #define yytable    error_table
83 #endif /* yytable */
84 
85 #ifndef yycheck
86 #define yycheck    error_check
87 #endif /* yycheck */
88 
89 #ifndef yyname
90 #define yyname     error_name
91 #endif /* yyname */
92 
93 #ifndef yyrule
94 #define yyrule     error_rule
95 #endif /* yyrule */
96 #define YYPREFIX "error_"
97 
98 #define YYPURE 0
99 
100 #line 2 "error.y"
101 int yylex(void);
102 static void yyerror(const char *);
103 #line 104 "error.tab.c"
104 
105 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
106 /* Default: YYSTYPE is the semantic value type. */
107 typedef int YYSTYPE;
108 # define YYSTYPE_IS_DECLARED 1
109 #endif
110 
111 /* compatibility with bison */
112 #ifdef YYPARSE_PARAM
113 /* compatibility with FreeBSD */
114 # ifdef YYPARSE_PARAM_TYPE
115 #  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
116 # else
117 #  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
118 # endif
119 #else
120 # define YYPARSE_DECL() yyparse(void)
121 #endif
122 
123 /* Parameters sent to lex. */
124 #ifdef YYLEX_PARAM
125 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
126 # define YYLEX yylex(YYLEX_PARAM)
127 #else
128 # define YYLEX_DECL() yylex(void)
129 # define YYLEX yylex()
130 #endif
131 
132 /* Parameters sent to yyerror. */
133 #ifndef YYERROR_DECL
134 #define YYERROR_DECL() yyerror(const char *s)
135 #endif
136 #ifndef YYERROR_CALL
137 #define YYERROR_CALL(msg) yyerror(msg)
138 #endif
139 
140 extern int YYPARSE_DECL();
141 
142 #define YYERRCODE 256
143 typedef int YYINT;
144 static const YYINT error_lhs[] = {                       -1,
145     0,
146 };
147 static const YYINT error_len[] = {                        2,
148     1,
149 };
150 static const YYINT error_defred[] = {                     0,
151     1,    0,
152 };
153 static const YYINT error_dgoto[] = {                      2,
154 };
155 static const YYINT error_sindex[] = {                  -256,
156     0,    0,
157 };
158 static const YYINT error_rindex[] = {                     0,
159     0,    0,
160 };
161 static const YYINT error_gindex[] = {                     0,
162 };
163 #define YYTABLESIZE 0
164 static const YYINT error_table[] = {                      1,
165 };
166 static const YYINT error_check[] = {                    256,
167 };
168 #define YYFINAL 2
169 #ifndef YYDEBUG
170 #define YYDEBUG 0
171 #endif
172 #define YYMAXTOKEN 256
173 #define YYUNDFTOKEN 259
174 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
175 #if YYDEBUG
176 static const char *const error_name[] = {
177 
178 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
179 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
180 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
181 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
182 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
183 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
184 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"illegal-symbol",
185 };
186 static const char *const error_rule[] = {
187 "$accept : S",
188 "S : error",
189 
190 };
191 #endif
192 
193 #if YYDEBUG
194 int      yydebug;
195 #endif
196 
197 int      yyerrflag;
198 int      yychar;
199 YYSTYPE  yyval;
200 YYSTYPE  yylval;
201 int      yynerrs;
202 
203 /* define the initial stack-sizes */
204 #ifdef YYSTACKSIZE
205 #undef YYMAXDEPTH
206 #define YYMAXDEPTH  YYSTACKSIZE
207 #else
208 #ifdef YYMAXDEPTH
209 #define YYSTACKSIZE YYMAXDEPTH
210 #else
211 #define YYSTACKSIZE 10000
212 #define YYMAXDEPTH  10000
213 #endif
214 #endif
215 
216 #define YYINITSTACKSIZE 200
217 
218 typedef struct {
219     unsigned stacksize;
220     YYINT    *s_base;
221     YYINT    *s_mark;
222     YYINT    *s_last;
223     YYSTYPE  *l_base;
224     YYSTYPE  *l_mark;
225 } YYSTACKDATA;
226 /* variables for the parser stack */
227 static YYSTACKDATA yystack;
228 #line 8 "error.y"
229 
230 #include <stdio.h>
231 
232 int
233 main(void)
234 {
235     printf("yyparse() = %d\n", yyparse());
236     return 0;
237 }
238 
239 int
240 yylex(void)
241 {
242     return -1;
243 }
244 
245 static void
246 yyerror(const char* s)
247 {
248     printf("%s\n", s);
249 }
250 #line 251 "error.tab.c"
251 
252 #if YYDEBUG
253 #include <stdio.h>	/* needed for printf */
254 #endif
255 
256 #include <stdlib.h>	/* needed for malloc, etc */
257 #include <string.h>	/* needed for memset */
258 
259 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
260 static int yygrowstack(YYSTACKDATA *data)
261 {
262     int i;
263     unsigned newsize;
264     YYINT *newss;
265     YYSTYPE *newvs;
266 
267     if ((newsize = data->stacksize) == 0)
268         newsize = YYINITSTACKSIZE;
269     else if (newsize >= YYMAXDEPTH)
270         return YYENOMEM;
271     else if ((newsize *= 2) > YYMAXDEPTH)
272         newsize = YYMAXDEPTH;
273 
274     i = (int) (data->s_mark - data->s_base);
275     newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
276     if (newss == NULL)
277         return YYENOMEM;
278 
279     data->s_base = newss;
280     data->s_mark = newss + i;
281 
282     newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
283     if (newvs == NULL)
284         return YYENOMEM;
285 
286     data->l_base = newvs;
287     data->l_mark = newvs + i;
288 
289     data->stacksize = newsize;
290     data->s_last = data->s_base + newsize - 1;
291     return 0;
292 }
293 
294 #if YYPURE || defined(YY_NO_LEAKS)
295 static void yyfreestack(YYSTACKDATA *data)
296 {
297     free(data->s_base);
298     free(data->l_base);
299     memset(data, 0, sizeof(*data));
300 }
301 #else
302 #define yyfreestack(data) /* nothing */
303 #endif
304 
305 #define YYABORT  goto yyabort
306 #define YYREJECT goto yyabort
307 #define YYACCEPT goto yyaccept
308 #define YYERROR  goto yyerrlab
309 
310 int
311 YYPARSE_DECL()
312 {
313     int yym, yyn, yystate;
314 #if YYDEBUG
315     const char *yys;
316 
317     if ((yys = getenv("YYDEBUG")) != NULL)
318     {
319         yyn = *yys;
320         if (yyn >= '0' && yyn <= '9')
321             yydebug = yyn - '0';
322     }
323 #endif
324 
325     /* yym is set below */
326     /* yyn is set below */
327     yynerrs = 0;
328     yyerrflag = 0;
329     yychar = YYEMPTY;
330     yystate = 0;
331 
332 #if YYPURE
333     memset(&yystack, 0, sizeof(yystack));
334 #endif
335 
336     if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
337     yystack.s_mark = yystack.s_base;
338     yystack.l_mark = yystack.l_base;
339     yystate = 0;
340     *yystack.s_mark = 0;
341 
342 yyloop:
343     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
344     if (yychar < 0)
345     {
346         yychar = YYLEX;
347         if (yychar < 0) yychar = YYEOF;
348 #if YYDEBUG
349         if (yydebug)
350         {
351             if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
352             printf("%sdebug: state %d, reading %d (%s)\n",
353                     YYPREFIX, yystate, yychar, yys);
354         }
355 #endif
356     }
357     if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
358             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
359     {
360 #if YYDEBUG
361         if (yydebug)
362             printf("%sdebug: state %d, shifting to state %d\n",
363                     YYPREFIX, yystate, yytable[yyn]);
364 #endif
365         if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
366         yystate = yytable[yyn];
367         *++yystack.s_mark = yytable[yyn];
368         *++yystack.l_mark = yylval;
369         yychar = YYEMPTY;
370         if (yyerrflag > 0)  --yyerrflag;
371         goto yyloop;
372     }
373     if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
374             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
375     {
376         yyn = yytable[yyn];
377         goto yyreduce;
378     }
379     if (yyerrflag != 0) goto yyinrecovery;
380 
381     YYERROR_CALL("syntax error");
382 
383     goto yyerrlab; /* redundant goto avoids 'unused label' warning */
384 yyerrlab:
385     ++yynerrs;
386 
387 yyinrecovery:
388     if (yyerrflag < 3)
389     {
390         yyerrflag = 3;
391         for (;;)
392         {
393             if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
394                     yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
395             {
396 #if YYDEBUG
397                 if (yydebug)
398                     printf("%sdebug: state %d, error recovery shifting\
399  to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
400 #endif
401                 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
402                 yystate = yytable[yyn];
403                 *++yystack.s_mark = yytable[yyn];
404                 *++yystack.l_mark = yylval;
405                 goto yyloop;
406             }
407             else
408             {
409 #if YYDEBUG
410                 if (yydebug)
411                     printf("%sdebug: error recovery discarding state %d\n",
412                             YYPREFIX, *yystack.s_mark);
413 #endif
414                 if (yystack.s_mark <= yystack.s_base) goto yyabort;
415                 --yystack.s_mark;
416                 --yystack.l_mark;
417             }
418         }
419     }
420     else
421     {
422         if (yychar == YYEOF) goto yyabort;
423 #if YYDEBUG
424         if (yydebug)
425         {
426             if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
427             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
428                     YYPREFIX, yystate, yychar, yys);
429         }
430 #endif
431         yychar = YYEMPTY;
432         goto yyloop;
433     }
434 
435 yyreduce:
436 #if YYDEBUG
437     if (yydebug)
438         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
439                 YYPREFIX, yystate, yyn, yyrule[yyn]);
440 #endif
441     yym = yylen[yyn];
442     if (yym > 0)
443         yyval = yystack.l_mark[1-yym];
444     else
445         memset(&yyval, 0, sizeof yyval);
446 
447     switch (yyn)
448     {
449     }
450     yystack.s_mark -= yym;
451     yystate = *yystack.s_mark;
452     yystack.l_mark -= yym;
453     yym = yylhs[yyn];
454     if (yystate == 0 && yym == 0)
455     {
456 #if YYDEBUG
457         if (yydebug)
458             printf("%sdebug: after reduction, shifting from state 0 to\
459  state %d\n", YYPREFIX, YYFINAL);
460 #endif
461         yystate = YYFINAL;
462         *++yystack.s_mark = YYFINAL;
463         *++yystack.l_mark = yyval;
464         if (yychar < 0)
465         {
466             yychar = YYLEX;
467             if (yychar < 0) yychar = YYEOF;
468 #if YYDEBUG
469             if (yydebug)
470             {
471                 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
472                 printf("%sdebug: state %d, reading %d (%s)\n",
473                         YYPREFIX, YYFINAL, yychar, yys);
474             }
475 #endif
476         }
477         if (yychar == YYEOF) goto yyaccept;
478         goto yyloop;
479     }
480     if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
481             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
482         yystate = yytable[yyn];
483     else
484         yystate = yydgoto[yym];
485 #if YYDEBUG
486     if (yydebug)
487         printf("%sdebug: after reduction, shifting from state %d \
488 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
489 #endif
490     if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
491     *++yystack.s_mark = (YYINT) yystate;
492     *++yystack.l_mark = yyval;
493     goto yyloop;
494 
495 yyoverflow:
496     YYERROR_CALL("yacc stack overflow");
497 
498 yyabort:
499     yyfreestack(&yystack);
500     return (1);
501 
502 yyaccept:
503     yyfreestack(&yystack);
504     return (0);
505 }
506