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 /* Realloc WHAT from SIZE to YYSTACKSIZE elements of TYPE.
80 If WHAT was malloc'ed (not the original automatic ARRAY), free it. */
81 #if YYSTACK_USE_ALLOCA
82 # define YYSTACK_REALLOC(Type, What, Array) \
85 What = (Type *) malloc (yystacksize * sizeof (Type)); \
86 __yy_memcpy ((char *) What, (char *) old, \
87 (size) * (unsigned int) sizeof (Type)); \
93 # define YYSTACK_REALLOC(Type, What, Array) \
96 What = (Type *) alloca (yystacksize * sizeof (Type)); \
97 __yy_memcpy ((char *) What, (char *) old, \
98 (size) * (unsigned int) sizeof (Type)); \
102 #define yyerrok (yyerrstatus = 0)
103 #define yyclearin (yychar = YYEMPTY)
106 #define YYACCEPT goto yyacceptlab
107 #define YYABORT goto yyabortlab
108 #define YYERROR goto yyerrlab1
109 /* Like YYERROR except do call yyerror. This remains here temporarily
110 to ease the transition to the new meaning of YYERROR, for GCC.
111 Once GCC version 2 has supplanted version 1, this can go. */
112 #define YYFAIL goto yyerrlab
113 #define YYRECOVERING() (!!yyerrstatus)
114 #define YYBACKUP(Token, Value) \
116 if (yychar == YYEMPTY && yylen == 1) \
120 yychar1 = YYTRANSLATE (yychar); \
126 yyerror ("syntax error: cannot back up"); \
132 #define YYERRCODE 256
135 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
138 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
139 first token. By default, to implement support for ranges, extend
140 its range to the last symbol. */
142 #ifndef YYLLOC_DEFAULT
143 # define YYLLOC_DEFAULT(Current, Rhs, N) \
144 Current.last_line = Rhs[N].last_line; \
145 Current.last_column = Rhs[N].last_column;
149 /* YYLEX -- calling `yylex' with the right arguments. */
154 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
156 # define YYLEX yylex (&yylval, &yylloc)
158 # else /* !YYLSP_NEEDED */
160 # define YYLEX yylex (&yylval, YYLEX_PARAM)
162 # define YYLEX yylex (&yylval)
164 # endif /* !YYLSP_NEEDED */
166 # define YYLEX yylex ()
170 /* Enable debugging if requested. */
172 # define YYDPRINTF(Args) \
177 /* Nonzero means print parse trace. [The following comment makes no
178 sense to me. Could someone clarify it? --akim] Since this is
179 uninitialized, it does not stop multiple parsers from coexisting.
183 # define YYDPRINTF(Args)
184 #endif /* !YYDEBUG */
186 /* YYINITDEPTH -- initial size of the parser's stacks. */
188 # define YYINITDEPTH 200
191 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
192 if the built-in stack extension method is used). */
198 # define YYMAXDEPTH 10000
201 /* Define __yy_memcpy. Note that the size argument
202 should be passed with type unsigned int, because that is what the non-GCC
203 definitions require. With GCC, __builtin_memcpy takes an arg
204 of type size_t, but it can handle unsigned int. */
206 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
207 # define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
208 #else /* not GNU C or C++ */
210 /* This is the most reliable way to avoid incompatibilities
211 in available built-in functions on various systems. */
214 __yy_memcpy (to, from, count)
218 # else /* __cplusplus */
219 __yy_memcpy (char *to, const char *from, unsigned int count)
222 register const char *f = from;
223 register char *t = to;
224 register int i = count;
234 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
235 into yyparse. The argument should have type void *.
236 It should actually point to an object.
237 Grammar actions can access the variable by casting it
238 to the proper pointer type. */
242 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
243 # define YYPARSE_PARAM_DECL
244 # else /* !__cplusplus */
245 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
246 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
247 # endif /* !__cplusplus */
248 #else /* !YYPARSE_PARAM */
249 # define YYPARSE_PARAM_ARG
250 # define YYPARSE_PARAM_DECL
251 #endif /* !YYPARSE_PARAM */
253 /* Prevent warning if -Wstrict-prototypes. */
255 # ifdef YYPARSE_PARAM
256 int yyparse (void *);
262 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
263 variables are global, or local to YYPARSE. */
265 #define _YY_DECL_VARIABLES \
266 /* The lookahead symbol. */ \
269 /* The semantic value of the lookahead symbol. */ \
272 /* Number of parse errors so far. */ \
276 # define YY_DECL_VARIABLES \
279 /* Location data for the lookahead symbol. */ \
282 # define YY_DECL_VARIABLES \
287 /* If nonreentrant, generate the variables here. */
294 yyparse (YYPARSE_PARAM_ARG)
297 /* If reentrant, generate the variables here. */
302 register int yystate;
304 /* Number of tokens to shift before error messages enabled. */
306 /* Lookahead token as an internal (translated) token number. */
309 /* Three stacks and their tools:
310 `yyss': related to states,
311 `yyvs': related to semantic values,
312 `yyls': related to locations.
314 Refer to the stacks thru separate pointers, to allow yyoverflow
315 to reallocate them elsewhere. */
317 /* The state stack. */
318 short yyssa[YYINITDEPTH];
320 register short *yyssp;
322 /* The semantic value stack. */
323 YYSTYPE yyvsa[YYINITDEPTH];
324 YYSTYPE *yyvs = yyvsa;
325 register YYSTYPE *yyvsp;
328 /* The location stack. */
329 YYLTYPE yylsa[YYINITDEPTH];
330 YYLTYPE *yyls = yylsa;
335 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
337 # define YYPOPSTACK (yyvsp--, yyssp--)
340 int yystacksize = YYINITDEPTH;
341 int yyfree_stacks = 0;
344 /* The variables used to return semantic value and location from the
351 /* When reducing, the number of symbols on the RHS of the reduced
355 YYDPRINTF ((stderr, "Starting parse\n"));
360 yychar = YYEMPTY; /* Cause a token to be read. */
362 /* Initialize stack pointers.
363 Waste one element of value and location stack
364 so that they stay on the same level as the state stack.
365 The wasted elements are never initialized. */
374 /*------------------------------------------------------------.
375 | yynewstate -- Push a new state, which is found in yystate. |
376 `------------------------------------------------------------*/
378 /* In all cases, when you get here, the value and location stacks
379 have just been pushed. so pushing a state here evens the stacks.
386 if (yyssp >= yyss + yystacksize - 1)
388 /* Get the current used size of the three stacks, in elements. */
389 int size = yyssp - yyss + 1;
393 /* Give user a chance to reallocate the stack. Use copies of
394 these so that the &'s don't force the real ones into
396 YYSTYPE *yyvs1 = yyvs;
399 /* Each stack pointer address is followed by the size of the
400 data in use in that stack, in bytes. */
402 YYLTYPE *yyls1 = yyls;
403 /* This used to be a conditional around just the two extra args,
404 but that might be undefined if yyoverflow is a macro. */
405 yyoverflow ("parser stack overflow",
406 &yyss1, size * sizeof (*yyssp),
407 &yyvs1, size * sizeof (*yyvsp),
408 &yyls1, size * sizeof (*yylsp),
412 yyoverflow ("parser stack overflow",
413 &yyss1, size * sizeof (*yyssp),
414 &yyvs1, size * sizeof (*yyvsp),
420 #else /* no yyoverflow */
421 /* Extend the stack our own way. */
422 if (yystacksize >= YYMAXDEPTH)
424 yyerror ("parser stack overflow");
436 if (yystacksize > YYMAXDEPTH)
437 yystacksize = YYMAXDEPTH;
439 YYSTACK_REALLOC (short, yyss, yyssa);
440 YYSTACK_REALLOC (YYSTYPE, yyvs, yyvsa);
442 YYSTACK_REALLOC (YYLTYPE, yyls, yylsa);
444 #endif /* no yyoverflow */
446 yyssp = yyss + size - 1;
447 yyvsp = yyvs + size - 1;
449 yylsp = yyls + size - 1;
452 YYDPRINTF ((stderr, "Stack size increased to %d\n", yystacksize));
454 if (yyssp >= yyss + yystacksize - 1)
458 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
468 /* Do appropriate processing given the current state. */
469 /* Read a lookahead token if we need one and don't already have one. */
472 /* First try to decide what to do without reference to lookahead token. */
474 yyn = yypact[yystate];
478 /* Not known => get a lookahead token if don't already have one. */
480 /* yychar is either YYEMPTY or YYEOF
481 or a valid token in external form. */
483 if (yychar == YYEMPTY)
485 YYDPRINTF ((stderr, "Reading a token: "));
489 /* Convert token to internal form (in yychar1) for indexing tables with */
491 if (yychar <= 0) /* This means end of input. */
494 yychar = YYEOF; /* Don't call YYLEX any more */
496 YYDPRINTF ((stderr, "Now at end of input.\n"));
500 yychar1 = YYTRANSLATE (yychar);
503 /* We have to keep this `#if YYDEBUG', since we use variables
504 which are defined only if `YYDEBUG' is set. */
507 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
508 /* Give the individual parser a way to print the precise
509 meaning of a token, for further debugging info. */
511 YYPRINT (stderr, yychar, yylval);
513 fprintf (stderr, ")\n");
519 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
524 /* yyn is what to do for this token type in this state.
525 Negative => reduce, -yyn is rule number.
526 Positive => shift, yyn is new state.
527 New state is final state => don't bother to shift,
529 0, or most negative number => error. */
544 /* Shift the lookahead token. */
545 YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]));
547 /* Discard the token being shifted unless it is eof. */
556 /* Count tokens shifted since error; after three, turn off error
565 /*-----------------------------------------------------------.
566 | yydefault -- do the default action for the current state. |
567 `-----------------------------------------------------------*/
569 yyn = yydefact[yystate];
575 /*-----------------------------.
576 | yyreduce -- Do a reduction. |
577 `-----------------------------*/
579 /* yyn is the number of a rule to reduce with. */
582 /* If YYLEN is nonzero, implement the default value of the action:
585 Otherwise, the following line sets YYVAL to the semantic value of
586 the lookahead token. This behavior is undocumented and Bison
587 users should not rely upon it. Assigning to YYVAL
588 unconditionally makes the parser a bit smaller, and it avoids a
589 GCC warning that YYVAL may be used uninitialized. */
590 yyval = yyvsp[1-yylen];
593 /* Similarly for the default location. Let the user run additional
594 commands if for instance locations are ranges. */
595 yyloc = yylsp[1-yylen];
596 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
600 /* We have to keep this `#if YYDEBUG', since we use variables which
601 are defined only if `YYDEBUG' is set. */
606 fprintf (stderr, "Reducing via rule %d (line %d), ",
609 /* Print the symbols being reduced, and their result. */
610 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
611 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
612 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
615 %% actions /* The action file replaces this line. */
627 short *ssp1 = yyss - 1;
628 fprintf (stderr, "state stack now");
629 while (ssp1 != yyssp)
630 fprintf (stderr, " %d", *++ssp1);
631 fprintf (stderr, "\n");
640 /* Now `shift' the result of the reduction. Determine what state
641 that goes to, based on the state we popped back to and the rule
642 number reduced by. */
646 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
647 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
648 yystate = yytable[yystate];
650 yystate = yydefgoto[yyn - YYNTBASE];
655 /*------------------------------------.
656 | yyerrlab -- here on detecting error |
657 `------------------------------------*/
659 /* If not already recovering from an error, report this error. */
664 #ifdef YYERROR_VERBOSE
665 yyn = yypact[yystate];
667 if (yyn > YYFLAG && yyn < YYLAST)
674 /* Start X at -YYN if negative to avoid negative indexes in
676 for (x = yyn < 0 ? -yyn : 0;
677 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
678 if (yycheck[x + yyn] == x)
679 size += strlen (yytname[x]) + 15, count++;
680 size += strlen ("parse error, unexpected ") + 1;
681 size += strlen (yytname[YYTRANSLATE (yychar)]);
682 msg = (char *) malloc (size);
685 strcpy (msg, "parse error, unexpected ");
686 strcat (msg, yytname[YYTRANSLATE (yychar)]);
691 for (x = yyn < 0 ? -yyn : 0;
692 x < (int) (sizeof (yytname) / sizeof (char *)); x++)
693 if (yycheck[x + yyn] == x)
695 strcat (msg, count == 0 ? ", expecting " : " or ");
696 strcat (msg, yytname[x]);
704 yyerror ("parse error; also virtual memory exhausted");
707 #endif /* YYERROR_VERBOSE */
708 yyerror ("parse error");
713 /*--------------------------------------------------.
714 | yyerrlab1 -- error raised explicitly by an action |
715 `--------------------------------------------------*/
717 if (yyerrstatus == 3)
719 /* If just tried and failed to reuse lookahead token after an
720 error, discard it. */
722 /* return failure if at end of input */
725 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
726 yychar, yytname[yychar1]));
730 /* Else will try to reuse lookahead token after shifting the error
733 yyerrstatus = 3; /* Each real token shifted decrements this */
738 /*-------------------------------------------------------------------.
739 | yyerrdefault -- current state does not do anything special for the |
741 `-------------------------------------------------------------------*/
744 /* This is wrong; only states that explicitly want error tokens
745 should shift them. */
747 /* If its default is to accept any token, ok. Otherwise pop it. */
748 yyn = yydefact[yystate];
754 /*---------------------------------------------------------------.
755 | yyerrpop -- pop the current state because it cannot handle the |
757 `---------------------------------------------------------------*/
770 short *ssp1 = yyss - 1;
771 fprintf (stderr, "Error: state stack now");
772 while (ssp1 != yyssp)
773 fprintf (stderr, " %d", *++ssp1);
774 fprintf (stderr, "\n");
782 yyn = yypact[yystate];
787 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
804 YYDPRINTF ((stderr, "Shifting error token, "));
815 /*-------------------------------------.
816 | yyacceptlab -- YYACCEPT comes here. |
817 `-------------------------------------*/
830 /*-----------------------------------.
831 | yyabortlab -- YYABORT comes here. |
832 `-----------------------------------*/