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. */
33 #define alloca __builtin_alloca
34 #else /* not GNU C. */
35 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
38 /* This used to test MSDOS, but that is a bad idea
39 since that is in the user namespace. */
40 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
42 #else /* not MSDOS, or __TURBOC__ */
46 #else /* not MSDOS, or __TURBOC__, or _AIX */
50 void *alloca (unsigned int);
52 #else /* not __cplusplus */
54 #endif /* not __cplusplus */
57 #endif /* not MSDOS, or __TURBOC__ */
58 #endif /* not sparc. */
59 #endif /* not GNU C. */
60 #endif /* alloca not defined. */
62 /* Note: there must be only one dollar sign in this file.
63 It is replaced by the list of actions, each action
64 as one case of the switch. */
66 #define yyerrok (yyerrstatus = 0)
67 #define yyclearin (yychar = YYEMPTY)
70 #define YYACCEPT return(0)
71 #define YYABORT return(1)
72 #define YYERROR goto yyerrlab1
73 /* Like YYERROR except do call yyerror.
74 This remains here temporarily to ease the
75 transition to the new meaning of YYERROR, for GCC.
76 Once GCC version 2 has supplanted version 1, this can go. */
77 #define YYFAIL goto yyerrlab
78 #define YYRECOVERING() (!!yyerrstatus)
79 #define YYBACKUP(token, value) \
81 if (yychar == YYEMPTY && yylen == 1) \
82 { yychar = (token), yylval = (value); \
83 yychar1 = YYTRANSLATE (yychar); \
88 { yyerror ("syntax error: cannot back up"); YYERROR; } \
101 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
103 #define YYLEX yylex(&yylval, &yylloc)
105 #else /* not YYLSP_NEEDED */
107 #define YYLEX yylex(&yylval, YYLEX_PARAM)
109 #define YYLEX yylex(&yylval)
111 #endif /* not YYLSP_NEEDED */
114 /* If nonreentrant, generate the variables here */
118 int yychar; /* the lookahead symbol */
119 YYSTYPE yylval; /* the semantic value of the */
120 /* lookahead symbol */
123 YYLTYPE yylloc; /* location data for the lookahead */
127 int yynerrs; /* number of parse errors so far */
128 #endif /* not YYPURE */
131 int yydebug; /* nonzero means print parse trace */
132 /* Since this is uninitialized, it does not stop multiple parsers
136 /* YYINITDEPTH indicates the initial size of the parser's stacks */
139 #define YYINITDEPTH 200
142 /* YYMAXDEPTH is the maximum size the stacks can grow to
143 (effective only if the built-in stack extension method is used). */
150 #define YYMAXDEPTH 10000
153 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
154 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
155 #else /* not GNU C or C++ */
158 /* This is the most reliable way to avoid incompatibilities
159 in available built-in functions on various systems. */
161 __yy_memcpy (to, from, count)
166 register char *f = from;
167 register char *t = to;
168 register int i = count;
174 #else /* __cplusplus */
176 /* This is the most reliable way to avoid incompatibilities
177 in available built-in functions on various systems. */
179 __yy_memcpy (char *to, char *from, int count)
181 register char *t = to;
182 register char *f = from;
183 register int i = count;
192 #line 196 "bison.simple"
194 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
195 into yyparse. The argument should have type void *.
196 It should actually point to an object.
197 Grammar actions can access the variable by casting it
198 to the proper pointer type. */
202 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
203 #define YYPARSE_PARAM_DECL
204 #else /* not __cplusplus */
205 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
206 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
207 #endif /* not __cplusplus */
208 #else /* not YYPARSE_PARAM */
209 #define YYPARSE_PARAM_ARG
210 #define YYPARSE_PARAM_DECL
211 #endif /* not YYPARSE_PARAM */
213 /* Prevent warning if -Wstrict-prototypes. */
216 int yyparse (void *);
223 yyparse(YYPARSE_PARAM_ARG)
226 register int yystate;
228 register short *yyssp;
229 register YYSTYPE *yyvsp;
230 int yyerrstatus; /* number of tokens to shift before error messages enabled */
231 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
233 short yyssa[YYINITDEPTH]; /* the state stack */
234 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
236 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
237 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
240 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
241 YYLTYPE *yyls = yylsa;
244 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
246 #define YYPOPSTACK (yyvsp--, yyssp--)
249 int yystacksize = YYINITDEPTH;
260 YYSTYPE yyval; /* the variable used to return */
261 /* semantic values from the action */
268 fprintf(stderr, "Starting parse\n");
274 yychar = YYEMPTY; /* Cause a token to be read. */
276 /* Initialize stack pointers.
277 Waste one element of value and location stack
278 so that they stay on the same level as the state stack.
279 The wasted elements are never initialized. */
287 /* Push a new state, which is found in yystate . */
288 /* In all cases, when you get here, the value and location stacks
289 have just been pushed. so pushing a state here evens the stacks. */
294 if (yyssp >= yyss + yystacksize - 1)
296 /* Give user a chance to reallocate the stack */
297 /* Use copies of these so that the &'s don't force the real ones into memory. */
298 YYSTYPE *yyvs1 = yyvs;
301 YYLTYPE *yyls1 = yyls;
304 /* Get the current used size of the three stacks, in elements. */
305 int size = yyssp - yyss + 1;
308 /* Each stack pointer address is followed by the size of
309 the data in use in that stack, in bytes. */
311 /* This used to be a conditional around just the two extra args,
312 but that might be undefined if yyoverflow is a macro. */
313 yyoverflow("parser stack overflow",
314 &yyss1, size * sizeof (*yyssp),
315 &yyvs1, size * sizeof (*yyvsp),
316 &yyls1, size * sizeof (*yylsp),
319 yyoverflow("parser stack overflow",
320 &yyss1, size * sizeof (*yyssp),
321 &yyvs1, size * sizeof (*yyvsp),
325 yyss = yyss1; yyvs = yyvs1;
329 #else /* no yyoverflow */
330 /* Extend the stack our own way. */
331 if (yystacksize >= YYMAXDEPTH)
333 yyerror("parser stack overflow");
337 if (yystacksize > YYMAXDEPTH)
338 yystacksize = YYMAXDEPTH;
339 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
340 __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
341 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
342 __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
344 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
345 __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
347 #endif /* no yyoverflow */
349 yyssp = yyss + size - 1;
350 yyvsp = yyvs + size - 1;
352 yylsp = yyls + size - 1;
357 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
360 if (yyssp >= yyss + yystacksize - 1)
366 fprintf(stderr, "Entering state %d\n", yystate);
372 /* Do appropriate processing given the current state. */
373 /* Read a lookahead token if we need one and don't already have one. */
376 /* First try to decide what to do without reference to lookahead token. */
378 yyn = yypact[yystate];
382 /* Not known => get a lookahead token if don't already have one. */
384 /* yychar is either YYEMPTY or YYEOF
385 or a valid token in external form. */
387 if (yychar == YYEMPTY)
391 fprintf(stderr, "Reading a token: ");
396 /* Convert token to internal form (in yychar1) for indexing tables with */
398 if (yychar <= 0) /* This means end of input. */
401 yychar = YYEOF; /* Don't call YYLEX any more */
405 fprintf(stderr, "Now at end of input.\n");
410 yychar1 = YYTRANSLATE(yychar);
415 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
416 /* Give the individual parser a way to print the precise meaning
417 of a token, for further debugging info. */
419 YYPRINT (stderr, yychar, yylval);
421 fprintf (stderr, ")\n");
427 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
432 /* yyn is what to do for this token type in this state.
433 Negative => reduce, -yyn is rule number.
434 Positive => shift, yyn is new state.
435 New state is final state => don't bother to shift,
437 0, or most negative number => error. */
452 /* Shift the lookahead token. */
456 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
459 /* Discard the token being shifted unless it is eof. */
468 /* count tokens shifted since error; after three, turn off error status. */
469 if (yyerrstatus) yyerrstatus--;
474 /* Do the default action for the current state. */
477 yyn = yydefact[yystate];
481 /* Do a reduction. yyn is the number of a rule to reduce with. */
485 yyval = yyvsp[1-yylen]; /* implement default value of the action */
492 fprintf (stderr, "Reducing via rule %d (line %d), ",
495 /* Print the symbols being reduced, and their result. */
496 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
497 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
498 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
502 $ /* the action file gets copied in in place of this dollarsign */
503 #line 498 "bison.simple"
514 short *ssp1 = yyss - 1;
515 fprintf (stderr, "state stack now");
516 while (ssp1 != yyssp)
517 fprintf (stderr, " %d", *++ssp1);
518 fprintf (stderr, "\n");
528 yylsp->first_line = yylloc.first_line;
529 yylsp->first_column = yylloc.first_column;
530 yylsp->last_line = (yylsp-1)->last_line;
531 yylsp->last_column = (yylsp-1)->last_column;
536 yylsp->last_line = (yylsp+yylen-1)->last_line;
537 yylsp->last_column = (yylsp+yylen-1)->last_column;
541 /* Now "shift" the result of the reduction.
542 Determine what state that goes to,
543 based on the state we popped back to
544 and the rule number reduced by. */
548 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
549 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
550 yystate = yytable[yystate];
552 yystate = yydefgoto[yyn - YYNTBASE];
556 yyerrlab: /* here on detecting error */
559 /* If not already recovering from an error, report this error. */
563 #ifdef YYERROR_VERBOSE
564 yyn = yypact[yystate];
566 if (yyn > YYFLAG && yyn < YYLAST)
573 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
574 for (x = (yyn < 0 ? -yyn : 0);
575 x < (sizeof(yytname) / sizeof(char *)); x++)
576 if (yycheck[x + yyn] == x)
577 size += strlen(yytname[x]) + 15, count++;
578 msg = (char *) malloc(size + 15);
581 strcpy(msg, "parse error");
586 for (x = (yyn < 0 ? -yyn : 0);
587 x < (sizeof(yytname) / sizeof(char *)); x++)
588 if (yycheck[x + yyn] == x)
590 strcat(msg, count == 0 ? ", expecting `" : " or `");
591 strcat(msg, yytname[x]);
600 yyerror ("parse error; also virtual memory exceeded");
603 #endif /* YYERROR_VERBOSE */
604 yyerror("parse error");
608 yyerrlab1: /* here on error raised explicitly by an action */
610 if (yyerrstatus == 3)
612 /* if just tried and failed to reuse lookahead token after an error, discard it. */
614 /* return failure if at end of input */
620 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
626 /* Else will try to reuse lookahead token
627 after shifting the error token. */
629 yyerrstatus = 3; /* Each real token shifted decrements this */
633 yyerrdefault: /* current state does not do anything special for the error token. */
636 /* This is wrong; only states that explicitly want error tokens
637 should shift them. */
638 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
639 if (yyn) goto yydefault;
642 yyerrpop: /* pop the current state because it cannot handle the error token */
644 if (yyssp == yyss) YYABORT;
654 short *ssp1 = yyss - 1;
655 fprintf (stderr, "Error: state stack now");
656 while (ssp1 != yyssp)
657 fprintf (stderr, " %d", *++ssp1);
658 fprintf (stderr, "\n");
664 yyn = yypact[yystate];
669 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
688 fprintf(stderr, "Shifting error token, ");