1 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
4 /* Skeleton output parser for bison,
5 Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
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 1, 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. */
24 #define alloca __builtin_alloca
25 #else /* not GNU C. */
26 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
29 #if defined (MSDOS) && !defined (__TURBOC__)
31 #else /* not MSDOS, or __TURBOC__ */
35 #else /* not MSDOS, __TURBOC__, or _AIX */
39 void *alloca (unsigned int);
41 #else /* not __cplusplus */
43 #endif /* not __cplusplus */
46 #endif /* not MSDOS, or __TURBOC__ */
47 #endif /* not sparc. */
48 #endif /* not GNU C. */
49 #endif /* alloca not defined. */
51 /* This is the parser code that is written into each bison parser
52 when the %semantic_parser declaration is not specified in the grammar.
53 It was written by Richard Stallman by simplifying the hairy parser
54 used when %semantic_parser is specified. */
56 /* Note: there must be only one dollar sign in this file.
57 It is replaced by the list of actions, each action
58 as one case of the switch. */
60 #define yyerrok (yyerrstatus = 0)
61 #define yyclearin (yychar = YYEMPTY)
64 #define YYACCEPT return(0)
65 #define YYABORT return(1)
66 #define YYERROR goto yyerrlab1
67 /* Like YYERROR except do call yyerror.
68 This remains here temporarily to ease the
69 transition to the new meaning of YYERROR, for GCC.
70 Once GCC version 2 has supplanted version 1, this can go. */
71 #define YYFAIL goto yyerrlab
72 #define YYRECOVERING() (!!yyerrstatus)
73 #define YYBACKUP(token, value) \
75 if (yychar == YYEMPTY && yylen == 1) \
76 { yychar = (token), yylval = (value); \
77 yychar1 = YYTRANSLATE (yychar); \
82 { yyerror ("syntax error: cannot back up"); YYERROR; } \
94 #define YYLEX yylex(&yylval, &yylloc)
96 #define YYLEX yylex(&yylval)
100 /* If nonreentrant, generate the variables here */
104 int yychar; /* the lookahead symbol */
105 YYSTYPE yylval; /* the semantic value of the */
106 /* lookahead symbol */
109 YYLTYPE yylloc; /* location data for the lookahead */
113 int yynerrs; /* number of parse errors so far */
114 #endif /* not YYPURE */
117 int yydebug; /* nonzero means print parse trace */
118 /* Since this is uninitialized, it does not stop multiple parsers
122 /* YYINITDEPTH indicates the initial size of the parser's stacks */
125 #define YYINITDEPTH 200
128 /* YYMAXDEPTH is the maximum size the stacks can grow to
129 (effective only if the built-in stack extension method is used). */
136 #define YYMAXDEPTH 10000
139 /* Prevent warning if -Wstrict-prototypes. */
144 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
145 #define __yy_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
146 #else /* not GNU C or C++ */
149 /* This is the most reliable way to avoid incompatibilities
150 in available built-in functions on various systems. */
152 __yy_bcopy (from, to, count)
157 register char *f = from;
158 register char *t = to;
159 register int i = count;
165 #else /* __cplusplus */
167 /* This is the most reliable way to avoid incompatibilities
168 in available built-in functions on various systems. */
170 __yy_bcopy (char *from, char *to, int count)
172 register char *f = from;
173 register char *t = to;
174 register int i = count;
183 #line 184 "bison.simple"
187 register int yystate;
189 register short *yyssp;
190 register YYSTYPE *yyvsp;
191 int yyerrstatus; /* number of tokens to shift before error messages enabled */
192 int yychar1; /* lookahead token as an internal (translated) token number */
194 short yyssa[YYINITDEPTH]; /* the state stack */
195 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
197 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
198 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
201 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
202 YYLTYPE *yyls = yylsa;
205 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
207 #define YYPOPSTACK (yyvsp--, yyssp--)
210 int yystacksize = YYINITDEPTH;
221 YYSTYPE yyval; /* the variable used to return */
222 /* semantic values from the action */
229 fprintf(stderr, "Starting parse\n");
235 yychar = YYEMPTY; /* Cause a token to be read. */
237 /* Initialize stack pointers.
238 Waste one element of value and location stack
239 so that they stay on the same level as the state stack.
240 The wasted elements are never initialized. */
248 /* Push a new state, which is found in yystate . */
249 /* In all cases, when you get here, the value and location stacks
250 have just been pushed. so pushing a state here evens the stacks. */
255 if (yyssp >= yyss + yystacksize - 1)
257 /* Give user a chance to reallocate the stack */
258 /* Use copies of these so that the &'s don't force the real ones into memory. */
259 YYSTYPE *yyvs1 = yyvs;
262 YYLTYPE *yyls1 = yyls;
265 /* Get the current used size of the three stacks, in elements. */
266 int size = yyssp - yyss + 1;
269 /* Each stack pointer address is followed by the size of
270 the data in use in that stack, in bytes. */
271 yyoverflow("parser stack overflow",
272 &yyss1, size * sizeof (*yyssp),
273 &yyvs1, size * sizeof (*yyvsp),
275 &yyls1, size * sizeof (*yylsp),
279 yyss = yyss1; yyvs = yyvs1;
283 #else /* no yyoverflow */
284 /* Extend the stack our own way. */
285 if (yystacksize >= YYMAXDEPTH)
287 yyerror("parser stack overflow");
291 if (yystacksize > YYMAXDEPTH)
292 yystacksize = YYMAXDEPTH;
293 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
294 __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
295 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
296 __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
298 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
299 __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
301 #endif /* no yyoverflow */
303 yyssp = yyss + size - 1;
304 yyvsp = yyvs + size - 1;
306 yylsp = yyls + size - 1;
311 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
314 if (yyssp >= yyss + yystacksize - 1)
320 fprintf(stderr, "Entering state %d\n", yystate);
326 /* Do appropriate processing given the current state. */
327 /* Read a lookahead token if we need one and don't already have one. */
330 /* First try to decide what to do without reference to lookahead token. */
332 yyn = yypact[yystate];
336 /* Not known => get a lookahead token if don't already have one. */
338 /* yychar is either YYEMPTY or YYEOF
339 or a valid token in external form. */
341 if (yychar == YYEMPTY)
345 fprintf(stderr, "Reading a token: ");
350 /* Convert token to internal form (in yychar1) for indexing tables with */
352 if (yychar <= 0) /* This means end of input. */
355 yychar = YYEOF; /* Don't call YYLEX any more */
359 fprintf(stderr, "Now at end of input.\n");
364 yychar1 = YYTRANSLATE(yychar);
369 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
370 /* Give the individual parser a way to print the precise meaning
371 of a token, for further debugging info. */
373 YYPRINT (stderr, yychar, yylval);
375 fprintf (stderr, ")\n");
381 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
386 /* yyn is what to do for this token type in this state.
387 Negative => reduce, -yyn is rule number.
388 Positive => shift, yyn is new state.
389 New state is final state => don't bother to shift,
391 0, or most negative number => error. */
406 /* Shift the lookahead token. */
410 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
413 /* Discard the token being shifted unless it is eof. */
422 /* count tokens shifted since error; after three, turn off error status. */
423 if (yyerrstatus) yyerrstatus--;
428 /* Do the default action for the current state. */
431 yyn = yydefact[yystate];
435 /* Do a reduction. yyn is the number of a rule to reduce with. */
438 yyval = yyvsp[1-yylen]; /* implement default value of the action */
445 fprintf (stderr, "Reducing via rule %d (line %d), ",
448 /* Print the symbols being reduced, and their result. */
449 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
450 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
451 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
455 $ /* the action file gets copied in in place of this dollarsign */
456 #line 457 "bison.simple"
467 short *ssp1 = yyss - 1;
468 fprintf (stderr, "state stack now");
469 while (ssp1 != yyssp)
470 fprintf (stderr, " %d", *++ssp1);
471 fprintf (stderr, "\n");
481 yylsp->first_line = yylloc.first_line;
482 yylsp->first_column = yylloc.first_column;
483 yylsp->last_line = (yylsp-1)->last_line;
484 yylsp->last_column = (yylsp-1)->last_column;
489 yylsp->last_line = (yylsp+yylen-1)->last_line;
490 yylsp->last_column = (yylsp+yylen-1)->last_column;
494 /* Now "shift" the result of the reduction.
495 Determine what state that goes to,
496 based on the state we popped back to
497 and the rule number reduced by. */
501 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
502 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
503 yystate = yytable[yystate];
505 yystate = yydefgoto[yyn - YYNTBASE];
509 yyerrlab: /* here on detecting error */
512 /* If not already recovering from an error, report this error. */
516 #ifdef YYERROR_VERBOSE
517 yyn = yypact[yystate];
519 if (yyn > YYFLAG && yyn < YYLAST)
526 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
527 for (x = (yyn < 0 ? -yyn : 0);
528 x < (sizeof(yytname) / sizeof(char *)); x++)
529 if (yycheck[x + yyn] == x)
530 size += strlen(yytname[x]) + 15, count++;
531 msg = (char *) malloc(size + 15);
534 strcpy(msg, "parse error");
539 for (x = (yyn < 0 ? -yyn : 0);
540 x < (sizeof(yytname) / sizeof(char *)); x++)
541 if (yycheck[x + yyn] == x)
543 strcat(msg, count == 0 ? ", expecting `" : " or `");
544 strcat(msg, yytname[x]);
553 yyerror ("parse error; also virtual memory exceeded");
556 #endif /* YYERROR_VERBOSE */
557 yyerror("parse error");
561 yyerrlab1: /* here on error raised explicitly by an action */
563 if (yyerrstatus == 3)
565 /* if just tried and failed to reuse lookahead token after an error, discard it. */
567 /* return failure if at end of input */
573 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
579 /* Else will try to reuse lookahead token
580 after shifting the error token. */
582 yyerrstatus = 3; /* Each real token shifted decrements this */
586 yyerrdefault: /* current state does not do anything special for the error token. */
589 /* This is wrong; only states that explicitly want error tokens
590 should shift them. */
591 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
592 if (yyn) goto yydefault;
595 yyerrpop: /* pop the current state because it cannot handle the error token */
597 if (yyssp == yyss) YYABORT;
607 short *ssp1 = yyss - 1;
608 fprintf (stderr, "Error: state stack now");
609 while (ssp1 != yyssp)
610 fprintf (stderr, " %d", *++ssp1);
611 fprintf (stderr, "\n");
617 yyn = yypact[yystate];
622 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
641 fprintf(stderr, "Shifting error token, ");