]> git.saurik.com Git - bison.git/blame - src/bison.simple
*** empty log message ***
[bison.git] / src / bison.simple
CommitLineData
10fa2066
RS
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
38extern "C" {
39void *alloca (unsigned int);
40};
41#else /* not __cplusplus */
42void *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) \
74do \
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; } \
83while (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
104int yychar; /* the lookahead symbol */
105YYSTYPE yylval; /* the semantic value of the */
106 /* lookahead symbol */
107
108#ifdef YYLSP_NEEDED
109YYLTYPE yylloc; /* location data for the lookahead */
110 /* symbol */
111#endif
112
113int yynerrs; /* number of parse errors so far */
114#endif /* not YYPURE */
115
116#if YYDEBUG != 0
117int 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__
141int 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. */
151static 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. */
169static 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"
184int
185yyparse()
186{
187 register int yystate;
188 register int yyn;
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 */
193
194 short yyssa[YYINITDEPTH]; /* the state stack */
195 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
196
197 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
198 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
199
200#ifdef YYLSP_NEEDED
201 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
202 YYLTYPE *yyls = yylsa;
203 YYLTYPE *yylsp;
204
205#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
206#else
207#define YYPOPSTACK (yyvsp--, yyssp--)
208#endif
209
210 int yystacksize = YYINITDEPTH;
211
212#ifdef YYPURE
213 int yychar;
214 YYSTYPE yylval;
215 int yynerrs;
216#ifdef YYLSP_NEEDED
217 YYLTYPE yylloc;
218#endif
219#endif
220
221 YYSTYPE yyval; /* the variable used to return */
222 /* semantic values from the action */
223 /* routines */
224
225 int yylen;
226
227#if YYDEBUG != 0
228 if (yydebug)
229 fprintf(stderr, "Starting parse\n");
230#endif
231
232 yystate = 0;
233 yyerrstatus = 0;
234 yynerrs = 0;
235 yychar = YYEMPTY; /* Cause a token to be read. */
236
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. */
241
242 yyssp = yyss - 1;
243 yyvsp = yyvs;
244#ifdef YYLSP_NEEDED
245 yylsp = yyls;
246#endif
247
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. */
251yynewstate:
252
253 *++yyssp = yystate;
254
255 if (yyssp >= yyss + yystacksize - 1)
256 {
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;
260 short *yyss1 = yyss;
261#ifdef YYLSP_NEEDED
262 YYLTYPE *yyls1 = yyls;
263#endif
264
265 /* Get the current used size of the three stacks, in elements. */
266 int size = yyssp - yyss + 1;
267
268#ifdef yyoverflow
269 /* Each stack pointer address is followed by the size of
270 the data in use in that stack, in bytes. */
be4bf877
RS
271#ifdef YYLSP_NEEDED
272 /* This used to be a conditional around just the two extra args,
273 but that might be undefined if yyoverflow is a macro. */
10fa2066
RS
274 yyoverflow("parser stack overflow",
275 &yyss1, size * sizeof (*yyssp),
276 &yyvs1, size * sizeof (*yyvsp),
10fa2066 277 &yyls1, size * sizeof (*yylsp),
10fa2066 278 &yystacksize);
be4bf877
RS
279#else
280 yyoverflow("parser stack overflow",
281 &yyss1, size * sizeof (*yyssp),
282 &yyvs1, size * sizeof (*yyvsp),
283 &yystacksize);
284#endif
10fa2066
RS
285
286 yyss = yyss1; yyvs = yyvs1;
287#ifdef YYLSP_NEEDED
288 yyls = yyls1;
289#endif
290#else /* no yyoverflow */
291 /* Extend the stack our own way. */
292 if (yystacksize >= YYMAXDEPTH)
293 {
294 yyerror("parser stack overflow");
295 return 2;
296 }
297 yystacksize *= 2;
298 if (yystacksize > YYMAXDEPTH)
299 yystacksize = YYMAXDEPTH;
300 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
301 __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
302 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
303 __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
304#ifdef YYLSP_NEEDED
305 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
306 __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
307#endif
308#endif /* no yyoverflow */
309
310 yyssp = yyss + size - 1;
311 yyvsp = yyvs + size - 1;
312#ifdef YYLSP_NEEDED
313 yylsp = yyls + size - 1;
314#endif
315
316#if YYDEBUG != 0
317 if (yydebug)
318 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
319#endif
320
321 if (yyssp >= yyss + yystacksize - 1)
322 YYABORT;
323 }
324
325#if YYDEBUG != 0
326 if (yydebug)
327 fprintf(stderr, "Entering state %d\n", yystate);
328#endif
329
330 goto yybackup;
331 yybackup:
332
333/* Do appropriate processing given the current state. */
334/* Read a lookahead token if we need one and don't already have one. */
335/* yyresume: */
336
337 /* First try to decide what to do without reference to lookahead token. */
338
339 yyn = yypact[yystate];
340 if (yyn == YYFLAG)
341 goto yydefault;
342
343 /* Not known => get a lookahead token if don't already have one. */
344
345 /* yychar is either YYEMPTY or YYEOF
346 or a valid token in external form. */
347
348 if (yychar == YYEMPTY)
349 {
350#if YYDEBUG != 0
351 if (yydebug)
352 fprintf(stderr, "Reading a token: ");
353#endif
354 yychar = YYLEX;
355 }
356
357 /* Convert token to internal form (in yychar1) for indexing tables with */
358
359 if (yychar <= 0) /* This means end of input. */
360 {
361 yychar1 = 0;
362 yychar = YYEOF; /* Don't call YYLEX any more */
363
364#if YYDEBUG != 0
365 if (yydebug)
366 fprintf(stderr, "Now at end of input.\n");
367#endif
368 }
369 else
370 {
371 yychar1 = YYTRANSLATE(yychar);
372
373#if YYDEBUG != 0
374 if (yydebug)
375 {
376 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
377 /* Give the individual parser a way to print the precise meaning
378 of a token, for further debugging info. */
379#ifdef YYPRINT
380 YYPRINT (stderr, yychar, yylval);
381#endif
382 fprintf (stderr, ")\n");
383 }
384#endif
385 }
386
387 yyn += yychar1;
388 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
389 goto yydefault;
390
391 yyn = yytable[yyn];
392
393 /* yyn is what to do for this token type in this state.
394 Negative => reduce, -yyn is rule number.
395 Positive => shift, yyn is new state.
396 New state is final state => don't bother to shift,
397 just return success.
398 0, or most negative number => error. */
399
400 if (yyn < 0)
401 {
402 if (yyn == YYFLAG)
403 goto yyerrlab;
404 yyn = -yyn;
405 goto yyreduce;
406 }
407 else if (yyn == 0)
408 goto yyerrlab;
409
410 if (yyn == YYFINAL)
411 YYACCEPT;
412
413 /* Shift the lookahead token. */
414
415#if YYDEBUG != 0
416 if (yydebug)
417 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
418#endif
419
420 /* Discard the token being shifted unless it is eof. */
421 if (yychar != YYEOF)
422 yychar = YYEMPTY;
423
424 *++yyvsp = yylval;
425#ifdef YYLSP_NEEDED
426 *++yylsp = yylloc;
427#endif
428
429 /* count tokens shifted since error; after three, turn off error status. */
430 if (yyerrstatus) yyerrstatus--;
431
432 yystate = yyn;
433 goto yynewstate;
434
435/* Do the default action for the current state. */
436yydefault:
437
438 yyn = yydefact[yystate];
439 if (yyn == 0)
440 goto yyerrlab;
441
442/* Do a reduction. yyn is the number of a rule to reduce with. */
443yyreduce:
444 yylen = yyr2[yyn];
fb75fa82
RS
445 if (yylen > 0)
446 yyval = yyvsp[1-yylen]; /* implement default value of the action */
10fa2066
RS
447
448#if YYDEBUG != 0
449 if (yydebug)
450 {
451 int i;
452
453 fprintf (stderr, "Reducing via rule %d (line %d), ",
454 yyn, yyrline[yyn]);
455
456 /* Print the symbols being reduced, and their result. */
457 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
458 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
459 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
460 }
461#endif
462
463$ /* the action file gets copied in in place of this dollarsign */
fb75fa82 464#line 465 "bison.simple"
10fa2066
RS
465\f
466 yyvsp -= yylen;
467 yyssp -= yylen;
468#ifdef YYLSP_NEEDED
469 yylsp -= yylen;
470#endif
471
472#if YYDEBUG != 0
473 if (yydebug)
474 {
475 short *ssp1 = yyss - 1;
476 fprintf (stderr, "state stack now");
477 while (ssp1 != yyssp)
478 fprintf (stderr, " %d", *++ssp1);
479 fprintf (stderr, "\n");
480 }
481#endif
482
483 *++yyvsp = yyval;
484
485#ifdef YYLSP_NEEDED
486 yylsp++;
487 if (yylen == 0)
488 {
489 yylsp->first_line = yylloc.first_line;
490 yylsp->first_column = yylloc.first_column;
491 yylsp->last_line = (yylsp-1)->last_line;
492 yylsp->last_column = (yylsp-1)->last_column;
493 yylsp->text = 0;
494 }
495 else
496 {
497 yylsp->last_line = (yylsp+yylen-1)->last_line;
498 yylsp->last_column = (yylsp+yylen-1)->last_column;
499 }
500#endif
501
502 /* Now "shift" the result of the reduction.
503 Determine what state that goes to,
504 based on the state we popped back to
505 and the rule number reduced by. */
506
507 yyn = yyr1[yyn];
508
509 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
510 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
511 yystate = yytable[yystate];
512 else
513 yystate = yydefgoto[yyn - YYNTBASE];
514
515 goto yynewstate;
516
517yyerrlab: /* here on detecting error */
518
519 if (! yyerrstatus)
520 /* If not already recovering from an error, report this error. */
521 {
522 ++yynerrs;
523
524#ifdef YYERROR_VERBOSE
525 yyn = yypact[yystate];
526
527 if (yyn > YYFLAG && yyn < YYLAST)
528 {
529 int size = 0;
530 char *msg;
531 int x, count;
532
533 count = 0;
534 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
535 for (x = (yyn < 0 ? -yyn : 0);
536 x < (sizeof(yytname) / sizeof(char *)); x++)
537 if (yycheck[x + yyn] == x)
538 size += strlen(yytname[x]) + 15, count++;
539 msg = (char *) malloc(size + 15);
540 if (msg != 0)
541 {
542 strcpy(msg, "parse error");
543
544 if (count < 5)
545 {
546 count = 0;
547 for (x = (yyn < 0 ? -yyn : 0);
548 x < (sizeof(yytname) / sizeof(char *)); x++)
549 if (yycheck[x + yyn] == x)
550 {
551 strcat(msg, count == 0 ? ", expecting `" : " or `");
552 strcat(msg, yytname[x]);
553 strcat(msg, "'");
554 count++;
555 }
556 }
557 yyerror(msg);
558 free(msg);
559 }
560 else
561 yyerror ("parse error; also virtual memory exceeded");
562 }
563 else
564#endif /* YYERROR_VERBOSE */
565 yyerror("parse error");
566 }
567
568 goto yyerrlab1;
569yyerrlab1: /* here on error raised explicitly by an action */
570
571 if (yyerrstatus == 3)
572 {
573 /* if just tried and failed to reuse lookahead token after an error, discard it. */
574
575 /* return failure if at end of input */
576 if (yychar == YYEOF)
577 YYABORT;
578
579#if YYDEBUG != 0
580 if (yydebug)
581 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
582#endif
583
584 yychar = YYEMPTY;
585 }
586
587 /* Else will try to reuse lookahead token
588 after shifting the error token. */
589
590 yyerrstatus = 3; /* Each real token shifted decrements this */
591
592 goto yyerrhandle;
593
594yyerrdefault: /* current state does not do anything special for the error token. */
595
596#if 0
597 /* This is wrong; only states that explicitly want error tokens
598 should shift them. */
599 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
600 if (yyn) goto yydefault;
601#endif
602
603yyerrpop: /* pop the current state because it cannot handle the error token */
604
605 if (yyssp == yyss) YYABORT;
606 yyvsp--;
607 yystate = *--yyssp;
608#ifdef YYLSP_NEEDED
609 yylsp--;
610#endif
611
612#if YYDEBUG != 0
613 if (yydebug)
614 {
615 short *ssp1 = yyss - 1;
616 fprintf (stderr, "Error: state stack now");
617 while (ssp1 != yyssp)
618 fprintf (stderr, " %d", *++ssp1);
619 fprintf (stderr, "\n");
620 }
621#endif
622
623yyerrhandle:
624
625 yyn = yypact[yystate];
626 if (yyn == YYFLAG)
627 goto yyerrdefault;
628
629 yyn += YYTERROR;
630 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
631 goto yyerrdefault;
632
633 yyn = yytable[yyn];
634 if (yyn < 0)
635 {
636 if (yyn == YYFLAG)
637 goto yyerrpop;
638 yyn = -yyn;
639 goto yyreduce;
640 }
641 else if (yyn == 0)
642 goto yyerrpop;
643
644 if (yyn == YYFINAL)
645 YYACCEPT;
646
647#if YYDEBUG != 0
648 if (yydebug)
649 fprintf(stderr, "Shifting error token, ");
650#endif
651
652 *++yyvsp = yylval;
653#ifdef YYLSP_NEEDED
654 *++yylsp = yylloc;
655#endif
656
657 yystate = yyn;
658 goto yynewstate;
659}