1 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
4 /* Skeleton output parser for bison,
5 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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
27 when 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
34 #else /* alloca not defined */
36 #define YYSTACK_USE_ALLOCA
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
43 /* We think this test detects Watcom and Microsoft C. */
44 /* This used to test MSDOS, but that is a bad idea
45 since that symbol is in the user namespace. */
46 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
47 #if 0 /* No need for malloc.h, which pollutes the namespace;
48 instead, just don't use alloca. */
51 #else /* not MSDOS, or __TURBOC__ */
53 /* I don't know what this was needed for, but it pollutes the namespace.
54 So I turned it off. rms, 2 May 1997. */
55 /* #include <malloc.h> */
57 #define YYSTACK_USE_ALLOCA
58 #else /* not MSDOS, or __TURBOC__, or _AIX */
60 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
61 and on HPUX 10. Eventually we can turn this on. */
62 #define YYSTACK_USE_ALLOCA
63 #define alloca __builtin_alloca
67 #endif /* not MSDOS, or __TURBOC__ */
68 #endif /* not sparc */
69 #endif /* not GNU C */
70 #endif /* alloca not defined */
71 #endif /* YYSTACK_USE_ALLOCA not defined */
73 #ifdef YYSTACK_USE_ALLOCA
74 #define YYSTACK_ALLOC alloca
76 #define YYSTACK_ALLOC malloc
79 /* Note: there must be only one dollar sign in this file.
80 It is replaced by the list of actions, each action
81 as one case of the switch. */
83 #define yyerrok (yyerrstatus = 0)
84 #define yyclearin (yychar = YYEMPTY)
87 #define YYACCEPT goto yyacceptlab
88 #define YYABORT goto yyabortlab
89 #define YYERROR goto yyerrlab1
90 /* Like YYERROR except do call yyerror.
91 This remains here temporarily to ease the
92 transition to the new meaning of YYERROR, for GCC.
93 Once GCC version 2 has supplanted version 1, this can go. */
94 #define YYFAIL goto yyerrlab
95 #define YYRECOVERING() (!!yyerrstatus)
96 #define YYBACKUP(token, value) \
98 if (yychar == YYEMPTY && yylen == 1) \
99 { yychar = (token), yylval = (value); \
100 yychar1 = YYTRANSLATE (yychar); \
105 { yyerror ("syntax error: cannot back up"); YYERROR; } \
109 #define YYERRCODE 256
112 #define YYLEX yylex()
118 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
120 #define YYLEX yylex(&yylval, &yylloc)
122 #else /* not YYLSP_NEEDED */
124 #define YYLEX yylex(&yylval, YYLEX_PARAM)
126 #define YYLEX yylex(&yylval)
128 #endif /* not YYLSP_NEEDED */
131 /* If nonreentrant, generate the variables here */
135 int yychar; /* the lookahead symbol */
136 YYSTYPE yylval; /* the semantic value of the */
137 /* lookahead symbol */
140 YYLTYPE yylloc; /* location data for the lookahead */
144 int yynerrs; /* number of parse errors so far */
145 #endif /* not YYPURE */
148 int yydebug; /* nonzero means print parse trace */
149 /* Since this is uninitialized, it does not stop multiple parsers
153 /* YYINITDEPTH indicates the initial size of the parser's stacks */
156 #define YYINITDEPTH 200
159 /* YYMAXDEPTH is the maximum size the stacks can grow to
160 (effective only if the built-in stack extension method is used). */
167 #define YYMAXDEPTH 10000
170 /* Define __yy_memcpy. Note that the size argument
171 should be passed with type unsigned int, because that is what the non-GCC
172 definitions require. With GCC, __builtin_memcpy takes an arg
173 of type size_t, but it can handle unsigned int. */
175 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
176 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
177 #else /* not GNU C or C++ */
180 /* This is the most reliable way to avoid incompatibilities
181 in available built-in functions on various systems. */
183 __yy_memcpy (to, from, count)
188 register char *f = from;
189 register char *t = to;
190 register int i = count;
196 #else /* __cplusplus */
198 /* This is the most reliable way to avoid incompatibilities
199 in available built-in functions on various systems. */
201 __yy_memcpy (char *to, char *from, unsigned int count)
203 register char *t = to;
204 register char *f = from;
205 register int i = count;
214 #line 215 "bison.simple"
216 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
217 into yyparse. The argument should have type void *.
218 It should actually point to an object.
219 Grammar actions can access the variable by casting it
220 to the proper pointer type. */
224 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
225 #define YYPARSE_PARAM_DECL
226 #else /* not __cplusplus */
227 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
228 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
229 #endif /* not __cplusplus */
230 #else /* not YYPARSE_PARAM */
231 #define YYPARSE_PARAM_ARG
232 #define YYPARSE_PARAM_DECL
233 #endif /* not YYPARSE_PARAM */
235 /* Prevent warning if -Wstrict-prototypes. */
238 int yyparse (void *);
245 yyparse(YYPARSE_PARAM_ARG)
248 register int yystate;
250 register short *yyssp;
251 register YYSTYPE *yyvsp;
252 int yyerrstatus; /* number of tokens to shift before error messages enabled */
253 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
255 short yyssa[YYINITDEPTH]; /* the state stack */
256 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
258 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
259 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
262 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
263 YYLTYPE *yyls = yylsa;
266 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
268 #define YYPOPSTACK (yyvsp--, yyssp--)
271 int yystacksize = YYINITDEPTH;
272 int yyfree_stacks = 0;
283 YYSTYPE yyval; /* the variable used to return */
284 /* semantic values from the action */
291 fprintf(stderr, "Starting parse\n");
297 yychar = YYEMPTY; /* Cause a token to be read. */
299 /* Initialize stack pointers.
300 Waste one element of value and location stack
301 so that they stay on the same level as the state stack.
302 The wasted elements are never initialized. */
310 /* Push a new state, which is found in yystate . */
311 /* In all cases, when you get here, the value and location stacks
312 have just been pushed. so pushing a state here evens the stacks. */
317 if (yyssp >= yyss + yystacksize - 1)
319 /* Give user a chance to reallocate the stack */
320 /* Use copies of these so that the &'s don't force the real ones into memory. */
321 YYSTYPE *yyvs1 = yyvs;
324 YYLTYPE *yyls1 = yyls;
327 /* Get the current used size of the three stacks, in elements. */
328 int size = yyssp - yyss + 1;
331 /* Each stack pointer address is followed by the size of
332 the data in use in that stack, in bytes. */
334 /* This used to be a conditional around just the two extra args,
335 but that might be undefined if yyoverflow is a macro. */
336 yyoverflow("parser stack overflow",
337 &yyss1, size * sizeof (*yyssp),
338 &yyvs1, size * sizeof (*yyvsp),
339 &yyls1, size * sizeof (*yylsp),
342 yyoverflow("parser stack overflow",
343 &yyss1, size * sizeof (*yyssp),
344 &yyvs1, size * sizeof (*yyvsp),
348 yyss = yyss1; yyvs = yyvs1;
352 #else /* no yyoverflow */
353 /* Extend the stack our own way. */
354 if (yystacksize >= YYMAXDEPTH)
356 yyerror("parser stack overflow");
368 if (yystacksize > YYMAXDEPTH)
369 yystacksize = YYMAXDEPTH;
370 #ifndef YYSTACK_USE_ALLOCA
373 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
374 __yy_memcpy ((char *)yyss, (char *)yyss1,
375 size * (unsigned int) sizeof (*yyssp));
376 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
377 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
378 size * (unsigned int) sizeof (*yyvsp));
380 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
381 __yy_memcpy ((char *)yyls, (char *)yyls1,
382 size * (unsigned int) sizeof (*yylsp));
384 #endif /* no yyoverflow */
386 yyssp = yyss + size - 1;
387 yyvsp = yyvs + size - 1;
389 yylsp = yyls + size - 1;
394 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
397 if (yyssp >= yyss + yystacksize - 1)
403 fprintf(stderr, "Entering state %d\n", yystate);
409 /* Do appropriate processing given the current state. */
410 /* Read a lookahead token if we need one and don't already have one. */
413 /* First try to decide what to do without reference to lookahead token. */
415 yyn = yypact[yystate];
419 /* Not known => get a lookahead token if don't already have one. */
421 /* yychar is either YYEMPTY or YYEOF
422 or a valid token in external form. */
424 if (yychar == YYEMPTY)
428 fprintf(stderr, "Reading a token: ");
433 /* Convert token to internal form (in yychar1) for indexing tables with */
435 if (yychar <= 0) /* This means end of input. */
438 yychar = YYEOF; /* Don't call YYLEX any more */
442 fprintf(stderr, "Now at end of input.\n");
447 yychar1 = YYTRANSLATE(yychar);
452 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
453 /* Give the individual parser a way to print the precise meaning
454 of a token, for further debugging info. */
456 YYPRINT (stderr, yychar, yylval);
458 fprintf (stderr, ")\n");
464 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
469 /* yyn is what to do for this token type in this state.
470 Negative => reduce, -yyn is rule number.
471 Positive => shift, yyn is new state.
472 New state is final state => don't bother to shift,
474 0, or most negative number => error. */
489 /* Shift the lookahead token. */
493 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
496 /* Discard the token being shifted unless it is eof. */
505 /* count tokens shifted since error; after three, turn off error status. */
506 if (yyerrstatus) yyerrstatus--;
511 /* Do the default action for the current state. */
514 yyn = yydefact[yystate];
518 /* Do a reduction. yyn is the number of a rule to reduce with. */
522 yyval = yyvsp[1-yylen]; /* implement default value of the action */
529 fprintf (stderr, "Reducing via rule %d (line %d), ",
532 /* Print the symbols being reduced, and their result. */
533 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
534 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
535 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
539 $ /* the action file gets copied in in place of this dollarsign */
540 #line 541 "bison.simple"
551 short *ssp1 = yyss - 1;
552 fprintf (stderr, "state stack now");
553 while (ssp1 != yyssp)
554 fprintf (stderr, " %d", *++ssp1);
555 fprintf (stderr, "\n");
565 yylsp->first_line = yylloc.first_line;
566 yylsp->first_column = yylloc.first_column;
567 yylsp->last_line = (yylsp-1)->last_line;
568 yylsp->last_column = (yylsp-1)->last_column;
573 yylsp->last_line = (yylsp+yylen-1)->last_line;
574 yylsp->last_column = (yylsp+yylen-1)->last_column;
578 /* Now "shift" the result of the reduction.
579 Determine what state that goes to,
580 based on the state we popped back to
581 and the rule number reduced by. */
585 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
586 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
587 yystate = yytable[yystate];
589 yystate = yydefgoto[yyn - YYNTBASE];
593 yyerrlab: /* here on detecting error */
596 /* If not already recovering from an error, report this error. */
600 #ifdef YYERROR_VERBOSE
601 yyn = yypact[yystate];
603 if (yyn > YYFLAG && yyn < YYLAST)
610 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
611 for (x = (yyn < 0 ? -yyn : 0);
612 x < (sizeof(yytname) / sizeof(char *)); x++)
613 if (yycheck[x + yyn] == x)
614 size += strlen(yytname[x]) + 15, count++;
615 msg = (char *) malloc(size + 15);
618 strcpy(msg, "parse error");
623 for (x = (yyn < 0 ? -yyn : 0);
624 x < (sizeof(yytname) / sizeof(char *)); x++)
625 if (yycheck[x + yyn] == x)
627 strcat(msg, count == 0 ? ", expecting `" : " or `");
628 strcat(msg, yytname[x]);
637 yyerror ("parse error; also virtual memory exceeded");
640 #endif /* YYERROR_VERBOSE */
641 yyerror("parse error");
645 yyerrlab1: /* here on error raised explicitly by an action */
647 if (yyerrstatus == 3)
649 /* if just tried and failed to reuse lookahead token after an error, discard it. */
651 /* return failure if at end of input */
657 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
663 /* Else will try to reuse lookahead token
664 after shifting the error token. */
666 yyerrstatus = 3; /* Each real token shifted decrements this */
670 yyerrdefault: /* current state does not do anything special for the error token. */
673 /* This is wrong; only states that explicitly want error tokens
674 should shift them. */
675 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
676 if (yyn) goto yydefault;
679 yyerrpop: /* pop the current state because it cannot handle the error token */
681 if (yyssp == yyss) YYABORT;
691 short *ssp1 = yyss - 1;
692 fprintf (stderr, "Error: state stack now");
693 while (ssp1 != yyssp)
694 fprintf (stderr, " %d", *++ssp1);
695 fprintf (stderr, "\n");
701 yyn = yypact[yystate];
706 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
725 fprintf(stderr, "Shifting error token, ");
737 /* YYACCEPT comes here. */
749 /* YYABORT comes here. */