1 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
4 /* Skeleton output parser for bison,
5 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
26 /* This is the parser code that is written into each bison parser
27 when the %semantic_parser declaration is not specified in the grammar.
28 It was written by Richard Stallman by simplifying the hairy parser
29 used when %semantic_parser is specified. */
33 #define alloca __builtin_alloca
34 #else /* not GNU C. */
35 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
38 /* This used to test MSDOS, but that is a bad idea
39 since that is in the user namespace. */
40 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
42 #else /* not MSDOS, or __TURBOC__ */
46 #else /* not MSDOS, or __TURBOC__, or _AIX */
47 #ifdef __hpux /* This is right for HPUX 10. */
50 #if 0 /* This was right for HPUX 9.
51 Unfortunately there is no clean way to distinguish. */
55 void *alloca (unsigned int);
57 #else /* not __cplusplus */
59 #endif /* not __cplusplus */
63 #endif /* not MSDOS, or __TURBOC__ */
64 #endif /* not sparc. */
65 #endif /* not GNU C. */
66 #endif /* alloca not defined. */
68 /* Note: there must be only one dollar sign in this file.
69 It is replaced by the list of actions, each action
70 as one case of the switch. */
72 #define yyerrok (yyerrstatus = 0)
73 #define yyclearin (yychar = YYEMPTY)
76 #define YYACCEPT return(0)
77 #define YYABORT return(1)
78 #define YYERROR goto yyerrlab1
79 /* Like YYERROR except do call yyerror.
80 This remains here temporarily to ease the
81 transition to the new meaning of YYERROR, for GCC.
82 Once GCC version 2 has supplanted version 1, this can go. */
83 #define YYFAIL goto yyerrlab
84 #define YYRECOVERING() (!!yyerrstatus)
85 #define YYBACKUP(token, value) \
87 if (yychar == YYEMPTY && yylen == 1) \
88 { yychar = (token), yylval = (value); \
89 yychar1 = YYTRANSLATE (yychar); \
94 { yyerror ("syntax error: cannot back up"); YYERROR; } \
101 #define YYLEX yylex()
107 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
109 #define YYLEX yylex(&yylval, &yylloc)
111 #else /* not YYLSP_NEEDED */
113 #define YYLEX yylex(&yylval, YYLEX_PARAM)
115 #define YYLEX yylex(&yylval)
117 #endif /* not YYLSP_NEEDED */
120 /* If nonreentrant, generate the variables here */
124 int yychar; /* the lookahead symbol */
125 YYSTYPE yylval; /* the semantic value of the */
126 /* lookahead symbol */
129 YYLTYPE yylloc; /* location data for the lookahead */
133 int yynerrs; /* number of parse errors so far */
134 #endif /* not YYPURE */
137 int yydebug; /* nonzero means print parse trace */
138 /* Since this is uninitialized, it does not stop multiple parsers
142 /* YYINITDEPTH indicates the initial size of the parser's stacks */
145 #define YYINITDEPTH 200
148 /* YYMAXDEPTH is the maximum size the stacks can grow to
149 (effective only if the built-in stack extension method is used). */
156 #define YYMAXDEPTH 10000
159 /* Define __yy_memcpy. Note that the size argument
160 should be passed with type unsigned int, because that is what the non-GCC
161 definitions require. With GCC, __builtin_memcpy takes an arg
162 of type size_t, but it can handle unsigned int. */
164 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
165 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
166 #else /* not GNU C or C++ */
169 /* This is the most reliable way to avoid incompatibilities
170 in available built-in functions on various systems. */
172 __yy_memcpy (to, from, count)
177 register char *f = from;
178 register char *t = to;
179 register int i = count;
185 #else /* __cplusplus */
187 /* This is the most reliable way to avoid incompatibilities
188 in available built-in functions on various systems. */
190 __yy_memcpy (char *to, char *from, unsigned int count)
192 register char *t = to;
193 register char *f = from;
194 register int i = count;
203 #line 196 "bison.simple"
205 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
206 into yyparse. The argument should have type void *.
207 It should actually point to an object.
208 Grammar actions can access the variable by casting it
209 to the proper pointer type. */
213 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
214 #define YYPARSE_PARAM_DECL
215 #else /* not __cplusplus */
216 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
217 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
218 #endif /* not __cplusplus */
219 #else /* not YYPARSE_PARAM */
220 #define YYPARSE_PARAM_ARG
221 #define YYPARSE_PARAM_DECL
222 #endif /* not YYPARSE_PARAM */
224 /* Prevent warning if -Wstrict-prototypes. */
227 int yyparse (void *);
234 yyparse(YYPARSE_PARAM_ARG)
237 register int yystate;
239 register short *yyssp;
240 register YYSTYPE *yyvsp;
241 int yyerrstatus; /* number of tokens to shift before error messages enabled */
242 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
244 short yyssa[YYINITDEPTH]; /* the state stack */
245 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
247 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
248 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
251 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
252 YYLTYPE *yyls = yylsa;
255 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
257 #define YYPOPSTACK (yyvsp--, yyssp--)
260 int yystacksize = YYINITDEPTH;
271 YYSTYPE yyval; /* the variable used to return */
272 /* semantic values from the action */
279 fprintf(stderr, "Starting parse\n");
285 yychar = YYEMPTY; /* Cause a token to be read. */
287 /* Initialize stack pointers.
288 Waste one element of value and location stack
289 so that they stay on the same level as the state stack.
290 The wasted elements are never initialized. */
298 /* Push a new state, which is found in yystate . */
299 /* In all cases, when you get here, the value and location stacks
300 have just been pushed. so pushing a state here evens the stacks. */
305 if (yyssp >= yyss + yystacksize - 1)
307 /* Give user a chance to reallocate the stack */
308 /* Use copies of these so that the &'s don't force the real ones into memory. */
309 YYSTYPE *yyvs1 = yyvs;
312 YYLTYPE *yyls1 = yyls;
315 /* Get the current used size of the three stacks, in elements. */
316 int size = yyssp - yyss + 1;
319 /* Each stack pointer address is followed by the size of
320 the data in use in that stack, in bytes. */
322 /* This used to be a conditional around just the two extra args,
323 but that might be undefined if yyoverflow is a macro. */
324 yyoverflow("parser stack overflow",
325 &yyss1, size * sizeof (*yyssp),
326 &yyvs1, size * sizeof (*yyvsp),
327 &yyls1, size * sizeof (*yylsp),
330 yyoverflow("parser stack overflow",
331 &yyss1, size * sizeof (*yyssp),
332 &yyvs1, size * sizeof (*yyvsp),
336 yyss = yyss1; yyvs = yyvs1;
340 #else /* no yyoverflow */
341 /* Extend the stack our own way. */
342 if (yystacksize >= YYMAXDEPTH)
344 yyerror("parser stack overflow");
348 if (yystacksize > YYMAXDEPTH)
349 yystacksize = YYMAXDEPTH;
350 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
351 __yy_memcpy ((char *)yyss, (char *)yyss1,
352 size * (unsigned int) sizeof (*yyssp));
353 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
354 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
355 size * (unsigned int) sizeof (*yyvsp));
357 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
358 __yy_memcpy ((char *)yyls, (char *)yyls1,
359 size * (unsigned int) sizeof (*yylsp));
361 #endif /* no yyoverflow */
363 yyssp = yyss + size - 1;
364 yyvsp = yyvs + size - 1;
366 yylsp = yyls + size - 1;
371 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
374 if (yyssp >= yyss + yystacksize - 1)
380 fprintf(stderr, "Entering state %d\n", yystate);
386 /* Do appropriate processing given the current state. */
387 /* Read a lookahead token if we need one and don't already have one. */
390 /* First try to decide what to do without reference to lookahead token. */
392 yyn = yypact[yystate];
396 /* Not known => get a lookahead token if don't already have one. */
398 /* yychar is either YYEMPTY or YYEOF
399 or a valid token in external form. */
401 if (yychar == YYEMPTY)
405 fprintf(stderr, "Reading a token: ");
410 /* Convert token to internal form (in yychar1) for indexing tables with */
412 if (yychar <= 0) /* This means end of input. */
415 yychar = YYEOF; /* Don't call YYLEX any more */
419 fprintf(stderr, "Now at end of input.\n");
424 yychar1 = YYTRANSLATE(yychar);
429 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
430 /* Give the individual parser a way to print the precise meaning
431 of a token, for further debugging info. */
433 YYPRINT (stderr, yychar, yylval);
435 fprintf (stderr, ")\n");
441 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
446 /* yyn is what to do for this token type in this state.
447 Negative => reduce, -yyn is rule number.
448 Positive => shift, yyn is new state.
449 New state is final state => don't bother to shift,
451 0, or most negative number => error. */
466 /* Shift the lookahead token. */
470 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
473 /* Discard the token being shifted unless it is eof. */
482 /* count tokens shifted since error; after three, turn off error status. */
483 if (yyerrstatus) yyerrstatus--;
488 /* Do the default action for the current state. */
491 yyn = yydefact[yystate];
495 /* Do a reduction. yyn is the number of a rule to reduce with. */
499 yyval = yyvsp[1-yylen]; /* implement default value of the action */
506 fprintf (stderr, "Reducing via rule %d (line %d), ",
509 /* Print the symbols being reduced, and their result. */
510 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
511 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
512 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
516 $ /* the action file gets copied in in place of this dollarsign */
517 #line 498 "bison.simple"
528 short *ssp1 = yyss - 1;
529 fprintf (stderr, "state stack now");
530 while (ssp1 != yyssp)
531 fprintf (stderr, " %d", *++ssp1);
532 fprintf (stderr, "\n");
542 yylsp->first_line = yylloc.first_line;
543 yylsp->first_column = yylloc.first_column;
544 yylsp->last_line = (yylsp-1)->last_line;
545 yylsp->last_column = (yylsp-1)->last_column;
550 yylsp->last_line = (yylsp+yylen-1)->last_line;
551 yylsp->last_column = (yylsp+yylen-1)->last_column;
555 /* Now "shift" the result of the reduction.
556 Determine what state that goes to,
557 based on the state we popped back to
558 and the rule number reduced by. */
562 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
563 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
564 yystate = yytable[yystate];
566 yystate = yydefgoto[yyn - YYNTBASE];
570 yyerrlab: /* here on detecting error */
573 /* If not already recovering from an error, report this error. */
577 #ifdef YYERROR_VERBOSE
578 yyn = yypact[yystate];
580 if (yyn > YYFLAG && yyn < YYLAST)
587 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
588 for (x = (yyn < 0 ? -yyn : 0);
589 x < (sizeof(yytname) / sizeof(char *)); x++)
590 if (yycheck[x + yyn] == x)
591 size += strlen(yytname[x]) + 15, count++;
592 msg = (char *) malloc(size + 15);
595 strcpy(msg, "parse error");
600 for (x = (yyn < 0 ? -yyn : 0);
601 x < (sizeof(yytname) / sizeof(char *)); x++)
602 if (yycheck[x + yyn] == x)
604 strcat(msg, count == 0 ? ", expecting `" : " or `");
605 strcat(msg, yytname[x]);
614 yyerror ("parse error; also virtual memory exceeded");
617 #endif /* YYERROR_VERBOSE */
618 yyerror("parse error");
622 yyerrlab1: /* here on error raised explicitly by an action */
624 if (yyerrstatus == 3)
626 /* if just tried and failed to reuse lookahead token after an error, discard it. */
628 /* return failure if at end of input */
634 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
640 /* Else will try to reuse lookahead token
641 after shifting the error token. */
643 yyerrstatus = 3; /* Each real token shifted decrements this */
647 yyerrdefault: /* current state does not do anything special for the error token. */
650 /* This is wrong; only states that explicitly want error tokens
651 should shift them. */
652 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
653 if (yyn) goto yydefault;
656 yyerrpop: /* pop the current state because it cannot handle the error token */
658 if (yyssp == yyss) YYABORT;
668 short *ssp1 = yyss - 1;
669 fprintf (stderr, "Error: state stack now");
670 while (ssp1 != yyssp)
671 fprintf (stderr, " %d", *++ssp1);
672 fprintf (stderr, "\n");
678 yyn = yypact[yystate];
683 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
702 fprintf(stderr, "Shifting error token, ");