2 /* A Bison parser, made from expr.y
3 by GNU Bison version 1.28 */
5 #define YYBISON 1 /* Identify Bison output. */
7 #define TOKEN_IDENTIFIER 257
10 #define TOKEN_ARROW 260
11 #define TOKEN_ADDR 261
12 #define TOKEN_SIZEOF 262
13 #define TOKEN_NUMBER 263
30 extern int yyerror(char *);
35 //#define YYERROR_VERBOSE 1
56 #define YYTRANSLATE(x) ((unsigned)(x) <= 263 ? yytranslate[x] : 19)
58 static const char yytranslate
[] = { 0,
59 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
60 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
61 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
62 2, 2, 2, 2, 2, 2, 2, 2, 2, 11,
63 12, 2, 2, 2, 2, 2, 2, 2, 2, 2,
64 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
65 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
66 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
67 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
68 10, 2, 13, 2, 2, 2, 2, 2, 2, 2,
69 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
70 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
71 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
72 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
73 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
74 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
75 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
76 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
77 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
78 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
79 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
80 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
82 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
83 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
84 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
89 static const short yyprhs
[] = { 0,
90 0, 2, 4, 8, 12, 16, 21, 23, 26, 29,
94 static const short yyrhs
[] = { 15,
95 0, 16, 0, 11, 15, 12, 0, 15, 4, 18,
96 0, 15, 6, 18, 0, 15, 10, 17, 13, 0,
97 18, 0, 5, 15, 0, 7, 15, 0, 8, 11,
104 static const short yyrline
[] = { 0,
105 32, 35, 36, 37, 38, 39, 42, 43, 44, 45,
111 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
113 static const char * const yytname
[] = { "$","error","$undefined.","TOKEN_IDENTIFIER",
114 "TOKEN_DOT","TOKEN_STAR","TOKEN_ARROW","TOKEN_ADDR","TOKEN_SIZEOF","TOKEN_NUMBER",
115 "'['","'('","')'","']'","final","expression","simple_expression","number","ident", NULL
119 static const short yyr1
[] = { 0,
120 14, 15, 15, 15, 15, 15, 16, 16, 16, 16,
124 static const short yyr2
[] = { 0,
125 1, 1, 3, 3, 3, 4, 1, 2, 2, 4,
129 static const short yydefact
[] = { 0,
130 12, 0, 0, 0, 0, 1, 2, 7, 8, 9,
131 0, 0, 0, 0, 0, 0, 3, 4, 5, 11,
135 static const short yydefgoto
[] = { 24,
139 static const short yypact
[] = { -1,
140 -32768, -1, -1, -6, -1, 17,-32768,-32768, 17, 17,
141 -1, 7, 5, 5, 13, 8,-32768,-32768,-32768,-32768,
142 11,-32768,-32768, 25, 26,-32768
145 static const short yypgoto
[] = {-32768,
153 static const short yytable
[] = { 9,
154 10, 1, 12, 2, 11, 3, 4, 1, 16, 5,
155 13, 13, 14, 14, 18, 19, 15, 15, 17, 22,
156 13, 20, 14, 23, 25, 26, 15
159 static const short yycheck
[] = { 2,
160 3, 3, 5, 5, 11, 7, 8, 3, 11, 11,
161 4, 4, 6, 6, 13, 14, 10, 10, 12, 12,
162 4, 9, 6, 13, 0, 0, 10
164 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
165 #line 3 "/usr/lib/bison.simple"
166 /* This file comes from bison-1.28. */
168 /* Skeleton output parser for bison,
169 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
171 This program is free software; you can redistribute it and/or modify
172 it under the terms of the GNU General Public License as published by
173 the Free Software Foundation; either version 2, or (at your option)
176 This program is distributed in the hope that it will be useful,
177 but WITHOUT ANY WARRANTY; without even the implied warranty of
178 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
179 GNU General Public License for more details.
181 You should have received a copy of the GNU General Public License
182 along with this program; if not, write to the Free Software
183 Foundation, Inc., 59 Temple Place - Suite 330,
184 Boston, MA 02111-1307, USA. */
186 /* As a special exception, when this file is copied by Bison into a
187 Bison output file, you may use that output file without restriction.
188 This special exception was added by the Free Software Foundation
189 in version 1.24 of Bison. */
191 /* This is the parser code that is written into each bison parser
192 when the %semantic_parser declaration is not specified in the grammar.
193 It was written by Richard Stallman by simplifying the hairy parser
194 used when %semantic_parser is specified. */
196 #ifndef YYSTACK_USE_ALLOCA
198 #define YYSTACK_USE_ALLOCA
199 #else /* alloca not defined */
201 #define YYSTACK_USE_ALLOCA
202 #define alloca __builtin_alloca
203 #else /* not GNU C. */
204 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
205 #define YYSTACK_USE_ALLOCA
207 #else /* not sparc */
208 /* We think this test detects Watcom and Microsoft C. */
209 /* This used to test MSDOS, but that is a bad idea
210 since that symbol is in the user namespace. */
211 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
212 #if 0 /* No need for malloc.h, which pollutes the namespace;
213 instead, just don't use alloca. */
216 #else /* not MSDOS, or __TURBOC__ */
218 /* I don't know what this was needed for, but it pollutes the namespace.
219 So I turned it off. rms, 2 May 1997. */
220 /* #include <malloc.h> */
222 #define YYSTACK_USE_ALLOCA
223 #else /* not MSDOS, or __TURBOC__, or _AIX */
225 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
226 and on HPUX 10. Eventually we can turn this on. */
227 #define YYSTACK_USE_ALLOCA
228 #define alloca __builtin_alloca
231 #endif /* not _AIX */
232 #endif /* not MSDOS, or __TURBOC__ */
233 #endif /* not sparc */
234 #endif /* not GNU C */
235 #endif /* alloca not defined */
236 #endif /* YYSTACK_USE_ALLOCA not defined */
238 #ifdef YYSTACK_USE_ALLOCA
239 #define YYSTACK_ALLOC alloca
241 #define YYSTACK_ALLOC malloc
244 /* Note: there must be only one dollar sign in this file.
245 It is replaced by the list of actions, each action
246 as one case of the switch. */
248 #define yyerrok (yyerrstatus = 0)
249 #define yyclearin (yychar = YYEMPTY)
252 #define YYACCEPT goto yyacceptlab
253 #define YYABORT goto yyabortlab
254 #define YYERROR goto yyerrlab1
255 /* Like YYERROR except do call yyerror.
256 This remains here temporarily to ease the
257 transition to the new meaning of YYERROR, for GCC.
258 Once GCC version 2 has supplanted version 1, this can go. */
259 #define YYFAIL goto yyerrlab
260 #define YYRECOVERING() (!!yyerrstatus)
261 #define YYBACKUP(token, value) \
263 if (yychar == YYEMPTY && yylen == 1) \
264 { yychar = (token), yylval = (value); \
265 yychar1 = YYTRANSLATE (yychar); \
270 { yyerror ("syntax error: cannot back up"); YYERROR; } \
274 #define YYERRCODE 256
277 #define YYLEX yylex()
283 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
285 #define YYLEX yylex(&yylval, &yylloc)
287 #else /* not YYLSP_NEEDED */
289 #define YYLEX yylex(&yylval, YYLEX_PARAM)
291 #define YYLEX yylex(&yylval)
293 #endif /* not YYLSP_NEEDED */
296 /* If nonreentrant, generate the variables here */
300 int yychar
; /* the lookahead symbol */
301 YYSTYPE yylval
; /* the semantic value of the */
302 /* lookahead symbol */
305 YYLTYPE yylloc
; /* location data for the lookahead */
309 int yynerrs
; /* number of parse errors so far */
310 #endif /* not YYPURE */
313 int yydebug
; /* nonzero means print parse trace */
314 /* Since this is uninitialized, it does not stop multiple parsers
318 /* YYINITDEPTH indicates the initial size of the parser's stacks */
321 #define YYINITDEPTH 200
324 /* YYMAXDEPTH is the maximum size the stacks can grow to
325 (effective only if the built-in stack extension method is used). */
332 #define YYMAXDEPTH 10000
335 /* Define __yy_memcpy. Note that the size argument
336 should be passed with type unsigned int, because that is what the non-GCC
337 definitions require. With GCC, __builtin_memcpy takes an arg
338 of type size_t, but it can handle unsigned int. */
340 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
341 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
342 #else /* not GNU C or C++ */
345 /* This is the most reliable way to avoid incompatibilities
346 in available built-in functions on various systems. */
348 __yy_memcpy (to
, from
, count
)
353 register char *f
= from
;
354 register char *t
= to
;
355 register int i
= count
;
361 #else /* __cplusplus */
363 /* This is the most reliable way to avoid incompatibilities
364 in available built-in functions on various systems. */
366 __yy_memcpy (char *to
, char *from
, unsigned int count
)
368 register char *t
= to
;
369 register char *f
= from
;
370 register int i
= count
;
379 #line 217 "/usr/lib/bison.simple"
381 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
382 into yyparse. The argument should have type void *.
383 It should actually point to an object.
384 Grammar actions can access the variable by casting it
385 to the proper pointer type. */
389 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
390 #define YYPARSE_PARAM_DECL
391 #else /* not __cplusplus */
392 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
393 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
394 #endif /* not __cplusplus */
395 #else /* not YYPARSE_PARAM */
396 #define YYPARSE_PARAM_ARG
397 #define YYPARSE_PARAM_DECL
398 #endif /* not YYPARSE_PARAM */
400 /* Prevent warning if -Wstrict-prototypes. */
403 int yyparse (void *);
410 yyparse(YYPARSE_PARAM_ARG
)
413 register int yystate
;
415 register short *yyssp
;
416 register YYSTYPE
*yyvsp
;
417 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
418 int yychar1
= 0; /* lookahead token as an internal (translated) token number */
420 short yyssa
[YYINITDEPTH
]; /* the state stack */
421 YYSTYPE yyvsa
[YYINITDEPTH
]; /* the semantic value stack */
423 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
424 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
427 YYLTYPE yylsa
[YYINITDEPTH
]; /* the location stack */
428 YYLTYPE
*yyls
= yylsa
;
431 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
433 #define YYPOPSTACK (yyvsp--, yyssp--)
436 int yystacksize
= YYINITDEPTH
;
437 int yyfree_stacks
= 0;
448 YYSTYPE yyval
; /* the variable used to return */
449 /* semantic values from the action */
456 fprintf(stderr
, "Starting parse\n");
462 yychar
= YYEMPTY
; /* Cause a token to be read. */
464 /* Initialize stack pointers.
465 Waste one element of value and location stack
466 so that they stay on the same level as the state stack.
467 The wasted elements are never initialized. */
475 /* Push a new state, which is found in yystate . */
476 /* In all cases, when you get here, the value and location stacks
477 have just been pushed. so pushing a state here evens the stacks. */
482 if (yyssp
>= yyss
+ yystacksize
- 1)
484 /* Give user a chance to reallocate the stack */
485 /* Use copies of these so that the &'s don't force the real ones into memory. */
486 YYSTYPE
*yyvs1
= yyvs
;
489 YYLTYPE
*yyls1
= yyls
;
492 /* Get the current used size of the three stacks, in elements. */
493 int size
= yyssp
- yyss
+ 1;
496 /* Each stack pointer address is followed by the size of
497 the data in use in that stack, in bytes. */
499 /* This used to be a conditional around just the two extra args,
500 but that might be undefined if yyoverflow is a macro. */
501 yyoverflow("parser stack overflow",
502 &yyss1
, size
* sizeof (*yyssp
),
503 &yyvs1
, size
* sizeof (*yyvsp
),
504 &yyls1
, size
* sizeof (*yylsp
),
507 yyoverflow("parser stack overflow",
508 &yyss1
, size
* sizeof (*yyssp
),
509 &yyvs1
, size
* sizeof (*yyvsp
),
513 yyss
= yyss1
; yyvs
= yyvs1
;
517 #else /* no yyoverflow */
518 /* Extend the stack our own way. */
519 if (yystacksize
>= YYMAXDEPTH
)
521 yyerror("parser stack overflow");
533 if (yystacksize
> YYMAXDEPTH
)
534 yystacksize
= YYMAXDEPTH
;
535 #ifndef YYSTACK_USE_ALLOCA
538 yyss
= (short *) YYSTACK_ALLOC (yystacksize
* sizeof (*yyssp
));
539 __yy_memcpy ((char *)yyss
, (char *)yyss1
,
540 size
* (unsigned int) sizeof (*yyssp
));
541 yyvs
= (YYSTYPE
*) YYSTACK_ALLOC (yystacksize
* sizeof (*yyvsp
));
542 __yy_memcpy ((char *)yyvs
, (char *)yyvs1
,
543 size
* (unsigned int) sizeof (*yyvsp
));
545 yyls
= (YYLTYPE
*) YYSTACK_ALLOC (yystacksize
* sizeof (*yylsp
));
546 __yy_memcpy ((char *)yyls
, (char *)yyls1
,
547 size
* (unsigned int) sizeof (*yylsp
));
549 #endif /* no yyoverflow */
551 yyssp
= yyss
+ size
- 1;
552 yyvsp
= yyvs
+ size
- 1;
554 yylsp
= yyls
+ size
- 1;
559 fprintf(stderr
, "Stack size increased to %d\n", yystacksize
);
562 if (yyssp
>= yyss
+ yystacksize
- 1)
568 fprintf(stderr
, "Entering state %d\n", yystate
);
574 /* Do appropriate processing given the current state. */
575 /* Read a lookahead token if we need one and don't already have one. */
578 /* First try to decide what to do without reference to lookahead token. */
580 yyn
= yypact
[yystate
];
584 /* Not known => get a lookahead token if don't already have one. */
586 /* yychar is either YYEMPTY or YYEOF
587 or a valid token in external form. */
589 if (yychar
== YYEMPTY
)
593 fprintf(stderr
, "Reading a token: ");
598 /* Convert token to internal form (in yychar1) for indexing tables with */
600 if (yychar
<= 0) /* This means end of input. */
603 yychar
= YYEOF
; /* Don't call YYLEX any more */
607 fprintf(stderr
, "Now at end of input.\n");
612 yychar1
= YYTRANSLATE(yychar
);
617 fprintf (stderr
, "Next token is %d (%s", yychar
, yytname
[yychar1
]);
618 /* Give the individual parser a way to print the precise meaning
619 of a token, for further debugging info. */
621 YYPRINT (stderr
, yychar
, yylval
);
623 fprintf (stderr
, ")\n");
629 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
634 /* yyn is what to do for this token type in this state.
635 Negative => reduce, -yyn is rule number.
636 Positive => shift, yyn is new state.
637 New state is final state => don't bother to shift,
639 0, or most negative number => error. */
654 /* Shift the lookahead token. */
658 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
661 /* Discard the token being shifted unless it is eof. */
670 /* count tokens shifted since error; after three, turn off error status. */
671 if (yyerrstatus
) yyerrstatus
--;
676 /* Do the default action for the current state. */
679 yyn
= yydefact
[yystate
];
683 /* Do a reduction. yyn is the number of a rule to reduce with. */
687 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
694 fprintf (stderr
, "Reducing via rule %d (line %d), ",
697 /* Print the symbols being reduced, and their result. */
698 for (i
= yyprhs
[yyn
]; yyrhs
[i
] > 0; i
++)
699 fprintf (stderr
, "%s ", yytname
[yyrhs
[i
]]);
700 fprintf (stderr
, " -> %s\n", yytname
[yyr1
[yyn
]]);
709 { result
= yyvsp
[0]; ;
713 { yyval
= yyvsp
[0]; ;
717 { yyval
= yyvsp
[-1]; ;
721 { yyval
= exprNodeDot(yyvsp
[-2], yyvsp
[0]); ;
725 { yyval
= exprNodeArrow(yyvsp
[-2], yyvsp
[0]); ;
729 { yyval
= exprNodeArray(yyvsp
[-3], yyvsp
[-1]); ;
733 { yyval
= yyvsp
[0]; ;
737 { yyval
= exprNodeStar(yyvsp
[0]); ;
741 { yyval
= exprNodeAddr(yyvsp
[0]); ;
745 { yyval
= exprNodeSizeof(yyvsp
[-1]); ;
749 { yyval
= exprNodeNumber(); ;
753 {yyval
= exprNodeIdentifier(); ;
756 /* the action file gets copied in in place of this dollarsign */
757 #line 543 "/usr/lib/bison.simple"
768 short *ssp1
= yyss
- 1;
769 fprintf (stderr
, "state stack now");
770 while (ssp1
!= yyssp
)
771 fprintf (stderr
, " %d", *++ssp1
);
772 fprintf (stderr
, "\n");
782 yylsp
->first_line
= yylloc
.first_line
;
783 yylsp
->first_column
= yylloc
.first_column
;
784 yylsp
->last_line
= (yylsp
-1)->last_line
;
785 yylsp
->last_column
= (yylsp
-1)->last_column
;
790 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
791 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
795 /* Now "shift" the result of the reduction.
796 Determine what state that goes to,
797 based on the state we popped back to
798 and the rule number reduced by. */
802 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
803 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
804 yystate
= yytable
[yystate
];
806 yystate
= yydefgoto
[yyn
- YYNTBASE
];
810 yyerrlab
: /* here on detecting error */
813 /* If not already recovering from an error, report this error. */
817 #ifdef YYERROR_VERBOSE
818 yyn
= yypact
[yystate
];
820 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
827 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
828 for (x
= (yyn
< 0 ? -yyn
: 0);
829 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
830 if (yycheck
[x
+ yyn
] == x
)
831 size
+= strlen(yytname
[x
]) + 15, count
++;
832 msg
= (char *) malloc(size
+ 15);
835 strcpy(msg
, "parse error");
840 for (x
= (yyn
< 0 ? -yyn
: 0);
841 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
842 if (yycheck
[x
+ yyn
] == x
)
844 strcat(msg
, count
== 0 ? ", expecting `" : " or `");
845 strcat(msg
, yytname
[x
]);
854 yyerror ("parse error; also virtual memory exceeded");
857 #endif /* YYERROR_VERBOSE */
858 yyerror("parse error");
862 yyerrlab1
: /* here on error raised explicitly by an action */
864 if (yyerrstatus
== 3)
866 /* if just tried and failed to reuse lookahead token after an error, discard it. */
868 /* return failure if at end of input */
874 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
880 /* Else will try to reuse lookahead token
881 after shifting the error token. */
883 yyerrstatus
= 3; /* Each real token shifted decrements this */
887 yyerrdefault
: /* current state does not do anything special for the error token. */
890 /* This is wrong; only states that explicitly want error tokens
891 should shift them. */
892 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
893 if (yyn
) goto yydefault
;
896 yyerrpop
: /* pop the current state because it cannot handle the error token */
898 if (yyssp
== yyss
) YYABORT
;
908 short *ssp1
= yyss
- 1;
909 fprintf (stderr
, "Error: state stack now");
910 while (ssp1
!= yyssp
)
911 fprintf (stderr
, " %d", *++ssp1
);
912 fprintf (stderr
, "\n");
918 yyn
= yypact
[yystate
];
923 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
942 fprintf(stderr
, "Shifting error token, ");
954 /* YYACCEPT comes here. */
966 /* YYABORT comes here. */
987 int main(int argc
, char **argv
)
992 yyin
= fopen(argv
[0], "r");