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.23 of Bison. */
28 #define alloca __builtin_alloca
29 #else /* not GNU C. */
30 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
33 #if defined (MSDOS) && !defined (__TURBOC__)
35 #else /* not MSDOS, or __TURBOC__ */
39 #else /* not MSDOS, __TURBOC__, or _AIX */
43 void *alloca (unsigned int);
45 #else /* not __cplusplus */
47 #endif /* not __cplusplus */
50 #endif /* not MSDOS, or __TURBOC__ */
51 #endif /* not sparc. */
52 #endif /* not GNU C. */
53 #endif /* alloca not defined. */
55 /* This is the parser code that is written into each bison parser
56 when the %semantic_parser declaration is not specified in the grammar.
57 It was written by Richard Stallman by simplifying the hairy parser
58 used when %semantic_parser is specified. */
60 /* Note: there must be only one dollar sign in this file.
61 It is replaced by the list of actions, each action
62 as one case of the switch. */
64 #define yyerrok (yyerrstatus = 0)
65 #define yyclearin (yychar = YYEMPTY)
68 #define YYACCEPT return(0)
69 #define YYABORT return(1)
70 #define YYERROR goto yyerrlab1
71 /* Like YYERROR except do call yyerror.
72 This remains here temporarily to ease the
73 transition to the new meaning of YYERROR, for GCC.
74 Once GCC version 2 has supplanted version 1, this can go. */
75 #define YYFAIL goto yyerrlab
76 #define YYRECOVERING() (!!yyerrstatus)
77 #define YYBACKUP(token, value) \
79 if (yychar == YYEMPTY && yylen == 1) \
80 { yychar = (token), yylval = (value); \
81 yychar1 = YYTRANSLATE (yychar); \
86 { yyerror ("syntax error: cannot back up"); YYERROR; } \
99 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
101 #define YYLEX yylex(&yylval, &yylloc)
103 #else /* not YYLSP_NEEDED */
105 #define YYLEX yylex(&yylval, YYLEX_PARAM)
107 #define YYLEX yylex(&yylval)
109 #endif /* not YYLSP_NEEDED */
112 /* If nonreentrant, generate the variables here */
116 int yychar; /* the lookahead symbol */
117 YYSTYPE yylval; /* the semantic value of the */
118 /* lookahead symbol */
121 YYLTYPE yylloc; /* location data for the lookahead */
125 int yynerrs; /* number of parse errors so far */
126 #endif /* not YYPURE */
129 int yydebug; /* nonzero means print parse trace */
130 /* Since this is uninitialized, it does not stop multiple parsers
134 /* YYINITDEPTH indicates the initial size of the parser's stacks */
137 #define YYINITDEPTH 200
140 /* YYMAXDEPTH is the maximum size the stacks can grow to
141 (effective only if the built-in stack extension method is used). */
148 #define YYMAXDEPTH 10000
151 /* Prevent warning if -Wstrict-prototypes. */
156 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
157 #define __yy_memcpy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
158 #else /* not GNU C or C++ */
161 /* This is the most reliable way to avoid incompatibilities
162 in available built-in functions on various systems. */
164 __yy_memcpy (from, to, count)
169 register char *f = from;
170 register char *t = to;
171 register int i = count;
177 #else /* __cplusplus */
179 /* This is the most reliable way to avoid incompatibilities
180 in available built-in functions on various systems. */
182 __yy_memcpy (char *from, char *to, int count)
184 register char *f = from;
185 register char *t = to;
186 register int i = count;
195 #line 192 "bison.simple"
197 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
198 into yyparse. The argument should have type void *.
199 It should actually point to an object.
200 Grammar actions can access the variable by casting it
201 to the proper pointer type. */
204 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
206 #define YYPARSE_PARAM
207 #define YYPARSE_PARAM_DECL
211 yyparse(YYPARSE_PARAM)
214 register int yystate;
216 register short *yyssp;
217 register YYSTYPE *yyvsp;
218 int yyerrstatus; /* number of tokens to shift before error messages enabled */
219 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
221 short yyssa[YYINITDEPTH]; /* the state stack */
222 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
224 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
225 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
228 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
229 YYLTYPE *yyls = yylsa;
232 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
234 #define YYPOPSTACK (yyvsp--, yyssp--)
237 int yystacksize = YYINITDEPTH;
248 YYSTYPE yyval; /* the variable used to return */
249 /* semantic values from the action */
256 fprintf(stderr, "Starting parse\n");
262 yychar = YYEMPTY; /* Cause a token to be read. */
264 /* Initialize stack pointers.
265 Waste one element of value and location stack
266 so that they stay on the same level as the state stack.
267 The wasted elements are never initialized. */
275 /* Push a new state, which is found in yystate . */
276 /* In all cases, when you get here, the value and location stacks
277 have just been pushed. so pushing a state here evens the stacks. */
282 if (yyssp >= yyss + yystacksize - 1)
284 /* Give user a chance to reallocate the stack */
285 /* Use copies of these so that the &'s don't force the real ones into memory. */
286 YYSTYPE *yyvs1 = yyvs;
289 YYLTYPE *yyls1 = yyls;
292 /* Get the current used size of the three stacks, in elements. */
293 int size = yyssp - yyss + 1;
296 /* Each stack pointer address is followed by the size of
297 the data in use in that stack, in bytes. */
299 /* This used to be a conditional around just the two extra args,
300 but that might be undefined if yyoverflow is a macro. */
301 yyoverflow("parser stack overflow",
302 &yyss1, size * sizeof (*yyssp),
303 &yyvs1, size * sizeof (*yyvsp),
304 &yyls1, size * sizeof (*yylsp),
307 yyoverflow("parser stack overflow",
308 &yyss1, size * sizeof (*yyssp),
309 &yyvs1, size * sizeof (*yyvsp),
313 yyss = yyss1; yyvs = yyvs1;
317 #else /* no yyoverflow */
318 /* Extend the stack our own way. */
319 if (yystacksize >= YYMAXDEPTH)
321 yyerror("parser stack overflow");
325 if (yystacksize > YYMAXDEPTH)
326 yystacksize = YYMAXDEPTH;
327 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
328 __yy_memcpy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
329 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
330 __yy_memcpy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
332 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
333 __yy_memcpy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
335 #endif /* no yyoverflow */
337 yyssp = yyss + size - 1;
338 yyvsp = yyvs + size - 1;
340 yylsp = yyls + size - 1;
345 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
348 if (yyssp >= yyss + yystacksize - 1)
354 fprintf(stderr, "Entering state %d\n", yystate);
360 /* Do appropriate processing given the current state. */
361 /* Read a lookahead token if we need one and don't already have one. */
364 /* First try to decide what to do without reference to lookahead token. */
366 yyn = yypact[yystate];
370 /* Not known => get a lookahead token if don't already have one. */
372 /* yychar is either YYEMPTY or YYEOF
373 or a valid token in external form. */
375 if (yychar == YYEMPTY)
379 fprintf(stderr, "Reading a token: ");
384 /* Convert token to internal form (in yychar1) for indexing tables with */
386 if (yychar <= 0) /* This means end of input. */
389 yychar = YYEOF; /* Don't call YYLEX any more */
393 fprintf(stderr, "Now at end of input.\n");
398 yychar1 = YYTRANSLATE(yychar);
403 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
404 /* Give the individual parser a way to print the precise meaning
405 of a token, for further debugging info. */
407 YYPRINT (stderr, yychar, yylval);
409 fprintf (stderr, ")\n");
415 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
420 /* yyn is what to do for this token type in this state.
421 Negative => reduce, -yyn is rule number.
422 Positive => shift, yyn is new state.
423 New state is final state => don't bother to shift,
425 0, or most negative number => error. */
440 /* Shift the lookahead token. */
444 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
447 /* Discard the token being shifted unless it is eof. */
456 /* count tokens shifted since error; after three, turn off error status. */
457 if (yyerrstatus) yyerrstatus--;
462 /* Do the default action for the current state. */
465 yyn = yydefact[yystate];
469 /* Do a reduction. yyn is the number of a rule to reduce with. */
473 yyval = yyvsp[1-yylen]; /* implement default value of the action */
480 fprintf (stderr, "Reducing via rule %d (line %d), ",
483 /* Print the symbols being reduced, and their result. */
484 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
485 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
486 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
490 $ /* the action file gets copied in in place of this dollarsign */
491 #line 487 "bison.simple"
502 short *ssp1 = yyss - 1;
503 fprintf (stderr, "state stack now");
504 while (ssp1 != yyssp)
505 fprintf (stderr, " %d", *++ssp1);
506 fprintf (stderr, "\n");
516 yylsp->first_line = yylloc.first_line;
517 yylsp->first_column = yylloc.first_column;
518 yylsp->last_line = (yylsp-1)->last_line;
519 yylsp->last_column = (yylsp-1)->last_column;
524 yylsp->last_line = (yylsp+yylen-1)->last_line;
525 yylsp->last_column = (yylsp+yylen-1)->last_column;
529 /* Now "shift" the result of the reduction.
530 Determine what state that goes to,
531 based on the state we popped back to
532 and the rule number reduced by. */
536 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
537 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
538 yystate = yytable[yystate];
540 yystate = yydefgoto[yyn - YYNTBASE];
544 yyerrlab: /* here on detecting error */
547 /* If not already recovering from an error, report this error. */
551 #ifdef YYERROR_VERBOSE
552 yyn = yypact[yystate];
554 if (yyn > YYFLAG && yyn < YYLAST)
561 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
562 for (x = (yyn < 0 ? -yyn : 0);
563 x < (sizeof(yytname) / sizeof(char *)); x++)
564 if (yycheck[x + yyn] == x)
565 size += strlen(yytname[x]) + 15, count++;
566 msg = (char *) malloc(size + 15);
569 strcpy(msg, "parse error");
574 for (x = (yyn < 0 ? -yyn : 0);
575 x < (sizeof(yytname) / sizeof(char *)); x++)
576 if (yycheck[x + yyn] == x)
578 strcat(msg, count == 0 ? ", expecting `" : " or `");
579 strcat(msg, yytname[x]);
588 yyerror ("parse error; also virtual memory exceeded");
591 #endif /* YYERROR_VERBOSE */
592 yyerror("parse error");
596 yyerrlab1: /* here on error raised explicitly by an action */
598 if (yyerrstatus == 3)
600 /* if just tried and failed to reuse lookahead token after an error, discard it. */
602 /* return failure if at end of input */
608 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
614 /* Else will try to reuse lookahead token
615 after shifting the error token. */
617 yyerrstatus = 3; /* Each real token shifted decrements this */
621 yyerrdefault: /* current state does not do anything special for the error token. */
624 /* This is wrong; only states that explicitly want error tokens
625 should shift them. */
626 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
627 if (yyn) goto yydefault;
630 yyerrpop: /* pop the current state because it cannot handle the error token */
632 if (yyssp == yyss) YYABORT;
642 short *ssp1 = yyss - 1;
643 fprintf (stderr, "Error: state stack now");
644 while (ssp1 != yyssp)
645 fprintf (stderr, " %d", *++ssp1);
646 fprintf (stderr, "\n");
652 yyn = yypact[yystate];
657 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
676 fprintf(stderr, "Shifting error token, ");