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