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 /* Pacify GCC's `empty if-body' warning. */
82 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
84 # define YYSTACK_ALLOC malloc
85 # define YYSTACK_FREE(Ptr) free (Ptr)
88 /* A type that is properly aligned for any stack member. */
98 /* The size of the maximum gap between one aligned stack and the next. */
99 #define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
101 /* The size of an array large to enough to hold all stacks, each with
104 # define YYSTACK_BYTES(N) \
105 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
106 + 2 * YYSTACK_GAP_MAX)
108 # define YYSTACK_BYTES(N) \
109 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
113 /* Relocate the TYPE STACK from its old location to the new one. The
114 local variables SIZE and YYSTACKSIZE give the old and new number of
115 elements in the stack, and YYPTR gives the new location of the
116 stack. Advance YYPTR to a properly aligned location for the next
118 #define YYSTACK_RELOCATE(Type, Stack) \
122 __yy_memcpy (yyptr, (char *) (Stack), size * sizeof (Type)); \
123 (Stack) = (Type *) yyptr; \
124 yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX; \
125 yynewbytes -= yynewbytes % sizeof (union yyalloc); \
126 yyptr += yynewbytes; \
130 #define yyerrok (yyerrstatus = 0)
131 #define yyclearin (yychar = YYEMPTY)
134 #define YYACCEPT goto yyacceptlab
135 #define YYABORT goto yyabortlab
136 #define YYERROR goto yyerrlab1
137 /* Like YYERROR except do call yyerror. This remains here temporarily
138 to ease the transition to the new meaning of YYERROR, for GCC.
139 Once GCC version 2 has supplanted version 1, this can go. */
140 #define YYFAIL goto yyerrlab
141 #define YYRECOVERING() (!!yyerrstatus)
142 #define YYBACKUP(Token, Value) \
144 if (yychar == YYEMPTY && yylen == 1) \
148 yychar1 = YYTRANSLATE (yychar); \
154 yyerror ("syntax error: cannot back up"); \
160 #define YYERRCODE 256
163 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
166 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
167 first token. By default, to implement support for ranges, extend
168 its range to the last symbol. */
170 #ifndef YYLLOC_DEFAULT
171 # define YYLLOC_DEFAULT(Current, Rhs, N) \
172 Current.last_line = Rhs[N].last_line; \
173 Current.last_column = Rhs[N].last_column;
177 /* YYLEX -- calling `yylex' with the right arguments. */
182 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
184 # define YYLEX yylex (&yylval, &yylloc)
186 # else /* !YYLSP_NEEDED */
188 # define YYLEX yylex (&yylval, YYLEX_PARAM)
190 # define YYLEX yylex (&yylval)
192 # endif /* !YYLSP_NEEDED */
194 # define YYLEX yylex ()
198 /* Enable debugging if requested. */
200 # define YYDPRINTF(Args) \
205 /* Nonzero means print parse trace. [The following comment makes no
206 sense to me. Could someone clarify it? --akim] Since this is
207 uninitialized, it does not stop multiple parsers from coexisting.
211 # define YYDPRINTF(Args)
212 #endif /* !YYDEBUG */
214 /* YYINITDEPTH -- initial size of the parser's stacks. */
216 # define YYINITDEPTH 200
219 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
220 if the built-in stack extension method is used).
222 Do not make this value too large; the results are undefined if
223 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
224 evaluated with infinite-precision integer arithmetic. */
231 # define YYMAXDEPTH 10000
234 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
235 # define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
236 #else /* not GNU C or C++ */
238 /* This is the most reliable way to avoid incompatibilities
239 in available built-in functions on various systems. */
242 __yy_memcpy (to, from, count)
246 # else /* __cplusplus */
247 __yy_memcpy (char *to, const char *from, size_t count)
250 register const char *f = from;
251 register char *t = to;
252 register size_t i = count;
262 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
263 into yyparse. The argument should have type void *.
264 It should actually point to an object.
265 Grammar actions can access the variable by casting it
266 to the proper pointer type. */
270 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
271 # define YYPARSE_PARAM_DECL
272 # else /* !__cplusplus */
273 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
274 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
275 # endif /* !__cplusplus */
276 #else /* !YYPARSE_PARAM */
277 # define YYPARSE_PARAM_ARG
278 # define YYPARSE_PARAM_DECL
279 #endif /* !YYPARSE_PARAM */
281 /* Prevent warning if -Wstrict-prototypes. */
283 # ifdef YYPARSE_PARAM
284 int yyparse (void *);
290 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
291 variables are global, or local to YYPARSE. */
293 #define _YY_DECL_VARIABLES \
294 /* The lookahead symbol. */ \
297 /* The semantic value of the lookahead symbol. */ \
300 /* Number of parse errors so far. */ \
304 # define YY_DECL_VARIABLES \
307 /* Location data for the lookahead symbol. */ \
310 # define YY_DECL_VARIABLES \
315 /* If nonreentrant, generate the variables here. */
322 yyparse (YYPARSE_PARAM_ARG)
325 /* If reentrant, generate the variables here. */
330 register int yystate;
333 /* Number of tokens to shift before error messages enabled. */
335 /* Lookahead token as an internal (translated) token number. */
338 /* Three stacks and their tools:
339 `yyss': related to states,
340 `yyvs': related to semantic values,
341 `yyls': related to locations.
343 Refer to the stacks thru separate pointers, to allow yyoverflow
344 to reallocate them elsewhere. */
346 /* The state stack. */
347 short yyssa[YYINITDEPTH];
349 register short *yyssp;
351 /* The semantic value stack. */
352 YYSTYPE yyvsa[YYINITDEPTH];
353 YYSTYPE *yyvs = yyvsa;
354 register YYSTYPE *yyvsp;
357 /* The location stack. */
358 YYLTYPE yylsa[YYINITDEPTH];
359 YYLTYPE *yyls = yylsa;
364 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
366 # define YYPOPSTACK (yyvsp--, yyssp--)
369 size_t yystacksize = YYINITDEPTH;
372 /* The variables used to return semantic value and location from the
379 /* When reducing, the number of symbols on the RHS of the reduced
383 YYDPRINTF ((stderr, "Starting parse\n"));
388 yychar = YYEMPTY; /* Cause a token to be read. */
390 /* Initialize stack pointers.
391 Waste one element of value and location stack
392 so that they stay on the same level as the state stack.
393 The wasted elements are never initialized. */
402 /*------------------------------------------------------------.
403 | yynewstate -- Push a new state, which is found in yystate. |
404 `------------------------------------------------------------*/
406 /* In all cases, when you get here, the value and location stacks
407 have just been pushed. so pushing a state here evens the stacks.
414 if (yyssp >= yyss + yystacksize - 1)
416 /* Get the current used size of the three stacks, in elements. */
417 size_t size = yyssp - yyss + 1;
421 /* Give user a chance to reallocate the stack. Use copies of
422 these so that the &'s don't force the real ones into
424 YYSTYPE *yyvs1 = yyvs;
427 /* Each stack pointer address is followed by the size of the
428 data in use in that stack, in bytes. */
430 YYLTYPE *yyls1 = yyls;
431 /* This used to be a conditional around just the two extra args,
432 but that might be undefined if yyoverflow is a macro. */
433 yyoverflow ("parser stack overflow",
434 &yyss1, size * sizeof (*yyssp),
435 &yyvs1, size * sizeof (*yyvsp),
436 &yyls1, size * sizeof (*yylsp),
440 yyoverflow ("parser stack overflow",
441 &yyss1, size * sizeof (*yyssp),
442 &yyvs1, size * sizeof (*yyvsp),
448 #else /* no yyoverflow */
449 /* Extend the stack our own way. */
450 if (yystacksize >= YYMAXDEPTH)
453 if (yystacksize > YYMAXDEPTH)
454 yystacksize = YYMAXDEPTH;
458 char *yyptr = (char *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
461 YYSTACK_RELOCATE (short, yyss);
462 YYSTACK_RELOCATE (YYSTYPE, yyvs);
464 YYSTACK_RELOCATE (YYLTYPE, yyls);
466 # undef YYSTACK_RELOCATE
468 YYSTACK_FREE (yyss1);
470 #endif /* no yyoverflow */
472 yyssp = yyss + size - 1;
473 yyvsp = yyvs + size - 1;
475 yylsp = yyls + size - 1;
478 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
479 (unsigned long int) yystacksize));
481 if (yyssp >= yyss + yystacksize - 1)
485 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
495 /* Do appropriate processing given the current state. */
496 /* Read a lookahead token if we need one and don't already have one. */
499 /* First try to decide what to do without reference to lookahead token. */
501 yyn = yypact[yystate];
505 /* Not known => get a lookahead token if don't already have one. */
507 /* yychar is either YYEMPTY or YYEOF
508 or a valid token in external form. */
510 if (yychar == YYEMPTY)
512 YYDPRINTF ((stderr, "Reading a token: "));
516 /* Convert token to internal form (in yychar1) for indexing tables with */
518 if (yychar <= 0) /* This means end of input. */
521 yychar = YYEOF; /* Don't call YYLEX any more */
523 YYDPRINTF ((stderr, "Now at end of input.\n"));
527 yychar1 = YYTRANSLATE (yychar);
530 /* We have to keep this `#if YYDEBUG', since we use variables
531 which are defined only if `YYDEBUG' is set. */
534 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
535 /* Give the individual parser a way to print the precise
536 meaning of a token, for further debugging info. */
538 YYPRINT (stderr, yychar, yylval);
540 fprintf (stderr, ")\n");
546 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
551 /* yyn is what to do for this token type in this state.
552 Negative => reduce, -yyn is rule number.
553 Positive => shift, yyn is new state.
554 New state is final state => don't bother to shift,
556 0, or most negative number => error. */
571 /* Shift the lookahead token. */
572 YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]));
574 /* Discard the token being shifted unless it is eof. */
583 /* Count tokens shifted since error; after three, turn off error
592 /*-----------------------------------------------------------.
593 | yydefault -- do the default action for the current state. |
594 `-----------------------------------------------------------*/
596 yyn = yydefact[yystate];
602 /*-----------------------------.
603 | yyreduce -- Do a reduction. |
604 `-----------------------------*/
606 /* yyn is the number of a rule to reduce with. */
609 /* If YYLEN is nonzero, implement the default value of the action:
612 Otherwise, the following line sets YYVAL to the semantic value of
613 the lookahead token. This behavior is undocumented and Bison
614 users should not rely upon it. Assigning to YYVAL
615 unconditionally makes the parser a bit smaller, and it avoids a
616 GCC warning that YYVAL may be used uninitialized. */
617 yyval = yyvsp[1-yylen];
620 /* Similarly for the default location. Let the user run additional
621 commands if for instance locations are ranges. */
622 yyloc = yylsp[1-yylen];
623 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
627 /* We have to keep this `#if YYDEBUG', since we use variables which
628 are defined only if `YYDEBUG' is set. */
633 fprintf (stderr, "Reducing via rule %d (line %d), ",
636 /* Print the symbols being reduced, and their result. */
637 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
638 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
639 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
642 %% actions /* The action file replaces this line. */
654 short *ssp1 = yyss - 1;
655 fprintf (stderr, "state stack now");
656 while (ssp1 != yyssp)
657 fprintf (stderr, " %d", *++ssp1);
658 fprintf (stderr, "\n");
667 /* Now `shift' the result of the reduction. Determine what state
668 that goes to, based on the state we popped back to and the rule
669 number reduced by. */
673 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
674 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
675 yystate = yytable[yystate];
677 yystate = yydefgoto[yyn - YYNTBASE];
682 /*------------------------------------.
683 | yyerrlab -- here on detecting error |
684 `------------------------------------*/
686 /* If not already recovering from an error, report this error. */
691 #ifdef YYERROR_VERBOSE
692 yyn = yypact[yystate];
694 if (yyn > YYFLAG && yyn < YYLAST)
701 /* Start X at -YYN if negative to avoid negative indexes in
703 for (x = yyn < 0 ? -yyn : 0;
704 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
705 if (yycheck[x + yyn] == x)
706 size += strlen (yytname[x]) + 15, count++;
707 size += strlen ("parse error, unexpected ") + 1;
708 size += strlen (yytname[YYTRANSLATE (yychar)]);
709 msg = (char *) malloc (size);
712 strcpy (msg, "parse error, unexpected ");
713 strcat (msg, yytname[YYTRANSLATE (yychar)]);
718 for (x = yyn < 0 ? -yyn : 0;
719 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
720 if (yycheck[x + yyn] == x)
722 strcat (msg, count == 0 ? ", expecting " : " or ");
723 strcat (msg, yytname[x]);
731 yyerror ("parse error; also virtual memory exhausted");
734 #endif /* YYERROR_VERBOSE */
735 yyerror ("parse error");
740 /*--------------------------------------------------.
741 | yyerrlab1 -- error raised explicitly by an action |
742 `--------------------------------------------------*/
744 if (yyerrstatus == 3)
746 /* If just tried and failed to reuse lookahead token after an
747 error, discard it. */
749 /* return failure if at end of input */
752 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
753 yychar, yytname[yychar1]));
757 /* Else will try to reuse lookahead token after shifting the error
760 yyerrstatus = 3; /* Each real token shifted decrements this */
765 /*-------------------------------------------------------------------.
766 | yyerrdefault -- current state does not do anything special for the |
768 `-------------------------------------------------------------------*/
771 /* This is wrong; only states that explicitly want error tokens
772 should shift them. */
774 /* If its default is to accept any token, ok. Otherwise pop it. */
775 yyn = yydefact[yystate];
781 /*---------------------------------------------------------------.
782 | yyerrpop -- pop the current state because it cannot handle the |
784 `---------------------------------------------------------------*/
797 short *ssp1 = yyss - 1;
798 fprintf (stderr, "Error: state stack now");
799 while (ssp1 != yyssp)
800 fprintf (stderr, " %d", *++ssp1);
801 fprintf (stderr, "\n");
809 yyn = yypact[yystate];
814 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
831 YYDPRINTF ((stderr, "Shifting error token, "));
842 /*-------------------------------------.
843 | yyacceptlab -- YYACCEPT comes here. |
844 `-------------------------------------*/
849 /*-----------------------------------.
850 | yyabortlab -- YYABORT comes here. |
851 `-----------------------------------*/
856 /*---------------------------------------------.
857 | yyoverflowab -- parser overflow comes here. |
858 `---------------------------------------------*/
860 yyerror ("parser stack overflow");