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 #if YYSTACK_USE_ALLOCA
76 # define YYSTACK_ALLOC alloca
78 # define YYSTACK_ALLOC malloc
81 #define yyerrok (yyerrstatus = 0)
82 #define yyclearin (yychar = YYEMPTY)
85 #define YYACCEPT goto yyacceptlab
86 #define YYABORT goto yyabortlab
87 #define YYERROR goto yyerrlab1
88 /* Like YYERROR except do call yyerror. This remains here temporarily
89 to ease the transition to the new meaning of YYERROR, for GCC.
90 Once GCC version 2 has supplanted version 1, this can go. */
91 #define YYFAIL goto yyerrlab
92 #define YYRECOVERING() (!!yyerrstatus)
93 #define YYBACKUP(Token, Value) \
95 if (yychar == YYEMPTY && yylen == 1) \
99 yychar1 = YYTRANSLATE (yychar); \
105 yyerror ("syntax error: cannot back up"); \
111 #define YYERRCODE 256
114 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
117 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
118 first token. By default, to implement support for ranges, extend
119 its range to the last symbol. */
121 #ifndef YYLLOC_DEFAULT
122 # define YYLLOC_DEFAULT(Current, Rhs, N) \
123 Current.last_line = Rhs[N].last_line; \
124 Current.last_column = Rhs[N].last_column;
128 /* YYLEX -- calling `yylex' with the right arguments. */
133 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
135 # define YYLEX yylex (&yylval, &yylloc)
137 # else /* !YYLSP_NEEDED */
139 # define YYLEX yylex (&yylval, YYLEX_PARAM)
141 # define YYLEX yylex (&yylval)
143 # endif /* !YYLSP_NEEDED */
145 # define YYLEX yylex ()
149 /* Enable debugging if requested. */
151 # define YYDPRINTF(Args) \
156 /* Nonzero means print parse trace. [The following comment makes no
157 sense to me. Could someone clarify it? --akim] Since this is
158 uninitialized, it does not stop multiple parsers from coexisting.
162 # define YYDPRINTF(Args)
163 #endif /* !YYDEBUG */
165 /* YYINITDEPTH -- initial size of the parser's stacks. */
167 # define YYINITDEPTH 200
170 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
171 if the built-in stack extension method is used). */
177 # define YYMAXDEPTH 10000
180 /* Define __yy_memcpy. Note that the size argument
181 should be passed with type unsigned int, because that is what the non-GCC
182 definitions require. With GCC, __builtin_memcpy takes an arg
183 of type size_t, but it can handle unsigned int. */
185 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
186 # define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
187 #else /* not GNU C or C++ */
189 /* This is the most reliable way to avoid incompatibilities
190 in available built-in functions on various systems. */
193 __yy_memcpy (to, from, count)
197 # else /* __cplusplus */
198 __yy_memcpy (char *to, const char *from, unsigned int count)
201 register const char *f = from;
202 register char *t = to;
203 register int i = count;
213 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
214 into yyparse. The argument should have type void *.
215 It should actually point to an object.
216 Grammar actions can access the variable by casting it
217 to the proper pointer type. */
221 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
222 # define YYPARSE_PARAM_DECL
223 # else /* !__cplusplus */
224 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
225 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
226 # endif /* !__cplusplus */
227 #else /* !YYPARSE_PARAM */
228 # define YYPARSE_PARAM_ARG
229 # define YYPARSE_PARAM_DECL
230 #endif /* !YYPARSE_PARAM */
232 /* Prevent warning if -Wstrict-prototypes. */
234 # ifdef YYPARSE_PARAM
235 int yyparse (void *);
241 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
242 variables are global, or local to YYPARSE. */
244 #define _YY_DECL_VARIABLES \
245 /* The lookahead symbol. */ \
248 /* The semantic value of the lookahead symbol. */ \
251 /* Number of parse errors so far. */ \
255 # define YY_DECL_VARIABLES \
258 /* Location data for the lookahead symbol. */ \
261 # define YY_DECL_VARIABLES \
266 /* If nonreentrant, generate the variables here. */
273 yyparse (YYPARSE_PARAM_ARG)
276 /* If reentrant, generate the variables here. */
281 register int yystate;
283 /* Number of tokens to shift before error messages enabled. */
285 /* Lookahead token as an internal (translated) token number. */
288 /* Three stacks and their tools:
289 `yyss': related to states,
290 `yysv': related to semantic values,
291 `yyls': related to locations.
293 Refer to the stacks thru separate pointers, to allow yyoverflow
294 to reallocate them elsewhere. */
296 /* The state stack. */
297 short yyssa[YYINITDEPTH];
299 register short *yyssp;
301 /* The semantic value stack. */
302 YYSTYPE yyvsa[YYINITDEPTH];
303 YYSTYPE *yyvs = yyvsa;
304 register YYSTYPE *yyvsp;
307 /* The location stack. */
308 YYLTYPE yylsa[YYINITDEPTH];
309 YYLTYPE *yyls = yylsa;
314 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
316 # define YYPOPSTACK (yyvsp--, yyssp--)
319 int yystacksize = YYINITDEPTH;
320 int yyfree_stacks = 0;
323 /* The variables used to return semantic value and location from the
330 /* When reducing, the number of symbols on the RHS of the reduced
334 YYDPRINTF ((stderr, "Starting parse\n"));
339 yychar = YYEMPTY; /* Cause a token to be read. */
341 /* Initialize stack pointers.
342 Waste one element of value and location stack
343 so that they stay on the same level as the state stack.
344 The wasted elements are never initialized. */
353 /*------------------------------------------------------------.
354 | yynewstate -- Push a new state, which is found in yystate. |
355 `------------------------------------------------------------*/
357 /* In all cases, when you get here, the value and location stacks
358 have just been pushed. so pushing a state here evens the stacks.
362 if (yyssp >= yyss + yystacksize - 1)
364 /* Give user a chance to reallocate the stack. Use copies of
365 these so that the &'s don't force the real ones into memory.
367 YYSTYPE *yyvs1 = yyvs;
370 YYLTYPE *yyls1 = yyls;
373 /* Get the current used size of the three stacks, in elements. */
374 int size = yyssp - yyss + 1;
377 /* Each stack pointer address is followed by the size of the
378 data in use in that stack, in bytes. */
380 /* This used to be a conditional around just the two extra args,
381 but that might be undefined if yyoverflow is a macro. */
382 yyoverflow ("parser stack overflow",
383 &yyss1, size * sizeof (*yyssp),
384 &yyvs1, size * sizeof (*yyvsp),
385 &yyls1, size * sizeof (*yylsp),
388 yyoverflow ("parser stack overflow",
389 &yyss1, size * sizeof (*yyssp),
390 &yyvs1, size * sizeof (*yyvsp),
394 yyss = yyss1; yyvs = yyvs1;
398 #else /* no yyoverflow */
399 /* Extend the stack our own way. */
400 if (yystacksize >= YYMAXDEPTH)
402 yyerror ("parser stack overflow");
414 if (yystacksize > YYMAXDEPTH)
415 yystacksize = YYMAXDEPTH;
416 # ifndef YYSTACK_USE_ALLOCA
419 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
420 __yy_memcpy ((char *)yyss, (char *)yyss1,
421 size * (unsigned int) sizeof (*yyssp));
422 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
423 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
424 size * (unsigned int) sizeof (*yyvsp));
426 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
427 __yy_memcpy ((char *)yyls, (char *)yyls1,
428 size * (unsigned int) sizeof (*yylsp));
430 #endif /* no yyoverflow */
432 yyssp = yyss + size - 1;
433 yyvsp = yyvs + size - 1;
435 yylsp = yyls + size - 1;
438 YYDPRINTF ((stderr, "Stack size increased to %d\n", yystacksize));
440 if (yyssp >= yyss + yystacksize - 1)
444 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
454 /* Do appropriate processing given the current state. */
455 /* Read a lookahead token if we need one and don't already have one. */
458 /* First try to decide what to do without reference to lookahead token. */
460 yyn = yypact[yystate];
464 /* Not known => get a lookahead token if don't already have one. */
466 /* yychar is either YYEMPTY or YYEOF
467 or a valid token in external form. */
469 if (yychar == YYEMPTY)
471 YYDPRINTF ((stderr, "Reading a token: "));
475 /* Convert token to internal form (in yychar1) for indexing tables with */
477 if (yychar <= 0) /* This means end of input. */
480 yychar = YYEOF; /* Don't call YYLEX any more */
482 YYDPRINTF ((stderr, "Now at end of input.\n"));
486 yychar1 = YYTRANSLATE (yychar);
489 /* We have to keep this `#if YYDEBUG', since we use variables
490 which are defined only if `YYDEBUG' is set. */
493 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
494 /* Give the individual parser a way to print the precise
495 meaning of a token, for further debugging info. */
497 YYPRINT (stderr, yychar, yylval);
499 fprintf (stderr, ")\n");
505 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
510 /* yyn is what to do for this token type in this state.
511 Negative => reduce, -yyn is rule number.
512 Positive => shift, yyn is new state.
513 New state is final state => don't bother to shift,
515 0, or most negative number => error. */
530 /* Shift the lookahead token. */
531 YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]));
533 /* Discard the token being shifted unless it is eof. */
542 /* Count tokens shifted since error; after three, turn off error
551 /*-----------------------------------------------------------.
552 | yydefault -- do the default action for the current state. |
553 `-----------------------------------------------------------*/
555 yyn = yydefact[yystate];
561 /*-----------------------------.
562 | yyreduce -- Do a reduction. |
563 `-----------------------------*/
565 /* yyn is the number of a rule to reduce with. */
568 /* If YYLEN is nonzero, implement the default value of the action:
571 Otherwise, the following line sets YYVAL to the semantic value of
572 the lookahead token. This behavior is undocumented and Bison
573 users should not rely upon it. Assigning to YYVAL
574 unconditionally makes the parser a bit smaller, and it avoids a
575 GCC warning that YYVAL may be used uninitialized. */
576 yyval = yyvsp[1-yylen];
579 /* Similarly for the default location. Let the user run additional
580 commands if for instance locations are ranges. */
581 yyloc = yylsp[1-yylen];
582 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
586 /* We have to keep this `#if YYDEBUG', since we use variables which
587 are defined only if `YYDEBUG' is set. */
592 fprintf (stderr, "Reducing via rule %d (line %d), ",
595 /* Print the symbols being reduced, and their result. */
596 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
597 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
598 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
601 %% actions /* The action file replaces this line. */
613 short *ssp1 = yyss - 1;
614 fprintf (stderr, "state stack now");
615 while (ssp1 != yyssp)
616 fprintf (stderr, " %d", *++ssp1);
617 fprintf (stderr, "\n");
626 /* Now `shift' the result of the reduction. Determine what state
627 that goes to, based on the state we popped back to and the rule
628 number reduced by. */
632 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
633 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
634 yystate = yytable[yystate];
636 yystate = yydefgoto[yyn - YYNTBASE];
641 /*------------------------------------.
642 | yyerrlab -- here on detecting error |
643 `------------------------------------*/
645 /* If not already recovering from an error, report this error. */
650 #ifdef YYERROR_VERBOSE
651 yyn = yypact[yystate];
653 if (yyn > YYFLAG && yyn < YYLAST)
660 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
661 for (x = (yyn < 0 ? -yyn : 0);
662 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
663 if (yycheck[x + yyn] == x)
664 size += strlen (yytname[x]) + 15, count++;
665 size += strlen ("parse error, unexpected `") + 1;
666 size += strlen (yytname[YYTRANSLATE (yychar)]);
667 msg = (char *) malloc (size);
670 strcpy (msg, "parse error, unexpected `");
671 strcat (msg, yytname[YYTRANSLATE (yychar)]);
677 for (x = (yyn < 0 ? -yyn : 0);
678 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
679 if (yycheck[x + yyn] == x)
681 strcat (msg, count == 0 ? ", expecting `" : " or `");
682 strcat (msg, yytname[x]);
691 yyerror ("parse error; also virtual memory exceeded");
694 #endif /* YYERROR_VERBOSE */
695 yyerror ("parse error");
700 /*--------------------------------------------------.
701 | yyerrlab1 -- error raised explicitly by an action |
702 `--------------------------------------------------*/
704 if (yyerrstatus == 3)
706 /* If just tried and failed to reuse lookahead token after an
707 error, discard it. */
709 /* return failure if at end of input */
712 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
713 yychar, yytname[yychar1]));
717 /* Else will try to reuse lookahead token after shifting the error
720 yyerrstatus = 3; /* Each real token shifted decrements this */
725 /*-------------------------------------------------------------------.
726 | yyerrdefault -- current state does not do anything special for the |
728 `-------------------------------------------------------------------*/
731 /* This is wrong; only states that explicitly want error tokens
732 should shift them. */
734 /* If its default is to accept any token, ok. Otherwise pop it. */
735 yyn = yydefact[yystate];
741 /*---------------------------------------------------------------.
742 | yyerrpop -- pop the current state because it cannot handle the |
744 `---------------------------------------------------------------*/
757 short *ssp1 = yyss - 1;
758 fprintf (stderr, "Error: state stack now");
759 while (ssp1 != yyssp)
760 fprintf (stderr, " %d", *++ssp1);
761 fprintf (stderr, "\n");
769 yyn = yypact[yystate];
774 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
791 YYDPRINTF ((stderr, "Shifting error token, "));
802 /*-------------------------------------.
803 | yyacceptlab -- YYACCEPT comes here. |
804 `-------------------------------------*/
817 /*-----------------------------------.
818 | yyabortlab -- YYABORT comes here. |
819 `-----------------------------------*/