1 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
3 /* Skeleton output parser for bison,
4 Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, 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 when
27 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. */
31 #ifndef YYSTACK_USE_ALLOCA
33 # define YYSTACK_USE_ALLOCA 1
34 # else /* alloca not defined */
36 # define YYSTACK_USE_ALLOCA 1
37 # define alloca __builtin_alloca
38 # else /* not GNU C. */
39 # if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
40 # define YYSTACK_USE_ALLOCA 1
42 # else /* not sparc */
43 /* We think this test detects Watcom and Microsoft C. */
44 /* This used to test MSDOS, but that is a bad idea since that
45 symbol is in the user namespace. */
46 # if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
48 /* No need for malloc.h, which pollutes the namespace; instead,
49 just don't use alloca. */
52 # else /* not MSDOS, or __TURBOC__ */
54 /* I don't know what this was needed for, but it pollutes the
55 namespace. So I turned it off. rms, 2 May 1997. */
56 /* #include <malloc.h> */
58 # define YYSTACK_USE_ALLOCA 1
59 # else /* not MSDOS, or __TURBOC__, or _AIX */
61 /* haible@ilog.fr says this works for HPUX 9.05 and up, and on
62 HPUX 10. Eventually we can turn this on. */
64 # define YYSTACK_USE_ALLOCA 1
65 # define alloca __builtin_alloca
68 # endif /* not _AIX */
69 # endif /* not MSDOS, or __TURBOC__ */
70 # endif /* not sparc */
71 # endif /* not GNU C */
72 # endif /* alloca not defined */
73 #endif /* YYSTACK_USE_ALLOCA not defined */
75 #ifndef YYSTACK_USE_ALLOCA
76 # define YYSTACK_USE_ALLOCA 0
79 #if YYSTACK_USE_ALLOCA
80 # define YYSTACK_ALLOC alloca
81 # define YYSTACK_FREE(Ptr) /* empty */
83 # define YYSTACK_ALLOC malloc
84 # define YYSTACK_FREE(Ptr) free (Ptr)
87 /* A type that is properly aligned for any stack member. */
97 /* The size of the maximum gap between one aligned stack and the next. */
98 #define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
100 /* The size of an array large to enough to hold all stacks, each with
103 # define YYSTACK_BYTES(N) \
104 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
105 + 2 * YYSTACK_GAP_MAX)
107 # define YYSTACK_BYTES(N) \
108 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
112 /* Relocate the TYPE STACK from its old location to the new one. The
113 local variables SIZE and YYSTACKSIZE give the old and new number of
114 elements in the stack, and YYPTR gives the new location of the
115 stack. Advance YYPTR to a properly aligned location for the next
117 #define YYSTACK_RELOCATE(Type, Stack) \
121 __yy_memcpy (yyptr, (char *) (Stack), size * sizeof (Type)); \
122 (Stack) = (Type *) yyptr; \
123 yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX; \
124 yynewbytes -= yynewbytes % sizeof (union yyalloc); \
125 yyptr += yynewbytes; \
129 #define yyerrok (yyerrstatus = 0)
130 #define yyclearin (yychar = YYEMPTY)
133 #define YYACCEPT goto yyacceptlab
134 #define YYABORT goto yyabortlab
135 #define YYERROR goto yyerrlab1
136 /* Like YYERROR except do call yyerror. This remains here temporarily
137 to ease the transition to the new meaning of YYERROR, for GCC.
138 Once GCC version 2 has supplanted version 1, this can go. */
139 #define YYFAIL goto yyerrlab
140 #define YYRECOVERING() (!!yyerrstatus)
141 #define YYBACKUP(Token, Value) \
143 if (yychar == YYEMPTY && yylen == 1) \
147 yychar1 = YYTRANSLATE (yychar); \
153 yyerror ("syntax error: cannot back up"); \
159 #define YYERRCODE 256
162 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
165 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
166 first token. By default, to implement support for ranges, extend
167 its range to the last symbol. */
169 #ifndef YYLLOC_DEFAULT
170 # define YYLLOC_DEFAULT(Current, Rhs, N) \
171 Current.last_line = Rhs[N].last_line; \
172 Current.last_column = Rhs[N].last_column;
176 /* YYLEX -- calling `yylex' with the right arguments. */
181 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
183 # define YYLEX yylex (&yylval, &yylloc)
185 # else /* !YYLSP_NEEDED */
187 # define YYLEX yylex (&yylval, YYLEX_PARAM)
189 # define YYLEX yylex (&yylval)
191 # endif /* !YYLSP_NEEDED */
193 # define YYLEX yylex ()
197 /* Enable debugging if requested. */
199 # define YYDPRINTF(Args) \
204 /* Nonzero means print parse trace. [The following comment makes no
205 sense to me. Could someone clarify it? --akim] Since this is
206 uninitialized, it does not stop multiple parsers from coexisting.
210 # define YYDPRINTF(Args)
211 #endif /* !YYDEBUG */
213 /* YYINITDEPTH -- initial size of the parser's stacks. */
215 # define YYINITDEPTH 200
218 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
219 if the built-in stack extension method is used).
221 Do not make this value too large; the results are undefined if
222 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
223 evaluated with infinite-precision integer arithmetic. */
230 # define YYMAXDEPTH 10000
233 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
234 # define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
235 #else /* not GNU C or C++ */
237 /* This is the most reliable way to avoid incompatibilities
238 in available built-in functions on various systems. */
241 __yy_memcpy (to, from, count)
245 # else /* __cplusplus */
246 __yy_memcpy (char *to, const char *from, size_t count)
249 register const char *f = from;
250 register char *t = to;
251 register size_t i = count;
261 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
262 into yyparse. The argument should have type void *.
263 It should actually point to an object.
264 Grammar actions can access the variable by casting it
265 to the proper pointer type. */
269 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
270 # define YYPARSE_PARAM_DECL
271 # else /* !__cplusplus */
272 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
273 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
274 # endif /* !__cplusplus */
275 #else /* !YYPARSE_PARAM */
276 # define YYPARSE_PARAM_ARG
277 # define YYPARSE_PARAM_DECL
278 #endif /* !YYPARSE_PARAM */
280 /* Prevent warning if -Wstrict-prototypes. */
282 # ifdef YYPARSE_PARAM
283 int yyparse (void *);
289 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
290 variables are global, or local to YYPARSE. */
292 #define _YY_DECL_VARIABLES \
293 /* The lookahead symbol. */ \
296 /* The semantic value of the lookahead symbol. */ \
299 /* Number of parse errors so far. */ \
303 # define YY_DECL_VARIABLES \
306 /* Location data for the lookahead symbol. */ \
309 # define YY_DECL_VARIABLES \
314 /* If nonreentrant, generate the variables here. */
321 yyparse (YYPARSE_PARAM_ARG)
324 /* If reentrant, generate the variables here. */
329 register int yystate;
332 /* Number of tokens to shift before error messages enabled. */
334 /* Lookahead token as an internal (translated) token number. */
337 /* Three stacks and their tools:
338 `yyss': related to states,
339 `yyvs': related to semantic values,
340 `yyls': related to locations.
342 Refer to the stacks thru separate pointers, to allow yyoverflow
343 to reallocate them elsewhere. */
345 /* The state stack. */
346 short yyssa[YYINITDEPTH];
348 register short *yyssp;
350 /* The semantic value stack. */
351 YYSTYPE yyvsa[YYINITDEPTH];
352 YYSTYPE *yyvs = yyvsa;
353 register YYSTYPE *yyvsp;
356 /* The location stack. */
357 YYLTYPE yylsa[YYINITDEPTH];
358 YYLTYPE *yyls = yylsa;
363 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
365 # define YYPOPSTACK (yyvsp--, yyssp--)
368 size_t yystacksize = YYINITDEPTH;
371 /* The variables used to return semantic value and location from the
378 /* When reducing, the number of symbols on the RHS of the reduced
382 YYDPRINTF ((stderr, "Starting parse\n"));
387 yychar = YYEMPTY; /* Cause a token to be read. */
389 /* Initialize stack pointers.
390 Waste one element of value and location stack
391 so that they stay on the same level as the state stack.
392 The wasted elements are never initialized. */
401 /*------------------------------------------------------------.
402 | yynewstate -- Push a new state, which is found in yystate. |
403 `------------------------------------------------------------*/
405 /* In all cases, when you get here, the value and location stacks
406 have just been pushed. so pushing a state here evens the stacks.
413 if (yyssp >= yyss + yystacksize - 1)
415 /* Get the current used size of the three stacks, in elements. */
416 size_t size = yyssp - yyss + 1;
420 /* Give user a chance to reallocate the stack. Use copies of
421 these so that the &'s don't force the real ones into
423 YYSTYPE *yyvs1 = yyvs;
426 /* Each stack pointer address is followed by the size of the
427 data in use in that stack, in bytes. */
429 YYLTYPE *yyls1 = yyls;
430 /* This used to be a conditional around just the two extra args,
431 but that might be undefined if yyoverflow is a macro. */
432 yyoverflow ("parser stack overflow",
433 &yyss1, size * sizeof (*yyssp),
434 &yyvs1, size * sizeof (*yyvsp),
435 &yyls1, size * sizeof (*yylsp),
439 yyoverflow ("parser stack overflow",
440 &yyss1, size * sizeof (*yyssp),
441 &yyvs1, size * sizeof (*yyvsp),
447 #else /* no yyoverflow */
448 /* Extend the stack our own way. */
449 if (yystacksize >= YYMAXDEPTH)
452 if (yystacksize > YYMAXDEPTH)
453 yystacksize = YYMAXDEPTH;
457 char *yyptr = (char *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
460 YYSTACK_RELOCATE (short, yyss);
461 YYSTACK_RELOCATE (YYSTYPE, yyvs);
463 YYSTACK_RELOCATE (YYLTYPE, yyls);
465 # undef YYSTACK_RELOCATE
467 YYSTACK_FREE (yyss1);
469 #endif /* no yyoverflow */
471 yyssp = yyss + size - 1;
472 yyvsp = yyvs + size - 1;
474 yylsp = yyls + size - 1;
477 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
478 (unsigned long int) yystacksize));
480 if (yyssp >= yyss + yystacksize - 1)
484 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
494 /* Do appropriate processing given the current state. */
495 /* Read a lookahead token if we need one and don't already have one. */
498 /* First try to decide what to do without reference to lookahead token. */
500 yyn = yypact[yystate];
504 /* Not known => get a lookahead token if don't already have one. */
506 /* yychar is either YYEMPTY or YYEOF
507 or a valid token in external form. */
509 if (yychar == YYEMPTY)
511 YYDPRINTF ((stderr, "Reading a token: "));
515 /* Convert token to internal form (in yychar1) for indexing tables with */
517 if (yychar <= 0) /* This means end of input. */
520 yychar = YYEOF; /* Don't call YYLEX any more */
522 YYDPRINTF ((stderr, "Now at end of input.\n"));
526 yychar1 = YYTRANSLATE (yychar);
529 /* We have to keep this `#if YYDEBUG', since we use variables
530 which are defined only if `YYDEBUG' is set. */
533 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
534 /* Give the individual parser a way to print the precise
535 meaning of a token, for further debugging info. */
537 YYPRINT (stderr, yychar, yylval);
539 fprintf (stderr, ")\n");
545 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
550 /* yyn is what to do for this token type in this state.
551 Negative => reduce, -yyn is rule number.
552 Positive => shift, yyn is new state.
553 New state is final state => don't bother to shift,
555 0, or most negative number => error. */
570 /* Shift the lookahead token. */
571 YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]));
573 /* Discard the token being shifted unless it is eof. */
582 /* Count tokens shifted since error; after three, turn off error
591 /*-----------------------------------------------------------.
592 | yydefault -- do the default action for the current state. |
593 `-----------------------------------------------------------*/
595 yyn = yydefact[yystate];
601 /*-----------------------------.
602 | yyreduce -- Do a reduction. |
603 `-----------------------------*/
605 /* yyn is the number of a rule to reduce with. */
608 /* If YYLEN is nonzero, implement the default value of the action:
611 Otherwise, the following line sets YYVAL to the semantic value of
612 the lookahead token. This behavior is undocumented and Bison
613 users should not rely upon it. Assigning to YYVAL
614 unconditionally makes the parser a bit smaller, and it avoids a
615 GCC warning that YYVAL may be used uninitialized. */
616 yyval = yyvsp[1-yylen];
619 /* Similarly for the default location. Let the user run additional
620 commands if for instance locations are ranges. */
621 yyloc = yylsp[1-yylen];
622 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
626 /* We have to keep this `#if YYDEBUG', since we use variables which
627 are defined only if `YYDEBUG' is set. */
632 fprintf (stderr, "Reducing via rule %d (line %d), ",
635 /* Print the symbols being reduced, and their result. */
636 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
637 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
638 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
641 %% actions /* The action file replaces this line. */
653 short *ssp1 = yyss - 1;
654 fprintf (stderr, "state stack now");
655 while (ssp1 != yyssp)
656 fprintf (stderr, " %d", *++ssp1);
657 fprintf (stderr, "\n");
666 /* Now `shift' the result of the reduction. Determine what state
667 that goes to, based on the state we popped back to and the rule
668 number reduced by. */
672 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
673 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
674 yystate = yytable[yystate];
676 yystate = yydefgoto[yyn - YYNTBASE];
681 /*------------------------------------.
682 | yyerrlab -- here on detecting error |
683 `------------------------------------*/
685 /* If not already recovering from an error, report this error. */
690 #ifdef YYERROR_VERBOSE
691 yyn = yypact[yystate];
693 if (yyn > YYFLAG && yyn < YYLAST)
700 /* Start X at -YYN if negative to avoid negative indexes in
702 for (x = yyn < 0 ? -yyn : 0;
703 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
704 if (yycheck[x + yyn] == x)
705 size += strlen (yytname[x]) + 15, count++;
706 size += strlen ("parse error, unexpected ") + 1;
707 size += strlen (yytname[YYTRANSLATE (yychar)]);
708 msg = (char *) malloc (size);
711 strcpy (msg, "parse error, unexpected ");
712 strcat (msg, yytname[YYTRANSLATE (yychar)]);
717 for (x = yyn < 0 ? -yyn : 0;
718 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
719 if (yycheck[x + yyn] == x)
721 strcat (msg, count == 0 ? ", expecting " : " or ");
722 strcat (msg, yytname[x]);
730 yyerror ("parse error; also virtual memory exhausted");
733 #endif /* YYERROR_VERBOSE */
734 yyerror ("parse error");
739 /*--------------------------------------------------.
740 | yyerrlab1 -- error raised explicitly by an action |
741 `--------------------------------------------------*/
743 if (yyerrstatus == 3)
745 /* If just tried and failed to reuse lookahead token after an
746 error, discard it. */
748 /* return failure if at end of input */
751 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
752 yychar, yytname[yychar1]));
756 /* Else will try to reuse lookahead token after shifting the error
759 yyerrstatus = 3; /* Each real token shifted decrements this */
764 /*-------------------------------------------------------------------.
765 | yyerrdefault -- current state does not do anything special for the |
767 `-------------------------------------------------------------------*/
770 /* This is wrong; only states that explicitly want error tokens
771 should shift them. */
773 /* If its default is to accept any token, ok. Otherwise pop it. */
774 yyn = yydefact[yystate];
780 /*---------------------------------------------------------------.
781 | yyerrpop -- pop the current state because it cannot handle the |
783 `---------------------------------------------------------------*/
796 short *ssp1 = yyss - 1;
797 fprintf (stderr, "Error: state stack now");
798 while (ssp1 != yyssp)
799 fprintf (stderr, " %d", *++ssp1);
800 fprintf (stderr, "\n");
808 yyn = yypact[yystate];
813 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
830 YYDPRINTF ((stderr, "Shifting error token, "));
841 /*-------------------------------------.
842 | yyacceptlab -- YYACCEPT comes here. |
843 `-------------------------------------*/
848 /*-----------------------------------.
849 | yyabortlab -- YYABORT comes here. |
850 `-----------------------------------*/
855 /*---------------------------------------------.
856 | yyoverflowab -- parser overflow comes here. |
857 `---------------------------------------------*/
859 yyerror ("parser stack overflow");