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 /* All symbols defined below should begin with yy or YY, to avoid
32 infringing on user name space. This should be done even for local
33 variables, as they might otherwise be expanded by user macros.
34 There are some unavoidable exceptions within include files to
35 define necessary library symbols; they are noted "INFRINGES ON
36 USER NAME SPACE" below. */
38 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
40 /* The parser invokes alloca or malloc; define the necessary symbols. */
42 # if YYSTACK_USE_ALLOCA
43 # define YYSTACK_ALLOC alloca
44 # define YYSIZE_T size_t
46 # ifndef YYSTACK_USE_ALLOCA
47 # if defined (alloca) || defined (_ALLOCA_H)
48 # define YYSTACK_ALLOC alloca
49 # define YYSIZE_T size_t
51 # if defined (__GNUC__) || defined (_AIX) || defined (__hpux)
52 # define YYSTACK_ALLOC __builtin_alloca
58 # if defined (__sgi) || defined (__sparc__) || defined (__sparc) || defined (__sun)
59 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
60 # define YYSTACK_ALLOC alloca
61 # define YYSIZE_T size_t
69 /* Pacify GCC's `empty if-body' warning. */
70 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
73 # include <cstdlib> /* INFRINGES ON USER NAME SPACE */
74 # define YYSIZE_T std::size_t
75 # define YYSTACK_ALLOC std::malloc
76 # define YYSTACK_FREE std::free
79 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
80 # define YYSIZE_T size_t
82 # define YYSTACK_ALLOC malloc
83 # define YYSTACK_FREE free
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 YYSIZE 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) \
120 YYSIZE_T yynewbytes; \
121 yymemcpy ((char *) yyptr, (char *) (Stack), \
122 yysize * (YYSIZE_T) sizeof (Type)); \
123 Stack = &yyptr->Stack; \
124 yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX; \
125 yyptr += yynewbytes / sizeof (*yyptr); \
129 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
132 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
133 # define YYSIZE_T __SIZE_TYPE__
135 #if ! defined (YYSIZE_T) && defined (size_t)
136 # define YYSIZE_T size_t
138 #if ! defined (YYSIZE_T)
140 # include <cstddef> /* INFRINGES ON USER NAME SPACE */
141 # define YYSIZE_T std::size_t
144 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
145 # define YYSIZE_T size_t
149 #if ! defined (YYSIZE_T)
150 # define YYSIZE_T unsigned int
153 #define yyerrok (yyerrstatus = 0)
154 #define yyclearin (yychar = YYEMPTY)
157 #define YYACCEPT goto yyacceptlab
158 #define YYABORT goto yyabortlab
159 #define YYERROR goto yyerrlab1
160 /* Like YYERROR except do call yyerror. This remains here temporarily
161 to ease the transition to the new meaning of YYERROR, for GCC.
162 Once GCC version 2 has supplanted version 1, this can go. */
163 #define YYFAIL goto yyerrlab
164 #define YYRECOVERING() (!!yyerrstatus)
165 #define YYBACKUP(Token, Value) \
167 if (yychar == YYEMPTY && yylen == 1) \
171 yychar1 = YYTRANSLATE (yychar); \
177 yyerror ("syntax error: cannot back up"); \
183 #define YYERRCODE 256
186 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
189 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
190 first token. By default, to implement support for ranges, extend
191 its range to the last symbol. */
193 #ifndef YYLLOC_DEFAULT
194 # define YYLLOC_DEFAULT(Current, Rhs, N) \
195 Current.last_line = Rhs[N].last_line; \
196 Current.last_column = Rhs[N].last_column;
200 /* YYLEX -- calling `yylex' with the right arguments. */
205 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
207 # define YYLEX yylex (&yylval, &yylloc)
209 # else /* !YYLSP_NEEDED */
211 # define YYLEX yylex (&yylval, YYLEX_PARAM)
213 # define YYLEX yylex (&yylval)
215 # endif /* !YYLSP_NEEDED */
217 # define YYLEX yylex ()
221 /* Enable debugging if requested. */
226 # include <cstdio.h> /* INFRINGES ON USER NAME SPACE */
227 # define YYFPRINTF std::fprintf
228 # define YYSTDERR std::stderr
230 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
231 # define YYFPRINTF fprintf
232 # define YYSTDERR stderr
236 # define YYDPRINTF(Args) \
241 /* Nonzero means print parse trace. [The following comment makes no
242 sense to me. Could someone clarify it? --akim] Since this is
243 uninitialized, it does not stop multiple parsers from coexisting.
247 # define YYDPRINTF(Args)
248 #endif /* !YYDEBUG */
250 /* YYINITDEPTH -- initial size of the parser's stacks. */
252 # define YYINITDEPTH 200
255 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
256 if the built-in stack extension method is used).
258 Do not make this value too large; the results are undefined if
259 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
260 evaluated with infinite-precision integer arithmetic. */
267 # define YYMAXDEPTH 10000
270 #if ! defined (yyoverflow) && ! defined (yymemcpy)
271 # if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
272 # define yymemcpy __builtin_memcpy
273 # else /* not GNU C or C++ */
275 /* This is the most reliable way to avoid incompatibilities
276 in available built-in functions on various systems. */
278 # if defined (__STDC__) || defined (__cplusplus)
279 yymemcpy (char *yyto, const char *yyfrom, YYSIZE_T yycount)
281 yymemcpy (yyto, yyfrom, yycount)
287 register const char *yyf = yyfrom;
288 register char *yyt = yyto;
289 register YYSIZE_T yyi = yycount;
297 #ifdef YYERROR_VERBOSE
300 # if defined (__GLIBC__) && defined (_STRING_H)
301 # define yystrlen strlen
303 /* Return the length of YYSTR. */
305 # if defined (__STDC__) || defined (__cplusplus)
306 yystrlen (const char *yystr)
312 register const char *yys = yystr;
314 while (*yys++ != '\0')
317 return yys - yystr - 1;
323 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
324 # define yystpcpy stpcpy
326 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
329 # if defined (__STDC__) || defined (__cplusplus)
330 yystpcpy (char *yydest, const char *yysrc)
332 yystpcpy (yydest, yysrc)
337 register char *yyd = yydest;
338 register const char *yys = yysrc;
340 while ((*yyd++ = *yys++) != '\0')
351 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
352 into yyparse. The argument should have type void *.
353 It should actually point to an object.
354 Grammar actions can access the variable by casting it
355 to the proper pointer type. */
359 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
360 # define YYPARSE_PARAM_DECL
361 # else /* !__cplusplus */
362 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
363 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
364 # endif /* !__cplusplus */
365 #else /* !YYPARSE_PARAM */
366 # define YYPARSE_PARAM_ARG
367 # define YYPARSE_PARAM_DECL
368 #endif /* !YYPARSE_PARAM */
370 /* Prevent warning if -Wstrict-prototypes. */
372 # ifdef YYPARSE_PARAM
373 int yyparse (void *);
379 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
380 variables are global, or local to YYPARSE. */
382 #define YY_DECL_NON_LSP_VARIABLES \
383 /* The lookahead symbol. */ \
386 /* The semantic value of the lookahead symbol. */ \
389 /* Number of parse errors so far. */ \
393 # define YY_DECL_VARIABLES \
394 YY_DECL_NON_LSP_VARIABLES \
396 /* Location data for the lookahead symbol. */ \
399 # define YY_DECL_VARIABLES \
400 YY_DECL_NON_LSP_VARIABLES
404 /* If nonreentrant, generate the variables here. */
411 yyparse (YYPARSE_PARAM_ARG)
414 /* If reentrant, generate the variables here. */
419 register int yystate;
422 /* Number of tokens to shift before error messages enabled. */
424 /* Lookahead token as an internal (translated) token number. */
427 /* Three stacks and their tools:
428 `yyss': related to states,
429 `yyvs': related to semantic values,
430 `yyls': related to locations.
432 Refer to the stacks thru separate pointers, to allow yyoverflow
433 to reallocate them elsewhere. */
435 /* The state stack. */
436 short yyssa[YYINITDEPTH];
438 register short *yyssp;
440 /* The semantic value stack. */
441 YYSTYPE yyvsa[YYINITDEPTH];
442 YYSTYPE *yyvs = yyvsa;
443 register YYSTYPE *yyvsp;
446 /* The location stack. */
447 YYLTYPE yylsa[YYINITDEPTH];
448 YYLTYPE *yyls = yylsa;
453 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
455 # define YYPOPSTACK (yyvsp--, yyssp--)
458 YYSIZE_T yystacksize = YYINITDEPTH;
461 /* The variables used to return semantic value and location from the
468 /* When reducing, the number of symbols on the RHS of the reduced
472 YYDPRINTF ((YYSTDERR, "Starting parse\n"));
477 yychar = YYEMPTY; /* Cause a token to be read. */
479 /* Initialize stack pointers.
480 Waste one element of value and location stack
481 so that they stay on the same level as the state stack.
482 The wasted elements are never initialized. */
491 /*------------------------------------------------------------.
492 | yynewstate -- Push a new state, which is found in yystate. |
493 `------------------------------------------------------------*/
495 /* In all cases, when you get here, the value and location stacks
496 have just been pushed. so pushing a state here evens the stacks.
503 if (yyssp >= yyss + yystacksize - 1)
505 /* Get the current used size of the three stacks, in elements. */
506 YYSIZE_T yysize = yyssp - yyss + 1;
510 /* Give user a chance to reallocate the stack. Use copies of
511 these so that the &'s don't force the real ones into
513 YYSTYPE *yyvs1 = yyvs;
516 /* Each stack pointer address is followed by the size of the
517 data in use in that stack, in bytes. */
519 YYLTYPE *yyls1 = yyls;
520 /* This used to be a conditional around just the two extra args,
521 but that might be undefined if yyoverflow is a macro. */
522 yyoverflow ("parser stack overflow",
523 &yyss1, yysize * sizeof (*yyssp),
524 &yyvs1, yysize * sizeof (*yyvsp),
525 &yyls1, yysize * sizeof (*yylsp),
529 yyoverflow ("parser stack overflow",
530 &yyss1, yysize * sizeof (*yyssp),
531 &yyvs1, yysize * sizeof (*yyvsp),
537 #else /* no yyoverflow */
538 /* Extend the stack our own way. */
539 if (yystacksize >= YYMAXDEPTH)
542 if (yystacksize > YYMAXDEPTH)
543 yystacksize = YYMAXDEPTH;
547 union yyalloc *yyptr =
548 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
551 YYSTACK_RELOCATE (short, yyss);
552 YYSTACK_RELOCATE (YYSTYPE, yyvs);
554 YYSTACK_RELOCATE (YYLTYPE, yyls);
556 # undef YYSTACK_RELOCATE
558 YYSTACK_FREE (yyss1);
560 #endif /* no yyoverflow */
562 yyssp = yyss + yysize - 1;
563 yyvsp = yyvs + yysize - 1;
565 yylsp = yyls + yysize - 1;
568 YYDPRINTF ((YYSTDERR, "Stack size increased to %lu\n",
569 (unsigned long int) yystacksize));
571 if (yyssp >= yyss + yystacksize - 1)
575 YYDPRINTF ((YYSTDERR, "Entering state %d\n", yystate));
585 /* Do appropriate processing given the current state. */
586 /* Read a lookahead token if we need one and don't already have one. */
589 /* First try to decide what to do without reference to lookahead token. */
591 yyn = yypact[yystate];
595 /* Not known => get a lookahead token if don't already have one. */
597 /* yychar is either YYEMPTY or YYEOF
598 or a valid token in external form. */
600 if (yychar == YYEMPTY)
602 YYDPRINTF ((YYSTDERR, "Reading a token: "));
606 /* Convert token to internal form (in yychar1) for indexing tables with */
608 if (yychar <= 0) /* This means end of input. */
611 yychar = YYEOF; /* Don't call YYLEX any more */
613 YYDPRINTF ((YYSTDERR, "Now at end of input.\n"));
617 yychar1 = YYTRANSLATE (yychar);
620 /* We have to keep this `#if YYDEBUG', since we use variables
621 which are defined only if `YYDEBUG' is set. */
624 YYFPRINTF (YYSTDERR, "Next token is %d (%s",
625 yychar, yytname[yychar1]);
626 /* Give the individual parser a way to print the precise
627 meaning of a token, for further debugging info. */
629 YYPRINT (YYSTDERR, yychar, yylval);
631 YYFPRINTF (YYSTDERR, ")\n");
637 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
642 /* yyn is what to do for this token type in this state.
643 Negative => reduce, -yyn is rule number.
644 Positive => shift, yyn is new state.
645 New state is final state => don't bother to shift,
647 0, or most negative number => error. */
662 /* Shift the lookahead token. */
663 YYDPRINTF ((YYSTDERR, "Shifting token %d (%s), ",
664 yychar, yytname[yychar1]));
666 /* Discard the token being shifted unless it is eof. */
675 /* Count tokens shifted since error; after three, turn off error
684 /*-----------------------------------------------------------.
685 | yydefault -- do the default action for the current state. |
686 `-----------------------------------------------------------*/
688 yyn = yydefact[yystate];
694 /*-----------------------------.
695 | yyreduce -- Do a reduction. |
696 `-----------------------------*/
698 /* yyn is the number of a rule to reduce with. */
701 /* If YYLEN is nonzero, implement the default value of the action:
704 Otherwise, the following line sets YYVAL to the semantic value of
705 the lookahead token. This behavior is undocumented and Bison
706 users should not rely upon it. Assigning to YYVAL
707 unconditionally makes the parser a bit smaller, and it avoids a
708 GCC warning that YYVAL may be used uninitialized. */
709 yyval = yyvsp[1-yylen];
712 /* Similarly for the default location. Let the user run additional
713 commands if for instance locations are ranges. */
714 yyloc = yylsp[1-yylen];
715 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
719 /* We have to keep this `#if YYDEBUG', since we use variables which
720 are defined only if `YYDEBUG' is set. */
725 YYFPRINTF (YYSTDERR, "Reducing via rule %d (line %d), ",
728 /* Print the symbols being reduced, and their result. */
729 for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
730 YYFPRINTF (YYSTDERR, "%s ", yytname[yyrhs[yyi]]);
731 YYFPRINTF (YYSTDERR, " -> %s\n", yytname[yyr1[yyn]]);
734 %% actions /* The action file replaces this line. */
746 short *yyssp1 = yyss - 1;
747 YYFPRINTF (YYSTDERR, "state stack now");
748 while (yyssp1 != yyssp)
749 YYFPRINTF (YYSTDERR, " %d", *++yyssp1);
750 YYFPRINTF (YYSTDERR, "\n");
759 /* Now `shift' the result of the reduction. Determine what state
760 that goes to, based on the state we popped back to and the rule
761 number reduced by. */
765 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
766 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
767 yystate = yytable[yystate];
769 yystate = yydefgoto[yyn - YYNTBASE];
774 /*------------------------------------.
775 | yyerrlab -- here on detecting error |
776 `------------------------------------*/
778 /* If not already recovering from an error, report this error. */
783 #ifdef YYERROR_VERBOSE
784 yyn = yypact[yystate];
786 if (yyn > YYFLAG && yyn < YYLAST)
793 /* Start YYX at -YYN if negative to avoid negative indexes in
795 for (yyx = yyn < 0 ? -yyn : 0;
796 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
797 if (yycheck[yyx + yyn] == yyx)
798 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
799 yysize += yystrlen ("parse error, unexpected ") + 1;
800 yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
801 yymsg = (char *) YYSTACK_ALLOC (yysize);
804 char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
805 yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
810 for (yyx = yyn < 0 ? -yyn : 0;
811 yyx < (int) (sizeof (yytname) / sizeof (char *));
813 if (yycheck[yyx + yyn] == yyx)
815 const char *yyq = ! yycount ? ", expecting " : " or ";
816 yyp = yystpcpy (yyp, yyq);
817 yyp = yystpcpy (yyp, yytname[yyx]);
822 YYSTACK_FREE (yymsg);
825 yyerror ("parse error; also virtual memory exhausted");
828 #endif /* defined (YYERROR_VERBOSE) */
829 yyerror ("parse error");
834 /*--------------------------------------------------.
835 | yyerrlab1 -- error raised explicitly by an action |
836 `--------------------------------------------------*/
838 if (yyerrstatus == 3)
840 /* If just tried and failed to reuse lookahead token after an
841 error, discard it. */
843 /* return failure if at end of input */
846 YYDPRINTF ((YYSTDERR, "Discarding token %d (%s).\n",
847 yychar, yytname[yychar1]));
851 /* Else will try to reuse lookahead token after shifting the error
854 yyerrstatus = 3; /* Each real token shifted decrements this */
859 /*-------------------------------------------------------------------.
860 | yyerrdefault -- current state does not do anything special for the |
862 `-------------------------------------------------------------------*/
865 /* This is wrong; only states that explicitly want error tokens
866 should shift them. */
868 /* If its default is to accept any token, ok. Otherwise pop it. */
869 yyn = yydefact[yystate];
875 /*---------------------------------------------------------------.
876 | yyerrpop -- pop the current state because it cannot handle the |
878 `---------------------------------------------------------------*/
891 short *yyssp1 = yyss - 1;
892 YYFPRINTF (YYSTDERR, "Error: state stack now");
893 while (yyssp1 != yyssp)
894 YYFPRINTF (YYSTDERR, " %d", *++yyssp1);
895 YYFPRINTF (YYSTDERR, "\n");
903 yyn = yypact[yystate];
908 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
925 YYDPRINTF ((YYSTDERR, "Shifting error token, "));
936 /*-------------------------------------.
937 | yyacceptlab -- YYACCEPT comes here. |
938 `-------------------------------------*/
943 /*-----------------------------------.
944 | yyabortlab -- YYABORT comes here. |
945 `-----------------------------------*/
950 /*---------------------------------------------.
951 | yyoverflowab -- parser overflow comes here. |
952 `---------------------------------------------*/
954 yyerror ("parser stack overflow");