2 /* A Bison parser, made from cexp.y
3 by GNU Bison version 1.25
6 #define YYBISON 1 /* Identify Bison output. */
29 /* #define YYDEBUG 1 */
31 #ifdef MULTIBYTE_CHARS
34 #endif /* MULTIBYTE_CHARS */
36 typedef unsigned char U_CHAR
;
38 /* This is used for communicating lists of keywords with cccp.c. */
46 HOST_WIDEST_INT parse_c_expression
PROTO((char *, int));
48 static int yylex
PROTO((void));
49 static void yyerror
PVPROTO((const char *, ...))
50 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
51 static HOST_WIDEST_INT expression_value
;
52 #ifdef TEST_EXP_READER
53 static int expression_signedp
;
56 static jmp_buf parse_return_error
;
58 /* Nonzero means count most punctuation as part of a name. */
59 static int keyword_parsing
= 0;
61 /* Nonzero means do not evaluate this expression.
62 This is a count, since unevaluated expressions can nest. */
63 static int skip_evaluation
;
65 /* Nonzero means warn if undefined identifiers are evaluated. */
66 static int warn_undef
;
68 /* some external tables of character types */
69 extern unsigned char is_idstart
[], is_idchar
[], is_space
[];
71 /* Flag for -pedantic. */
74 /* Flag for -traditional. */
75 extern int traditional
;
77 /* Flag for -lang-c89. */
80 #ifndef CHAR_TYPE_SIZE
81 #define CHAR_TYPE_SIZE BITS_PER_UNIT
85 #define INT_TYPE_SIZE BITS_PER_WORD
88 #ifndef LONG_TYPE_SIZE
89 #define LONG_TYPE_SIZE BITS_PER_WORD
92 #ifndef WCHAR_TYPE_SIZE
93 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
96 #ifndef MAX_CHAR_TYPE_SIZE
97 #define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE
100 #ifndef MAX_INT_TYPE_SIZE
101 #define MAX_INT_TYPE_SIZE INT_TYPE_SIZE
104 #ifndef MAX_LONG_TYPE_SIZE
105 #define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE
108 #ifndef MAX_WCHAR_TYPE_SIZE
109 #define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
112 #define MAX_CHAR_TYPE_MASK (MAX_CHAR_TYPE_SIZE < HOST_BITS_PER_WIDEST_INT \
113 ? (~ (~ (HOST_WIDEST_INT) 0 << MAX_CHAR_TYPE_SIZE)) \
114 : ~ (HOST_WIDEST_INT) 0)
116 #define MAX_WCHAR_TYPE_MASK (MAX_WCHAR_TYPE_SIZE < HOST_BITS_PER_WIDEST_INT \
117 ? ~ (~ (HOST_WIDEST_INT) 0 << MAX_WCHAR_TYPE_SIZE) \
118 : ~ (HOST_WIDEST_INT) 0)
120 /* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
121 Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
122 Suppose SIGNEDP is negative if the result is signed, zero if unsigned.
123 Then this yields nonzero if overflow occurred during the addition.
124 Overflow occurs if A and B have the same sign, but A and SUM differ in sign,
125 and SIGNEDP is negative.
126 Use `^' to test whether signs differ, and `< 0' to isolate the sign. */
127 #define overflow_sum_sign(a, b, sum, signedp) \
128 ((~((a) ^ (b)) & ((a) ^ (sum)) & (signedp)) < 0)
132 HOST_WIDEST_INT parse_escape
PROTO((char **, HOST_WIDEST_INT
));
133 int check_assertion
PROTO((U_CHAR
*, int, int, struct arglist
*));
134 struct hashnode
*lookup
PROTO((U_CHAR
*, int, int));
135 void error
PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1
;
136 void verror
PROTO((const char *, va_list));
137 void pedwarn
PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1
;
138 void warning
PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1
;
140 static int parse_number
PROTO((int));
141 static HOST_WIDEST_INT left_shift
PROTO((struct constant
*, unsigned HOST_WIDEST_INT
));
142 static HOST_WIDEST_INT right_shift
PROTO((struct constant
*, unsigned HOST_WIDEST_INT
));
143 static void integer_overflow
PROTO((void));
145 /* `signedp' values */
151 struct constant
{HOST_WIDEST_INT value
; int signedp
;} integer
;
152 struct name
{U_CHAR
*address
; int length
;} name
;
153 struct arglist
*keywords
;
166 #define YYFLAG -32768
169 #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 43)
171 static const char yytranslate
[] = { 0,
172 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
173 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
174 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
175 2, 2, 29, 2, 31, 2, 27, 14, 2, 32,
176 33, 25, 23, 9, 24, 2, 26, 2, 2, 2,
177 2, 2, 2, 2, 2, 2, 2, 8, 2, 17,
178 2, 18, 7, 2, 2, 2, 2, 2, 2, 2,
179 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
180 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
181 2, 2, 2, 13, 2, 2, 2, 2, 2, 2,
182 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
184 2, 2, 2, 12, 2, 30, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
187 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
188 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
189 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
190 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
194 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
195 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
196 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
197 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
198 6, 10, 11, 15, 16, 19, 20, 21, 22, 28
202 static const short yyprhs
[] = { 0,
203 0, 2, 4, 8, 11, 14, 17, 20, 23, 24,
204 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
205 71, 75, 79, 83, 87, 91, 95, 99, 100, 105,
206 106, 111, 112, 113, 121, 123, 125, 127, 128, 133
209 static const short yyrhs
[] = { 35,
210 0, 36, 0, 35, 9, 36, 0, 24, 36, 0,
211 29, 36, 0, 23, 36, 0, 30, 36, 0, 31,
212 5, 0, 0, 31, 5, 37, 32, 42, 33, 0,
213 32, 35, 33, 0, 36, 25, 36, 0, 36, 26,
214 36, 0, 36, 27, 36, 0, 36, 23, 36, 0,
215 36, 24, 36, 0, 36, 21, 36, 0, 36, 22,
216 36, 0, 36, 15, 36, 0, 36, 16, 36, 0,
217 36, 19, 36, 0, 36, 20, 36, 0, 36, 17,
218 36, 0, 36, 18, 36, 0, 36, 14, 36, 0,
219 36, 13, 36, 0, 36, 12, 36, 0, 0, 36,
220 11, 38, 36, 0, 0, 36, 10, 39, 36, 0,
221 0, 0, 36, 7, 40, 36, 8, 41, 36, 0,
222 3, 0, 4, 0, 5, 0, 0, 32, 42, 33,
229 static const short yyrline
[] = { 0,
230 184, 194, 195, 202, 207, 210, 212, 215, 219, 221,
231 226, 231, 244, 261, 274, 280, 286, 292, 298, 301,
232 304, 311, 318, 325, 332, 335, 338, 341, 344, 347,
233 350, 353, 355, 358, 361, 363, 365, 373, 375, 388
238 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
240 static const char * const yytname
[] = { "$","error","$undefined.","INT","CHAR",
241 "NAME","ERROR","'?'","':'","','","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL",
242 "'<'","'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'","UNARY","'!'",
243 "'~'","'#'","'('","')'","start","exp1","exp","@1","@2","@3","@4","@5","keywords", NULL
247 static const short yyr1
[] = { 0,
248 34, 35, 35, 36, 36, 36, 36, 36, 37, 36,
249 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
250 36, 36, 36, 36, 36, 36, 36, 38, 36, 39,
251 36, 40, 41, 36, 36, 36, 36, 42, 42, 42
254 static const short yyr2
[] = { 0,
255 1, 1, 3, 2, 2, 2, 2, 2, 0, 6,
256 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
257 3, 3, 3, 3, 3, 3, 3, 0, 4, 0,
258 4, 0, 0, 7, 1, 1, 1, 0, 4, 2
261 static const short yydefact
[] = { 0,
262 35, 36, 37, 0, 0, 0, 0, 0, 0, 1,
263 2, 6, 4, 5, 7, 8, 0, 0, 32, 30,
264 28, 0, 0, 0, 0, 0, 0, 0, 0, 0,
265 0, 0, 0, 0, 0, 0, 0, 0, 11, 3,
266 0, 0, 0, 27, 26, 25, 19, 20, 23, 24,
267 21, 22, 17, 18, 15, 16, 12, 13, 14, 38,
268 0, 31, 29, 38, 38, 0, 33, 40, 0, 10,
269 0, 38, 34, 39, 0, 0, 0
272 static const short yydefgoto
[] = { 75,
273 10, 11, 38, 43, 42, 41, 71, 66
276 static const short yypact
[] = { 12,
277 -32768,-32768,-32768, 12, 12, 12, 12, 1, 12, 4,
278 79,-32768,-32768,-32768,-32768, -21, 31, 12,-32768,-32768,
279 -32768, 12, 12, 12, 12, 12, 12, 12, 12, 12,
280 12, 12, 12, 12, 12, 12, 12, 30,-32768, 79,
281 12, 12, 12, 110, 124, 137, 148, 148, 155, 155,
282 155, 155, 160, 160, -17, -17,-32768,-32768,-32768, 2,
283 58, 34, 95, 2, 2, 54,-32768,-32768, 55,-32768,
284 12, 2, 79,-32768, 63, 188,-32768
287 static const short yypgoto
[] = {-32768,
288 180, -4,-32768,-32768,-32768,-32768,-32768, -60
295 static const short yytable
[] = { 12,
296 13, 14, 15, 68, 69, 16, 64, 35, 36, 37,
297 -9, 74, 18, 40, 1, 2, 3, 44, 45, 46,
298 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
299 57, 58, 59, 65, 4, 5, 61, 62, 63, 18,
300 6, 7, 8, 9, 21, 22, 23, 24, 25, 26,
301 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
302 37, 60, 76, 39, 19, 67, 73, 20, 21, 22,
303 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
304 33, 34, 35, 36, 37, 19, 70, 72, 20, 21,
305 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
306 32, 33, 34, 35, 36, 37, 22, 23, 24, 25,
307 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
308 36, 37, 23, 24, 25, 26, 27, 28, 29, 30,
309 31, 32, 33, 34, 35, 36, 37, 24, 25, 26,
310 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
311 37, 25, 26, 27, 28, 29, 30, 31, 32, 33,
312 34, 35, 36, 37, 27, 28, 29, 30, 31, 32,
313 33, 34, 35, 36, 37, 31, 32, 33, 34, 35,
314 36, 37, 33, 34, 35, 36, 37, 77, 17
317 static const short yycheck
[] = { 4,
318 5, 6, 7, 64, 65, 5, 5, 25, 26, 27,
319 32, 72, 9, 18, 3, 4, 5, 22, 23, 24,
320 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
321 35, 36, 37, 32, 23, 24, 41, 42, 43, 9,
322 29, 30, 31, 32, 11, 12, 13, 14, 15, 16,
323 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
324 27, 32, 0, 33, 7, 8, 71, 10, 11, 12,
325 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
326 23, 24, 25, 26, 27, 7, 33, 33, 10, 11,
327 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
328 22, 23, 24, 25, 26, 27, 12, 13, 14, 15,
329 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
330 26, 27, 13, 14, 15, 16, 17, 18, 19, 20,
331 21, 22, 23, 24, 25, 26, 27, 14, 15, 16,
332 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
333 27, 15, 16, 17, 18, 19, 20, 21, 22, 23,
334 24, 25, 26, 27, 17, 18, 19, 20, 21, 22,
335 23, 24, 25, 26, 27, 21, 22, 23, 24, 25,
336 26, 27, 23, 24, 25, 26, 27, 0, 9
338 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
339 #line 3 "/tmp/sky/share/bison.simple"
341 /* Skeleton output parser for bison,
342 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
344 This program is free software; you can redistribute it and/or modify
345 it under the terms of the GNU General Public License as published by
346 the Free Software Foundation; either version 2, or (at your option)
349 This program is distributed in the hope that it will be useful,
350 but WITHOUT ANY WARRANTY; without even the implied warranty of
351 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
352 GNU General Public License for more details.
354 You should have received a copy of the GNU General Public License
355 along with this program; if not, write to the Free Software
356 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
358 /* As a special exception, when this file is copied by Bison into a
359 Bison output file, you may use that output file without restriction.
360 This special exception was added by the Free Software Foundation
361 in version 1.24 of Bison. */
365 #define alloca __builtin_alloca
366 #else /* not GNU C. */
367 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
369 #else /* not sparc */
370 #if defined (MSDOS) && !defined (__TURBOC__)
372 #else /* not MSDOS, or __TURBOC__ */
376 #else /* not MSDOS, __TURBOC__, or _AIX */
380 void *alloca (unsigned int);
382 #else /* not __cplusplus */
384 #endif /* not __cplusplus */
386 #endif /* not _AIX */
387 #endif /* not MSDOS, or __TURBOC__ */
388 #endif /* not sparc. */
389 #endif /* not GNU C. */
390 #endif /* alloca not defined. */
392 /* This is the parser code that is written into each bison parser
393 when the %semantic_parser declaration is not specified in the grammar.
394 It was written by Richard Stallman by simplifying the hairy parser
395 used when %semantic_parser is specified. */
397 /* Note: there must be only one dollar sign in this file.
398 It is replaced by the list of actions, each action
399 as one case of the switch. */
401 #define yyerrok (yyerrstatus = 0)
402 #define yyclearin (yychar = YYEMPTY)
405 #define YYACCEPT return(0)
406 #define YYABORT return(1)
407 #define YYERROR goto yyerrlab1
408 /* Like YYERROR except do call yyerror.
409 This remains here temporarily to ease the
410 transition to the new meaning of YYERROR, for GCC.
411 Once GCC version 2 has supplanted version 1, this can go. */
412 #define YYFAIL goto yyerrlab
413 #define YYRECOVERING() (!!yyerrstatus)
414 #define YYBACKUP(token, value) \
416 if (yychar == YYEMPTY && yylen == 1) \
417 { yychar = (token), yylval = (value); \
418 yychar1 = YYTRANSLATE (yychar); \
423 { yyerror ("syntax error: cannot back up"); YYERROR; } \
427 #define YYERRCODE 256
430 #define YYLEX yylex()
436 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
438 #define YYLEX yylex(&yylval, &yylloc)
440 #else /* not YYLSP_NEEDED */
442 #define YYLEX yylex(&yylval, YYLEX_PARAM)
444 #define YYLEX yylex(&yylval)
446 #endif /* not YYLSP_NEEDED */
449 /* If nonreentrant, generate the variables here */
453 int yychar
; /* the lookahead symbol */
454 YYSTYPE yylval
; /* the semantic value of the */
455 /* lookahead symbol */
458 YYLTYPE yylloc
; /* location data for the lookahead */
462 int yynerrs
; /* number of parse errors so far */
463 #endif /* not YYPURE */
466 int yydebug
; /* nonzero means print parse trace */
467 /* Since this is uninitialized, it does not stop multiple parsers
471 /* YYINITDEPTH indicates the initial size of the parser's stacks */
474 #define YYINITDEPTH 200
477 /* YYMAXDEPTH is the maximum size the stacks can grow to
478 (effective only if the built-in stack extension method is used). */
485 #define YYMAXDEPTH 10000
488 /* Prevent warning if -Wstrict-prototypes. */
493 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
494 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
495 #else /* not GNU C or C++ */
498 /* This is the most reliable way to avoid incompatibilities
499 in available built-in functions on various systems. */
501 __yy_memcpy (to
, from
, count
)
506 register char *f
= from
;
507 register char *t
= to
;
508 register int i
= count
;
514 #else /* __cplusplus */
516 /* This is the most reliable way to avoid incompatibilities
517 in available built-in functions on various systems. */
519 __yy_memcpy (char *to
, char *from
, int count
)
521 register char *f
= from
;
522 register char *t
= to
;
523 register int i
= count
;
532 #line 196 "/tmp/sky/share/bison.simple"
534 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
535 into yyparse. The argument should have type void *.
536 It should actually point to an object.
537 Grammar actions can access the variable by casting it
538 to the proper pointer type. */
542 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
543 #define YYPARSE_PARAM_DECL
544 #else /* not __cplusplus */
545 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
546 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
547 #endif /* not __cplusplus */
548 #else /* not YYPARSE_PARAM */
549 #define YYPARSE_PARAM_ARG
550 #define YYPARSE_PARAM_DECL
551 #endif /* not YYPARSE_PARAM */
554 yyparse(YYPARSE_PARAM_ARG
)
557 register int yystate
;
559 register short *yyssp
;
560 register YYSTYPE
*yyvsp
;
561 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
562 int yychar1
= 0; /* lookahead token as an internal (translated) token number */
564 short yyssa
[YYINITDEPTH
]; /* the state stack */
565 YYSTYPE yyvsa
[YYINITDEPTH
]; /* the semantic value stack */
567 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
568 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
571 YYLTYPE yylsa
[YYINITDEPTH
]; /* the location stack */
572 YYLTYPE
*yyls
= yylsa
;
575 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
577 #define YYPOPSTACK (yyvsp--, yyssp--)
580 int yystacksize
= YYINITDEPTH
;
591 YYSTYPE yyval
; /* the variable used to return */
592 /* semantic values from the action */
599 fprintf(stderr
, "Starting parse\n");
605 yychar
= YYEMPTY
; /* Cause a token to be read. */
607 /* Initialize stack pointers.
608 Waste one element of value and location stack
609 so that they stay on the same level as the state stack.
610 The wasted elements are never initialized. */
618 /* Push a new state, which is found in yystate . */
619 /* In all cases, when you get here, the value and location stacks
620 have just been pushed. so pushing a state here evens the stacks. */
625 if (yyssp
>= yyss
+ yystacksize
- 1)
627 /* Give user a chance to reallocate the stack */
628 /* Use copies of these so that the &'s don't force the real ones into memory. */
629 YYSTYPE
*yyvs1
= yyvs
;
632 YYLTYPE
*yyls1
= yyls
;
635 /* Get the current used size of the three stacks, in elements. */
636 int size
= yyssp
- yyss
+ 1;
639 /* Each stack pointer address is followed by the size of
640 the data in use in that stack, in bytes. */
642 /* This used to be a conditional around just the two extra args,
643 but that might be undefined if yyoverflow is a macro. */
644 yyoverflow("parser stack overflow",
645 &yyss1
, size
* sizeof (*yyssp
),
646 &yyvs1
, size
* sizeof (*yyvsp
),
647 &yyls1
, size
* sizeof (*yylsp
),
650 yyoverflow("parser stack overflow",
651 &yyss1
, size
* sizeof (*yyssp
),
652 &yyvs1
, size
* sizeof (*yyvsp
),
656 yyss
= yyss1
; yyvs
= yyvs1
;
660 #else /* no yyoverflow */
661 /* Extend the stack our own way. */
662 if (yystacksize
>= YYMAXDEPTH
)
664 yyerror("parser stack overflow");
668 if (yystacksize
> YYMAXDEPTH
)
669 yystacksize
= YYMAXDEPTH
;
670 yyss
= (short *) alloca (yystacksize
* sizeof (*yyssp
));
671 __yy_memcpy ((char *)yyss
, (char *)yyss1
, size
* sizeof (*yyssp
));
672 yyvs
= (YYSTYPE
*) alloca (yystacksize
* sizeof (*yyvsp
));
673 __yy_memcpy ((char *)yyvs
, (char *)yyvs1
, size
* sizeof (*yyvsp
));
675 yyls
= (YYLTYPE
*) alloca (yystacksize
* sizeof (*yylsp
));
676 __yy_memcpy ((char *)yyls
, (char *)yyls1
, size
* sizeof (*yylsp
));
678 #endif /* no yyoverflow */
680 yyssp
= yyss
+ size
- 1;
681 yyvsp
= yyvs
+ size
- 1;
683 yylsp
= yyls
+ size
- 1;
688 fprintf(stderr
, "Stack size increased to %d\n", yystacksize
);
691 if (yyssp
>= yyss
+ yystacksize
- 1)
697 fprintf(stderr
, "Entering state %d\n", yystate
);
703 /* Do appropriate processing given the current state. */
704 /* Read a lookahead token if we need one and don't already have one. */
707 /* First try to decide what to do without reference to lookahead token. */
709 yyn
= yypact
[yystate
];
713 /* Not known => get a lookahead token if don't already have one. */
715 /* yychar is either YYEMPTY or YYEOF
716 or a valid token in external form. */
718 if (yychar
== YYEMPTY
)
722 fprintf(stderr
, "Reading a token: ");
727 /* Convert token to internal form (in yychar1) for indexing tables with */
729 if (yychar
<= 0) /* This means end of input. */
732 yychar
= YYEOF
; /* Don't call YYLEX any more */
736 fprintf(stderr
, "Now at end of input.\n");
741 yychar1
= YYTRANSLATE(yychar
);
746 fprintf (stderr
, "Next token is %d (%s", yychar
, yytname
[yychar1
]);
747 /* Give the individual parser a way to print the precise meaning
748 of a token, for further debugging info. */
750 YYPRINT (stderr
, yychar
, yylval
);
752 fprintf (stderr
, ")\n");
758 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
763 /* yyn is what to do for this token type in this state.
764 Negative => reduce, -yyn is rule number.
765 Positive => shift, yyn is new state.
766 New state is final state => don't bother to shift,
768 0, or most negative number => error. */
783 /* Shift the lookahead token. */
787 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
790 /* Discard the token being shifted unless it is eof. */
799 /* count tokens shifted since error; after three, turn off error status. */
800 if (yyerrstatus
) yyerrstatus
--;
805 /* Do the default action for the current state. */
808 yyn
= yydefact
[yystate
];
812 /* Do a reduction. yyn is the number of a rule to reduce with. */
816 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
823 fprintf (stderr
, "Reducing via rule %d (line %d), ",
826 /* Print the symbols being reduced, and their result. */
827 for (i
= yyprhs
[yyn
]; yyrhs
[i
] > 0; i
++)
828 fprintf (stderr
, "%s ", yytname
[yyrhs
[i
]]);
829 fprintf (stderr
, " -> %s\n", yytname
[yyr1
[yyn
]]);
839 expression_value
= yyvsp
[0].integer
.value
;
840 #ifdef TEST_EXP_READER
841 expression_signedp
= yyvsp
[0].integer
.signedp
;
848 pedwarn ("comma operator in operand of `#if'");
849 yyval
.integer
= yyvsp
[0].integer
; ;
853 { yyval
.integer
.value
= - yyvsp
[0].integer
.value
;
854 yyval
.integer
.signedp
= yyvsp
[0].integer
.signedp
;
855 if ((yyval
.integer
.value
& yyvsp
[0].integer
.value
& yyval
.integer
.signedp
) < 0)
856 integer_overflow (); ;
860 { yyval
.integer
.value
= ! yyvsp
[0].integer
.value
;
861 yyval
.integer
.signedp
= SIGNED
; ;
865 { yyval
.integer
= yyvsp
[0].integer
; ;
869 { yyval
.integer
.value
= ~ yyvsp
[0].integer
.value
;
870 yyval
.integer
.signedp
= yyvsp
[0].integer
.signedp
; ;
874 { yyval
.integer
.value
= check_assertion (yyvsp
[0].name
.address
, yyvsp
[0].name
.length
,
876 yyval
.integer
.signedp
= SIGNED
; ;
880 { keyword_parsing
= 1; ;
884 { yyval
.integer
.value
= check_assertion (yyvsp
[-4].name
.address
, yyvsp
[-4].name
.length
,
885 1, yyvsp
[-1].keywords
);
887 yyval
.integer
.signedp
= SIGNED
; ;
891 { yyval
.integer
= yyvsp
[-1].integer
; ;
895 { yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
896 if (yyval
.integer
.signedp
)
898 yyval
.integer
.value
= yyvsp
[-2].integer
.value
* yyvsp
[0].integer
.value
;
899 if (yyvsp
[-2].integer
.value
900 && (yyval
.integer
.value
/ yyvsp
[-2].integer
.value
!= yyvsp
[0].integer
.value
901 || (yyval
.integer
.value
& yyvsp
[-2].integer
.value
& yyvsp
[0].integer
.value
) < 0))
905 yyval
.integer
.value
= ((unsigned HOST_WIDEST_INT
) yyvsp
[-2].integer
.value
906 * yyvsp
[0].integer
.value
); ;
910 { if (yyvsp
[0].integer
.value
== 0)
912 if (!skip_evaluation
)
913 error ("division by zero in #if");
914 yyvsp
[0].integer
.value
= 1;
916 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
917 if (yyval
.integer
.signedp
)
919 yyval
.integer
.value
= yyvsp
[-2].integer
.value
/ yyvsp
[0].integer
.value
;
920 if ((yyval
.integer
.value
& yyvsp
[-2].integer
.value
& yyvsp
[0].integer
.value
) < 0)
924 yyval
.integer
.value
= ((unsigned HOST_WIDEST_INT
) yyvsp
[-2].integer
.value
925 / yyvsp
[0].integer
.value
); ;
929 { if (yyvsp
[0].integer
.value
== 0)
931 if (!skip_evaluation
)
932 error ("division by zero in #if");
933 yyvsp
[0].integer
.value
= 1;
935 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
936 if (yyval
.integer
.signedp
)
937 yyval
.integer
.value
= yyvsp
[-2].integer
.value
% yyvsp
[0].integer
.value
;
939 yyval
.integer
.value
= ((unsigned HOST_WIDEST_INT
) yyvsp
[-2].integer
.value
940 % yyvsp
[0].integer
.value
); ;
944 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
+ yyvsp
[0].integer
.value
;
945 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
946 if (overflow_sum_sign (yyvsp
[-2].integer
.value
, yyvsp
[0].integer
.value
,
947 yyval
.integer
.value
, yyval
.integer
.signedp
))
948 integer_overflow (); ;
952 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
- yyvsp
[0].integer
.value
;
953 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
954 if (overflow_sum_sign (yyval
.integer
.value
, yyvsp
[0].integer
.value
,
955 yyvsp
[-2].integer
.value
, yyval
.integer
.signedp
))
956 integer_overflow (); ;
960 { yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
;
961 if ((yyvsp
[0].integer
.value
& yyvsp
[0].integer
.signedp
) < 0)
962 yyval
.integer
.value
= right_shift (&yyvsp
[-2].integer
, -yyvsp
[0].integer
.value
);
964 yyval
.integer
.value
= left_shift (&yyvsp
[-2].integer
, yyvsp
[0].integer
.value
); ;
968 { yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
;
969 if ((yyvsp
[0].integer
.value
& yyvsp
[0].integer
.signedp
) < 0)
970 yyval
.integer
.value
= left_shift (&yyvsp
[-2].integer
, -yyvsp
[0].integer
.value
);
972 yyval
.integer
.value
= right_shift (&yyvsp
[-2].integer
, yyvsp
[0].integer
.value
); ;
976 { yyval
.integer
.value
= (yyvsp
[-2].integer
.value
== yyvsp
[0].integer
.value
);
977 yyval
.integer
.signedp
= SIGNED
; ;
981 { yyval
.integer
.value
= (yyvsp
[-2].integer
.value
!= yyvsp
[0].integer
.value
);
982 yyval
.integer
.signedp
= SIGNED
; ;
986 { yyval
.integer
.signedp
= SIGNED
;
987 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
988 yyval
.integer
.value
= yyvsp
[-2].integer
.value
<= yyvsp
[0].integer
.value
;
990 yyval
.integer
.value
= ((unsigned HOST_WIDEST_INT
) yyvsp
[-2].integer
.value
991 <= yyvsp
[0].integer
.value
); ;
995 { yyval
.integer
.signedp
= SIGNED
;
996 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
997 yyval
.integer
.value
= yyvsp
[-2].integer
.value
>= yyvsp
[0].integer
.value
;
999 yyval
.integer
.value
= ((unsigned HOST_WIDEST_INT
) yyvsp
[-2].integer
.value
1000 >= yyvsp
[0].integer
.value
); ;
1004 { yyval
.integer
.signedp
= SIGNED
;
1005 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
1006 yyval
.integer
.value
= yyvsp
[-2].integer
.value
< yyvsp
[0].integer
.value
;
1008 yyval
.integer
.value
= ((unsigned HOST_WIDEST_INT
) yyvsp
[-2].integer
.value
1009 < yyvsp
[0].integer
.value
); ;
1013 { yyval
.integer
.signedp
= SIGNED
;
1014 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
1015 yyval
.integer
.value
= yyvsp
[-2].integer
.value
> yyvsp
[0].integer
.value
;
1017 yyval
.integer
.value
= ((unsigned HOST_WIDEST_INT
) yyvsp
[-2].integer
.value
1018 > yyvsp
[0].integer
.value
); ;
1022 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
& yyvsp
[0].integer
.value
;
1023 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1027 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
^ yyvsp
[0].integer
.value
;
1028 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1032 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
| yyvsp
[0].integer
.value
;
1033 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1037 { skip_evaluation
+= !yyvsp
[-1].integer
.value
; ;
1041 { skip_evaluation
-= !yyvsp
[-3].integer
.value
;
1042 yyval
.integer
.value
= (yyvsp
[-3].integer
.value
&& yyvsp
[0].integer
.value
);
1043 yyval
.integer
.signedp
= SIGNED
; ;
1047 { skip_evaluation
+= !!yyvsp
[-1].integer
.value
; ;
1051 { skip_evaluation
-= !!yyvsp
[-3].integer
.value
;
1052 yyval
.integer
.value
= (yyvsp
[-3].integer
.value
|| yyvsp
[0].integer
.value
);
1053 yyval
.integer
.signedp
= SIGNED
; ;
1057 { skip_evaluation
+= !yyvsp
[-1].integer
.value
; ;
1061 { skip_evaluation
+= !!yyvsp
[-4].integer
.value
- !yyvsp
[-4].integer
.value
; ;
1065 { skip_evaluation
-= !!yyvsp
[-6].integer
.value
;
1066 yyval
.integer
.value
= yyvsp
[-6].integer
.value
? yyvsp
[-3].integer
.value
: yyvsp
[0].integer
.value
;
1067 yyval
.integer
.signedp
= yyvsp
[-3].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1071 { yyval
.integer
= yylval
.integer
; ;
1075 { yyval
.integer
= yylval
.integer
; ;
1079 { if (warn_undef
&& !skip_evaluation
)
1080 warning ("`%.*s' is not defined",
1081 yyvsp
[0].name
.length
, yyvsp
[0].name
.address
);
1082 yyval
.integer
.value
= 0;
1083 yyval
.integer
.signedp
= SIGNED
; ;
1087 { yyval
.keywords
= 0; ;
1091 { struct arglist
*temp
;
1092 yyval
.keywords
= (struct arglist
*) xmalloc (sizeof (struct arglist
));
1093 yyval
.keywords
->next
= yyvsp
[-2].keywords
;
1094 yyval
.keywords
->name
= (U_CHAR
*) "(";
1095 yyval
.keywords
->length
= 1;
1096 temp
= yyval
.keywords
;
1097 while (temp
!= 0 && temp
->next
!= 0)
1099 temp
->next
= (struct arglist
*) xmalloc (sizeof (struct arglist
));
1100 temp
->next
->next
= yyvsp
[0].keywords
;
1101 temp
->next
->name
= (U_CHAR
*) ")";
1102 temp
->next
->length
= 1; ;
1106 { yyval
.keywords
= (struct arglist
*) xmalloc (sizeof (struct arglist
));
1107 yyval
.keywords
->name
= yyvsp
[-1].name
.address
;
1108 yyval
.keywords
->length
= yyvsp
[-1].name
.length
;
1109 yyval
.keywords
->next
= yyvsp
[0].keywords
; ;
1112 /* the action file gets copied in in place of this dollarsign */
1113 #line 498 "/tmp/sky/share/bison.simple"
1124 short *ssp1
= yyss
- 1;
1125 fprintf (stderr
, "state stack now");
1126 while (ssp1
!= yyssp
)
1127 fprintf (stderr
, " %d", *++ssp1
);
1128 fprintf (stderr
, "\n");
1138 yylsp
->first_line
= yylloc
.first_line
;
1139 yylsp
->first_column
= yylloc
.first_column
;
1140 yylsp
->last_line
= (yylsp
-1)->last_line
;
1141 yylsp
->last_column
= (yylsp
-1)->last_column
;
1146 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
1147 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
1151 /* Now "shift" the result of the reduction.
1152 Determine what state that goes to,
1153 based on the state we popped back to
1154 and the rule number reduced by. */
1158 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
1159 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1160 yystate
= yytable
[yystate
];
1162 yystate
= yydefgoto
[yyn
- YYNTBASE
];
1166 yyerrlab
: /* here on detecting error */
1169 /* If not already recovering from an error, report this error. */
1173 #ifdef YYERROR_VERBOSE
1174 yyn
= yypact
[yystate
];
1176 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
1183 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1184 for (x
= (yyn
< 0 ? -yyn
: 0);
1185 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
1186 if (yycheck
[x
+ yyn
] == x
)
1187 size
+= strlen(yytname
[x
]) + 15, count
++;
1188 msg
= (char *) malloc(size
+ 15);
1191 strcpy(msg
, "parse error");
1196 for (x
= (yyn
< 0 ? -yyn
: 0);
1197 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
1198 if (yycheck
[x
+ yyn
] == x
)
1200 strcat(msg
, count
== 0 ? ", expecting `" : " or `");
1201 strcat(msg
, yytname
[x
]);
1210 yyerror ("parse error; also virtual memory exceeded");
1213 #endif /* YYERROR_VERBOSE */
1214 yyerror("parse error");
1218 yyerrlab1
: /* here on error raised explicitly by an action */
1220 if (yyerrstatus
== 3)
1222 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1224 /* return failure if at end of input */
1225 if (yychar
== YYEOF
)
1230 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
1236 /* Else will try to reuse lookahead token
1237 after shifting the error token. */
1239 yyerrstatus
= 3; /* Each real token shifted decrements this */
1243 yyerrdefault
: /* current state does not do anything special for the error token. */
1246 /* This is wrong; only states that explicitly want error tokens
1247 should shift them. */
1248 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1249 if (yyn
) goto yydefault
;
1252 yyerrpop
: /* pop the current state because it cannot handle the error token */
1254 if (yyssp
== yyss
) YYABORT
;
1264 short *ssp1
= yyss
- 1;
1265 fprintf (stderr
, "Error: state stack now");
1266 while (ssp1
!= yyssp
)
1267 fprintf (stderr
, " %d", *++ssp1
);
1268 fprintf (stderr
, "\n");
1274 yyn
= yypact
[yystate
];
1279 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
1298 fprintf(stderr
, "Shifting error token, ");
1312 /* During parsing of a C expression, the pointer to the next character
1313 is in this variable. */
1315 static char *lexptr
;
1317 /* Take care of parsing a number (anything that starts with a digit).
1318 Set yylval and return the token type; update lexptr.
1319 LEN is the number of characters in it. */
1321 /* maybe needs to actually deal with floating point numbers */
1327 register char *p
= lexptr
;
1329 register unsigned HOST_WIDEST_INT n
= 0, nd
, max_over_base
;
1330 register int base
= 10;
1331 register int len
= olen
;
1332 register int overflow
= 0;
1333 register int digit
, largest_digit
= 0;
1336 yylval
.integer
.signedp
= SIGNED
;
1340 if (len
>= 3 && (p
[1] == 'x' || p
[1] == 'X')) {
1347 max_over_base
= (unsigned HOST_WIDEST_INT
) -1 / base
;
1349 for (; len
> 0; len
--) {
1352 if (c
>= '0' && c
<= '9')
1354 else if (base
== 16 && c
>= 'a' && c
<= 'f')
1355 digit
= c
- 'a' + 10;
1356 else if (base
== 16 && c
>= 'A' && c
<= 'F')
1357 digit
= c
- 'A' + 10;
1359 /* `l' means long, and `u' means unsigned. */
1361 if (c
== 'l' || c
== 'L')
1363 if (!pedantic
< spec_long
)
1364 yyerror ("too many `l's in integer constant");
1367 else if (c
== 'u' || c
== 'U')
1369 if (! yylval
.integer
.signedp
)
1370 yyerror ("two `u's in integer constant");
1371 yylval
.integer
.signedp
= UNSIGNED
;
1374 if (c
== '.' || c
== 'e' || c
== 'E' || c
== 'p' || c
== 'P')
1375 yyerror ("Floating point numbers not allowed in #if expressions");
1377 yyerror ("missing white space after number `%.*s'",
1378 (int) (p
- lexptr
- 1), lexptr
);
1385 /* Don't look for any more digits after the suffixes. */
1388 if (largest_digit
< digit
)
1389 largest_digit
= digit
;
1390 nd
= n
* base
+ digit
;
1391 overflow
|= (max_over_base
< n
) | (nd
< n
);
1395 if (base
<= largest_digit
)
1396 pedwarn ("integer constant contains digits beyond the radix");
1399 pedwarn ("integer constant out of range");
1401 /* If too big to be signed, consider it unsigned. */
1402 if (((HOST_WIDEST_INT
) n
& yylval
.integer
.signedp
) < 0)
1405 warning ("integer constant is so large that it is unsigned");
1406 yylval
.integer
.signedp
= UNSIGNED
;
1410 yylval
.integer
.value
= n
;
1415 const char *operator;
1419 static struct token tokentab2
[] = {
1433 /* Read one token, getting characters through lexptr. */
1439 register int namelen
;
1440 register unsigned char *tokstart
;
1441 register struct token
*toktab
;
1443 HOST_WIDEST_INT mask
;
1447 tokstart
= (unsigned char *) lexptr
;
1449 /* See if it is a special token of length 2. */
1450 if (! keyword_parsing
)
1451 for (toktab
= tokentab2
; toktab
->operator != NULL
; toktab
++)
1452 if (c
== *toktab
->operator && tokstart
[1] == toktab
->operator[1]) {
1454 if (toktab
->token
== ERROR
)
1455 yyerror ("`%s' not allowed in operand of `#if'", toktab
->operator);
1456 return toktab
->token
;
1470 /* Capital L may start a wide-string or wide-character constant. */
1471 if (lexptr
[1] == '\'')
1475 mask
= MAX_WCHAR_TYPE_MASK
;
1478 if (lexptr
[1] == '"')
1482 mask
= MAX_WCHAR_TYPE_MASK
;
1483 goto string_constant
;
1489 mask
= MAX_CHAR_TYPE_MASK
;
1492 if (keyword_parsing
) {
1493 char *start_ptr
= lexptr
- 1;
1497 c
= parse_escape (&lexptr
, mask
);
1501 yylval
.name
.address
= tokstart
;
1502 yylval
.name
.length
= lexptr
- start_ptr
;
1506 /* This code for reading a character constant
1507 handles multicharacter constants and wide characters.
1508 It is mostly copied from c-lex.c. */
1510 register HOST_WIDEST_INT result
= 0;
1511 register int num_chars
= 0;
1513 unsigned width
= MAX_CHAR_TYPE_SIZE
;
1515 #ifdef MULTIBYTE_CHARS
1516 int longest_char
= local_mb_cur_max ();
1517 char *token_buffer
= (char *) alloca (longest_char
);
1518 (void) local_mbtowc (NULL_PTR
, NULL_PTR
, 0);
1521 max_chars
= MAX_LONG_TYPE_SIZE
/ width
;
1523 width
= MAX_WCHAR_TYPE_SIZE
;
1529 if (c
== '\'' || c
== EOF
)
1535 c
= parse_escape (&lexptr
, mask
);
1539 #ifdef MULTIBYTE_CHARS
1543 for (i
= 1; i
<= longest_char
; ++i
)
1545 token_buffer
[i
- 1] = c
;
1546 char_len
= local_mbtowc (& wc
, token_buffer
, i
);
1553 /* mbtowc sometimes needs an extra char before accepting */
1558 /* Merge character into result; ignore excess chars. */
1559 for (i
= 1; i
<= char_len
; ++i
)
1563 if (width
< HOST_BITS_PER_INT
)
1564 result
= (result
<< width
)
1565 | (token_buffer
[i
- 1]
1566 & ((1 << width
) - 1));
1568 result
= token_buffer
[i
- 1];
1570 num_chars
+= char_len
;
1577 warning ("Ignoring invalid multibyte character");
1581 #endif /* ! MULTIBYTE_CHARS */
1586 if (chars_seen
== 1) /* only keep the first one */
1591 /* Merge character into result; ignore excess chars. */
1593 if (num_chars
<= max_chars
)
1595 if (width
< HOST_BITS_PER_INT
)
1596 result
= (result
<< width
) | (c
& ((1 << width
) - 1));
1603 error ("malformatted character constant");
1604 else if (chars_seen
== 0)
1605 error ("empty character constant");
1606 else if (num_chars
> max_chars
)
1608 num_chars
= max_chars
;
1609 error ("character constant too long");
1611 else if (chars_seen
!= 1 && ! traditional
)
1612 warning ("multi-character character constant");
1614 /* If char type is signed, sign-extend the constant. */
1617 int num_bits
= num_chars
* width
;
1619 /* We already got an error; avoid invalid shift. */
1620 yylval
.integer
.value
= 0;
1621 else if (lookup ((U_CHAR
*) "__CHAR_UNSIGNED__",
1622 sizeof ("__CHAR_UNSIGNED__") - 1, -1)
1623 || ((result
>> (num_bits
- 1)) & 1) == 0)
1624 yylval
.integer
.value
1625 = result
& (~ (unsigned HOST_WIDEST_INT
) 0
1626 >> (HOST_BITS_PER_WIDEST_INT
- num_bits
));
1628 yylval
.integer
.value
1629 = result
| ~(~ (unsigned HOST_WIDEST_INT
) 0
1630 >> (HOST_BITS_PER_WIDEST_INT
- num_bits
));
1634 yylval
.integer
.value
= result
;
1638 /* This is always a signed type. */
1639 yylval
.integer
.signedp
= SIGNED
;
1643 /* some of these chars are invalid in constant expressions;
1644 maybe do something about them later */
1668 if (keyword_parsing
)
1676 mask
= MAX_CHAR_TYPE_MASK
;
1678 if (keyword_parsing
) {
1679 char *start_ptr
= lexptr
;
1684 c
= parse_escape (&lexptr
, mask
);
1688 yylval
.name
.address
= tokstart
;
1689 yylval
.name
.length
= lexptr
- start_ptr
;
1692 yyerror ("string constants not allowed in #if expressions");
1696 if (c
>= '0' && c
<= '9' && !keyword_parsing
) {
1698 for (namelen
= 1; ; namelen
++) {
1699 int d
= tokstart
[namelen
];
1700 if (! ((is_idchar
[d
] || d
== '.')
1701 || ((d
== '-' || d
== '+')
1702 && (c
== 'e' || c
== 'E'
1703 || ((c
== 'p' || c
== 'P') && ! c89
))
1708 return parse_number (namelen
);
1711 /* It is a name. See how long it is. */
1713 if (keyword_parsing
) {
1714 for (namelen
= 0;; namelen
++) {
1715 if (is_space
[tokstart
[namelen
]])
1717 if (tokstart
[namelen
] == '(' || tokstart
[namelen
] == ')')
1719 if (tokstart
[namelen
] == '"' || tokstart
[namelen
] == '\'')
1723 if (!is_idstart
[c
]) {
1724 yyerror ("Invalid token in expression");
1728 for (namelen
= 0; is_idchar
[tokstart
[namelen
]]; namelen
++)
1733 yylval
.name
.address
= tokstart
;
1734 yylval
.name
.length
= namelen
;
1739 /* Parse a C escape sequence. STRING_PTR points to a variable
1740 containing a pointer to the string to parse. That pointer
1741 is updated past the characters we use. The value of the
1742 escape sequence is returned.
1744 RESULT_MASK is used to mask out the result;
1745 an error is reported if bits are lost thereby.
1747 A negative value means the sequence \ newline was seen,
1748 which is supposed to be equivalent to nothing at all.
1750 If \ is followed by a null character, we return a negative
1751 value and leave the string pointer pointing at the null character.
1753 If \ is followed by 000, we return 0 and leave the string pointer
1754 after the zeros. A value of 0 does not mean end of string. */
1757 parse_escape (string_ptr
, result_mask
)
1759 HOST_WIDEST_INT result_mask
;
1761 register int c
= *(*string_ptr
)++;
1771 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c
);
1776 return TARGET_NEWLINE
;
1798 register HOST_WIDEST_INT i
= c
- '0';
1799 register int count
= 0;
1802 c
= *(*string_ptr
)++;
1803 if (c
>= '0' && c
<= '7')
1804 i
= (i
<< 3) + c
- '0';
1811 if (i
!= (i
& result_mask
))
1814 pedwarn ("octal escape sequence out of range");
1820 register unsigned HOST_WIDEST_INT i
= 0, overflow
= 0;
1821 register int digits_found
= 0, digit
;
1824 c
= *(*string_ptr
)++;
1825 if (c
>= '0' && c
<= '9')
1827 else if (c
>= 'a' && c
<= 'f')
1828 digit
= c
- 'a' + 10;
1829 else if (c
>= 'A' && c
<= 'F')
1830 digit
= c
- 'A' + 10;
1836 overflow
|= i
^ (i
<< 4 >> 4);
1837 i
= (i
<< 4) + digit
;
1841 yyerror ("\\x used with no following hex digits");
1842 if (overflow
| (i
!= (i
& result_mask
)))
1845 pedwarn ("hex escape sequence out of range");
1857 if (!skip_evaluation
&& pedantic
)
1858 pedwarn ("integer overflow in preprocessor expression");
1861 static HOST_WIDEST_INT
1864 unsigned HOST_WIDEST_INT b
;
1866 /* It's unclear from the C standard whether shifts can overflow.
1867 The following code ignores overflow; perhaps a C standard
1868 interpretation ruling is needed. */
1869 if (b
>= HOST_BITS_PER_WIDEST_INT
)
1872 return (unsigned HOST_WIDEST_INT
) a
->value
<< b
;
1875 static HOST_WIDEST_INT
1878 unsigned HOST_WIDEST_INT b
;
1880 if (b
>= HOST_BITS_PER_WIDEST_INT
)
1881 return a
->signedp
? a
->value
>> (HOST_BITS_PER_WIDEST_INT
- 1) : 0;
1882 else if (a
->signedp
)
1883 return a
->value
>> b
;
1885 return (unsigned HOST_WIDEST_INT
) a
->value
>> b
;
1888 /* This page contains the entry point to this file. */
1890 /* Parse STRING as an expression, and complain if this fails
1891 to use up all of the contents of STRING.
1892 STRING may contain '\0' bytes; it is terminated by the first '\n'
1893 outside a string constant, so that we can diagnose '\0' properly.
1894 If WARN_UNDEFINED is nonzero, warn if undefined identifiers are evaluated.
1895 We do not support C comments. They should be removed before
1896 this function is called. */
1899 parse_c_expression (string
, warn_undefined
)
1904 warn_undef
= warn_undefined
;
1906 /* if there is some sort of scanning error, just return 0 and assume
1907 the parsing routine has printed an error message somewhere.
1908 there is surely a better thing to do than this. */
1909 if (setjmp (parse_return_error
))
1912 if (yyparse () != 0)
1915 if (*lexptr
!= '\n')
1916 error ("Junk after end of expression.");
1918 return expression_value
; /* set by yyparse () */
1922 yyerror
VPROTO ((const char * msgid
, ...))
1924 #ifndef ANSI_PROTOTYPES
1929 VA_START (args
, msgid
);
1931 #ifndef ANSI_PROTOTYPES
1932 msgid
= va_arg (args
, const char *);
1935 verror (msgid
, args
);
1937 skip_evaluation
= 0;
1938 longjmp (parse_return_error
, 1);
1942 #ifdef TEST_EXP_READER
1952 int main
PROTO((int, char **));
1953 static void initialize_random_junk
PROTO((void));
1954 static void print_unsigned_host_widest_int
PROTO((unsigned HOST_WIDEST_INT
));
1956 /* Main program for testing purposes. */
1964 unsigned HOST_WIDEST_INT u
;
1966 pedantic
= 1 < argc
;
1967 traditional
= 2 < argc
;
1972 initialize_random_junk ();
1975 printf ("enter expression: ");
1977 while ((buf
[n
] = c
= getchar ()) != '\n' && c
!= EOF
)
1981 parse_c_expression (buf
, 1);
1982 printf ("parser returned ");
1983 u
= (unsigned HOST_WIDEST_INT
) expression_value
;
1984 if (expression_value
< 0 && expression_signedp
) {
1991 print_unsigned_host_widest_int (u
);
1992 if (! expression_signedp
)
2001 print_unsigned_host_widest_int (u
)
2002 unsigned HOST_WIDEST_INT u
;
2005 print_unsigned_host_widest_int (u
/ 10);
2006 putchar ('0' + (int) (u
% 10));
2010 /* table to tell if char can be part of a C identifier. */
2011 unsigned char is_idchar
[256];
2012 /* table to tell if char can be first char of a c identifier. */
2013 unsigned char is_idstart
[256];
2014 /* table to tell if c is horizontal or vertical space. */
2015 unsigned char is_space
[256];
2018 * initialize random junk in the hash table and maybe other places
2021 initialize_random_junk ()
2026 * Set up is_idchar and is_idstart tables. These should be
2027 * faster than saying (is_alpha (c) || c == '_'), etc.
2028 * Must do set up these things before calling any routines tthat
2031 for (i
= 'a'; i
<= 'z'; i
++) {
2032 ++is_idchar
[i
- 'a' + 'A'];
2034 ++is_idstart
[i
- 'a' + 'A'];
2037 for (i
= '0'; i
<= '9'; i
++)
2053 error
VPROTO ((char * msgid
, ...))
2055 #ifndef ANSI_PROTOTYPES
2060 VA_START (args
, msgid
);
2062 #ifndef ANSI_PROTOTYPES
2063 msgid
= va_arg (args
, char *);
2066 fprintf (stderr
, "error: ");
2067 vfprintf (stderr
, _(msgid
), args
);
2068 fprintf (stderr
, "\n");
2073 pedwarn
VPROTO ((char * msgid
, ...))
2075 #ifndef ANSI_PROTOTYPES
2080 VA_START (args
, msgid
);
2082 #ifndef ANSI_PROTOTYPES
2083 msgid
= va_arg (args
, char *);
2086 fprintf (stderr
, "pedwarn: ");
2087 vfprintf (stderr
, _(msgid
), args
);
2088 fprintf (stderr
, "\n");
2093 warning
VPROTO ((char * msgid
, ...))
2095 #ifndef ANSI_PROTOTYPES
2100 VA_START (args
, msgid
);
2102 #ifndef ANSI_PROTOTYPES
2103 msgid
= va_arg (args
, char *);
2106 fprintf (stderr
, "warning: ");
2107 vfprintf (stderr
, _(msgid
), args
);
2108 fprintf (stderr
, "\n");
2114 check_assertion (name
, sym_length
, tokens_specified
, tokens
)
2117 int tokens_specified
;
2118 struct arglist
*tokens
;
2124 lookup (name
, len
, hash
)
2129 return (DEFAULT_SIGNED_CHAR
) ? 0 : ((struct hashnode
*) -1);
2136 return (PTR
) malloc (size
);