]> git.saurik.com Git - bison.git/blob - bison.simple
e3bcfb6d2746b541223e08924d318c88e0d6e291
[bison.git] / bison.simple
1 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
2 #line 3 "bison.simple"
3
4 /* Skeleton output parser for bison,
5 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
6
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)
10 any later version.
11
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.
16
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. */
20
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. */
25
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. */
30
31 #ifndef alloca
32 #ifdef __GNUC__
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))
36 #include <alloca.h>
37 #else /* not sparc */
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__)
41 #include <malloc.h>
42 #else /* not MSDOS, or __TURBOC__ */
43 #if defined(_AIX)
44 #include <malloc.h>
45 #pragma alloca
46 #else /* not MSDOS, or __TURBOC__, or _AIX */
47 #ifdef __hpux /* This is right for HPUX 10. */
48 #include <alloca.h>
49 #endif
50 #if 0 /* This was right for HPUX 9.
51 Unfortunately there is no clean way to distinguish. */
52 #ifdef __hpux
53 #ifdef __cplusplus
54 extern "C" {
55 void *alloca (unsigned int);
56 };
57 #else /* not __cplusplus */
58 void *alloca ();
59 #endif /* not __cplusplus */
60 #endif /* __hpux */
61 #endif /* 0 */
62 #endif /* not _AIX */
63 #endif /* not MSDOS, or __TURBOC__ */
64 #endif /* not sparc. */
65 #endif /* not GNU C. */
66 #endif /* alloca not defined. */
67
68 /* Note: there must be only one dollar sign in this file.
69 It is replaced by the list of actions, each action
70 as one case of the switch. */
71
72 #define yyerrok (yyerrstatus = 0)
73 #define yyclearin (yychar = YYEMPTY)
74 #define YYEMPTY -2
75 #define YYEOF 0
76 #define YYACCEPT return(0)
77 #define YYABORT return(1)
78 #define YYERROR goto yyerrlab1
79 /* Like YYERROR except do call yyerror.
80 This remains here temporarily to ease the
81 transition to the new meaning of YYERROR, for GCC.
82 Once GCC version 2 has supplanted version 1, this can go. */
83 #define YYFAIL goto yyerrlab
84 #define YYRECOVERING() (!!yyerrstatus)
85 #define YYBACKUP(token, value) \
86 do \
87 if (yychar == YYEMPTY && yylen == 1) \
88 { yychar = (token), yylval = (value); \
89 yychar1 = YYTRANSLATE (yychar); \
90 YYPOPSTACK; \
91 goto yybackup; \
92 } \
93 else \
94 { yyerror ("syntax error: cannot back up"); YYERROR; } \
95 while (0)
96
97 #define YYTERROR 1
98 #define YYERRCODE 256
99
100 #ifndef YYPURE
101 #define YYLEX yylex()
102 #endif
103
104 #ifdef YYPURE
105 #ifdef YYLSP_NEEDED
106 #ifdef YYLEX_PARAM
107 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
108 #else
109 #define YYLEX yylex(&yylval, &yylloc)
110 #endif
111 #else /* not YYLSP_NEEDED */
112 #ifdef YYLEX_PARAM
113 #define YYLEX yylex(&yylval, YYLEX_PARAM)
114 #else
115 #define YYLEX yylex(&yylval)
116 #endif
117 #endif /* not YYLSP_NEEDED */
118 #endif
119
120 /* If nonreentrant, generate the variables here */
121
122 #ifndef YYPURE
123
124 int yychar; /* the lookahead symbol */
125 YYSTYPE yylval; /* the semantic value of the */
126 /* lookahead symbol */
127
128 #ifdef YYLSP_NEEDED
129 YYLTYPE yylloc; /* location data for the lookahead */
130 /* symbol */
131 #endif
132
133 int yynerrs; /* number of parse errors so far */
134 #endif /* not YYPURE */
135
136 #if YYDEBUG != 0
137 int yydebug; /* nonzero means print parse trace */
138 /* Since this is uninitialized, it does not stop multiple parsers
139 from coexisting. */
140 #endif
141
142 /* YYINITDEPTH indicates the initial size of the parser's stacks */
143
144 #ifndef YYINITDEPTH
145 #define YYINITDEPTH 200
146 #endif
147
148 /* YYMAXDEPTH is the maximum size the stacks can grow to
149 (effective only if the built-in stack extension method is used). */
150
151 #if YYMAXDEPTH == 0
152 #undef YYMAXDEPTH
153 #endif
154
155 #ifndef YYMAXDEPTH
156 #define YYMAXDEPTH 10000
157 #endif
158 \f
159 /* Define __yy_memcpy. Note that the size argument
160 should be passed with type unsigned int, because that is what the non-GCC
161 definitions require. With GCC, __builtin_memcpy takes an arg
162 of type size_t, but it can handle unsigned int. */
163
164 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
165 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
166 #else /* not GNU C or C++ */
167 #ifndef __cplusplus
168
169 /* This is the most reliable way to avoid incompatibilities
170 in available built-in functions on various systems. */
171 static void
172 __yy_memcpy (to, from, count)
173 char *to;
174 char *from;
175 unsigned int count;
176 {
177 register char *f = from;
178 register char *t = to;
179 register int i = count;
180
181 while (i-- > 0)
182 *t++ = *f++;
183 }
184
185 #else /* __cplusplus */
186
187 /* This is the most reliable way to avoid incompatibilities
188 in available built-in functions on various systems. */
189 static void
190 __yy_memcpy (char *to, char *from, unsigned int count)
191 {
192 register char *t = to;
193 register char *f = from;
194 register int i = count;
195
196 while (i-- > 0)
197 *t++ = *f++;
198 }
199
200 #endif
201 #endif
202 \f
203 #line 196 "bison.simple"
204
205 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
206 into yyparse. The argument should have type void *.
207 It should actually point to an object.
208 Grammar actions can access the variable by casting it
209 to the proper pointer type. */
210
211 #ifdef YYPARSE_PARAM
212 #ifdef __cplusplus
213 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
214 #define YYPARSE_PARAM_DECL
215 #else /* not __cplusplus */
216 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
217 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
218 #endif /* not __cplusplus */
219 #else /* not YYPARSE_PARAM */
220 #define YYPARSE_PARAM_ARG
221 #define YYPARSE_PARAM_DECL
222 #endif /* not YYPARSE_PARAM */
223
224 /* Prevent warning if -Wstrict-prototypes. */
225 #ifdef __GNUC__
226 #ifdef YYPARSE_PARAM
227 int yyparse (void *);
228 #else
229 int yyparse (void);
230 #endif
231 #endif
232
233 int
234 yyparse(YYPARSE_PARAM_ARG)
235 YYPARSE_PARAM_DECL
236 {
237 register int yystate;
238 register int yyn;
239 register short *yyssp;
240 register YYSTYPE *yyvsp;
241 int yyerrstatus; /* number of tokens to shift before error messages enabled */
242 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
243
244 short yyssa[YYINITDEPTH]; /* the state stack */
245 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
246
247 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
248 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
249
250 #ifdef YYLSP_NEEDED
251 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
252 YYLTYPE *yyls = yylsa;
253 YYLTYPE *yylsp;
254
255 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
256 #else
257 #define YYPOPSTACK (yyvsp--, yyssp--)
258 #endif
259
260 int yystacksize = YYINITDEPTH;
261
262 #ifdef YYPURE
263 int yychar;
264 YYSTYPE yylval;
265 int yynerrs;
266 #ifdef YYLSP_NEEDED
267 YYLTYPE yylloc;
268 #endif
269 #endif
270
271 YYSTYPE yyval; /* the variable used to return */
272 /* semantic values from the action */
273 /* routines */
274
275 int yylen;
276
277 #if YYDEBUG != 0
278 if (yydebug)
279 fprintf(stderr, "Starting parse\n");
280 #endif
281
282 yystate = 0;
283 yyerrstatus = 0;
284 yynerrs = 0;
285 yychar = YYEMPTY; /* Cause a token to be read. */
286
287 /* Initialize stack pointers.
288 Waste one element of value and location stack
289 so that they stay on the same level as the state stack.
290 The wasted elements are never initialized. */
291
292 yyssp = yyss - 1;
293 yyvsp = yyvs;
294 #ifdef YYLSP_NEEDED
295 yylsp = yyls;
296 #endif
297
298 /* Push a new state, which is found in yystate . */
299 /* In all cases, when you get here, the value and location stacks
300 have just been pushed. so pushing a state here evens the stacks. */
301 yynewstate:
302
303 *++yyssp = yystate;
304
305 if (yyssp >= yyss + yystacksize - 1)
306 {
307 /* Give user a chance to reallocate the stack */
308 /* Use copies of these so that the &'s don't force the real ones into memory. */
309 YYSTYPE *yyvs1 = yyvs;
310 short *yyss1 = yyss;
311 #ifdef YYLSP_NEEDED
312 YYLTYPE *yyls1 = yyls;
313 #endif
314
315 /* Get the current used size of the three stacks, in elements. */
316 int size = yyssp - yyss + 1;
317
318 #ifdef yyoverflow
319 /* Each stack pointer address is followed by the size of
320 the data in use in that stack, in bytes. */
321 #ifdef YYLSP_NEEDED
322 /* This used to be a conditional around just the two extra args,
323 but that might be undefined if yyoverflow is a macro. */
324 yyoverflow("parser stack overflow",
325 &yyss1, size * sizeof (*yyssp),
326 &yyvs1, size * sizeof (*yyvsp),
327 &yyls1, size * sizeof (*yylsp),
328 &yystacksize);
329 #else
330 yyoverflow("parser stack overflow",
331 &yyss1, size * sizeof (*yyssp),
332 &yyvs1, size * sizeof (*yyvsp),
333 &yystacksize);
334 #endif
335
336 yyss = yyss1; yyvs = yyvs1;
337 #ifdef YYLSP_NEEDED
338 yyls = yyls1;
339 #endif
340 #else /* no yyoverflow */
341 /* Extend the stack our own way. */
342 if (yystacksize >= YYMAXDEPTH)
343 {
344 yyerror("parser stack overflow");
345 return 2;
346 }
347 yystacksize *= 2;
348 if (yystacksize > YYMAXDEPTH)
349 yystacksize = YYMAXDEPTH;
350 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
351 __yy_memcpy ((char *)yyss, (char *)yyss1,
352 size * (unsigned int) sizeof (*yyssp));
353 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
354 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
355 size * (unsigned int) sizeof (*yyvsp));
356 #ifdef YYLSP_NEEDED
357 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
358 __yy_memcpy ((char *)yyls, (char *)yyls1,
359 size * (unsigned int) sizeof (*yylsp));
360 #endif
361 #endif /* no yyoverflow */
362
363 yyssp = yyss + size - 1;
364 yyvsp = yyvs + size - 1;
365 #ifdef YYLSP_NEEDED
366 yylsp = yyls + size - 1;
367 #endif
368
369 #if YYDEBUG != 0
370 if (yydebug)
371 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
372 #endif
373
374 if (yyssp >= yyss + yystacksize - 1)
375 YYABORT;
376 }
377
378 #if YYDEBUG != 0
379 if (yydebug)
380 fprintf(stderr, "Entering state %d\n", yystate);
381 #endif
382
383 goto yybackup;
384 yybackup:
385
386 /* Do appropriate processing given the current state. */
387 /* Read a lookahead token if we need one and don't already have one. */
388 /* yyresume: */
389
390 /* First try to decide what to do without reference to lookahead token. */
391
392 yyn = yypact[yystate];
393 if (yyn == YYFLAG)
394 goto yydefault;
395
396 /* Not known => get a lookahead token if don't already have one. */
397
398 /* yychar is either YYEMPTY or YYEOF
399 or a valid token in external form. */
400
401 if (yychar == YYEMPTY)
402 {
403 #if YYDEBUG != 0
404 if (yydebug)
405 fprintf(stderr, "Reading a token: ");
406 #endif
407 yychar = YYLEX;
408 }
409
410 /* Convert token to internal form (in yychar1) for indexing tables with */
411
412 if (yychar <= 0) /* This means end of input. */
413 {
414 yychar1 = 0;
415 yychar = YYEOF; /* Don't call YYLEX any more */
416
417 #if YYDEBUG != 0
418 if (yydebug)
419 fprintf(stderr, "Now at end of input.\n");
420 #endif
421 }
422 else
423 {
424 yychar1 = YYTRANSLATE(yychar);
425
426 #if YYDEBUG != 0
427 if (yydebug)
428 {
429 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
430 /* Give the individual parser a way to print the precise meaning
431 of a token, for further debugging info. */
432 #ifdef YYPRINT
433 YYPRINT (stderr, yychar, yylval);
434 #endif
435 fprintf (stderr, ")\n");
436 }
437 #endif
438 }
439
440 yyn += yychar1;
441 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
442 goto yydefault;
443
444 yyn = yytable[yyn];
445
446 /* yyn is what to do for this token type in this state.
447 Negative => reduce, -yyn is rule number.
448 Positive => shift, yyn is new state.
449 New state is final state => don't bother to shift,
450 just return success.
451 0, or most negative number => error. */
452
453 if (yyn < 0)
454 {
455 if (yyn == YYFLAG)
456 goto yyerrlab;
457 yyn = -yyn;
458 goto yyreduce;
459 }
460 else if (yyn == 0)
461 goto yyerrlab;
462
463 if (yyn == YYFINAL)
464 YYACCEPT;
465
466 /* Shift the lookahead token. */
467
468 #if YYDEBUG != 0
469 if (yydebug)
470 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
471 #endif
472
473 /* Discard the token being shifted unless it is eof. */
474 if (yychar != YYEOF)
475 yychar = YYEMPTY;
476
477 *++yyvsp = yylval;
478 #ifdef YYLSP_NEEDED
479 *++yylsp = yylloc;
480 #endif
481
482 /* count tokens shifted since error; after three, turn off error status. */
483 if (yyerrstatus) yyerrstatus--;
484
485 yystate = yyn;
486 goto yynewstate;
487
488 /* Do the default action for the current state. */
489 yydefault:
490
491 yyn = yydefact[yystate];
492 if (yyn == 0)
493 goto yyerrlab;
494
495 /* Do a reduction. yyn is the number of a rule to reduce with. */
496 yyreduce:
497 yylen = yyr2[yyn];
498 if (yylen > 0)
499 yyval = yyvsp[1-yylen]; /* implement default value of the action */
500
501 #if YYDEBUG != 0
502 if (yydebug)
503 {
504 int i;
505
506 fprintf (stderr, "Reducing via rule %d (line %d), ",
507 yyn, yyrline[yyn]);
508
509 /* Print the symbols being reduced, and their result. */
510 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
511 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
512 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
513 }
514 #endif
515
516 $ /* the action file gets copied in in place of this dollarsign */
517 #line 498 "bison.simple"
518 \f
519 yyvsp -= yylen;
520 yyssp -= yylen;
521 #ifdef YYLSP_NEEDED
522 yylsp -= yylen;
523 #endif
524
525 #if YYDEBUG != 0
526 if (yydebug)
527 {
528 short *ssp1 = yyss - 1;
529 fprintf (stderr, "state stack now");
530 while (ssp1 != yyssp)
531 fprintf (stderr, " %d", *++ssp1);
532 fprintf (stderr, "\n");
533 }
534 #endif
535
536 *++yyvsp = yyval;
537
538 #ifdef YYLSP_NEEDED
539 yylsp++;
540 if (yylen == 0)
541 {
542 yylsp->first_line = yylloc.first_line;
543 yylsp->first_column = yylloc.first_column;
544 yylsp->last_line = (yylsp-1)->last_line;
545 yylsp->last_column = (yylsp-1)->last_column;
546 yylsp->text = 0;
547 }
548 else
549 {
550 yylsp->last_line = (yylsp+yylen-1)->last_line;
551 yylsp->last_column = (yylsp+yylen-1)->last_column;
552 }
553 #endif
554
555 /* Now "shift" the result of the reduction.
556 Determine what state that goes to,
557 based on the state we popped back to
558 and the rule number reduced by. */
559
560 yyn = yyr1[yyn];
561
562 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
563 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
564 yystate = yytable[yystate];
565 else
566 yystate = yydefgoto[yyn - YYNTBASE];
567
568 goto yynewstate;
569
570 yyerrlab: /* here on detecting error */
571
572 if (! yyerrstatus)
573 /* If not already recovering from an error, report this error. */
574 {
575 ++yynerrs;
576
577 #ifdef YYERROR_VERBOSE
578 yyn = yypact[yystate];
579
580 if (yyn > YYFLAG && yyn < YYLAST)
581 {
582 int size = 0;
583 char *msg;
584 int x, count;
585
586 count = 0;
587 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
588 for (x = (yyn < 0 ? -yyn : 0);
589 x < (sizeof(yytname) / sizeof(char *)); x++)
590 if (yycheck[x + yyn] == x)
591 size += strlen(yytname[x]) + 15, count++;
592 msg = (char *) malloc(size + 15);
593 if (msg != 0)
594 {
595 strcpy(msg, "parse error");
596
597 if (count < 5)
598 {
599 count = 0;
600 for (x = (yyn < 0 ? -yyn : 0);
601 x < (sizeof(yytname) / sizeof(char *)); x++)
602 if (yycheck[x + yyn] == x)
603 {
604 strcat(msg, count == 0 ? ", expecting `" : " or `");
605 strcat(msg, yytname[x]);
606 strcat(msg, "'");
607 count++;
608 }
609 }
610 yyerror(msg);
611 free(msg);
612 }
613 else
614 yyerror ("parse error; also virtual memory exceeded");
615 }
616 else
617 #endif /* YYERROR_VERBOSE */
618 yyerror("parse error");
619 }
620
621 goto yyerrlab1;
622 yyerrlab1: /* here on error raised explicitly by an action */
623
624 if (yyerrstatus == 3)
625 {
626 /* if just tried and failed to reuse lookahead token after an error, discard it. */
627
628 /* return failure if at end of input */
629 if (yychar == YYEOF)
630 YYABORT;
631
632 #if YYDEBUG != 0
633 if (yydebug)
634 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
635 #endif
636
637 yychar = YYEMPTY;
638 }
639
640 /* Else will try to reuse lookahead token
641 after shifting the error token. */
642
643 yyerrstatus = 3; /* Each real token shifted decrements this */
644
645 goto yyerrhandle;
646
647 yyerrdefault: /* current state does not do anything special for the error token. */
648
649 #if 0
650 /* This is wrong; only states that explicitly want error tokens
651 should shift them. */
652 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
653 if (yyn) goto yydefault;
654 #endif
655
656 yyerrpop: /* pop the current state because it cannot handle the error token */
657
658 if (yyssp == yyss) YYABORT;
659 yyvsp--;
660 yystate = *--yyssp;
661 #ifdef YYLSP_NEEDED
662 yylsp--;
663 #endif
664
665 #if YYDEBUG != 0
666 if (yydebug)
667 {
668 short *ssp1 = yyss - 1;
669 fprintf (stderr, "Error: state stack now");
670 while (ssp1 != yyssp)
671 fprintf (stderr, " %d", *++ssp1);
672 fprintf (stderr, "\n");
673 }
674 #endif
675
676 yyerrhandle:
677
678 yyn = yypact[yystate];
679 if (yyn == YYFLAG)
680 goto yyerrdefault;
681
682 yyn += YYTERROR;
683 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
684 goto yyerrdefault;
685
686 yyn = yytable[yyn];
687 if (yyn < 0)
688 {
689 if (yyn == YYFLAG)
690 goto yyerrpop;
691 yyn = -yyn;
692 goto yyreduce;
693 }
694 else if (yyn == 0)
695 goto yyerrpop;
696
697 if (yyn == YYFINAL)
698 YYACCEPT;
699
700 #if YYDEBUG != 0
701 if (yydebug)
702 fprintf(stderr, "Shifting error token, ");
703 #endif
704
705 *++yyvsp = yylval;
706 #ifdef YYLSP_NEEDED
707 *++yylsp = yylloc;
708 #endif
709
710 yystate = yyn;
711 goto yynewstate;
712 }