2 /* A Bison parser, made from cexp.y with Bison version GNU Bison version 1.24
5 #define YYBISON 1 /* Identify Bison output. */
25 /* #define YYDEBUG 1 */
27 /* The following symbols should be autoconfigured:
30 In the mean time, we'll get by with approximations based
31 on existing GCC configuration symbols. */
34 # ifndef HAVE_STDLIB_H
35 # define HAVE_STDLIB_H 1
38 # define STDC_HEADERS 1
40 #endif /* defined (POSIX) */
46 #if HAVE_STDLIB_H || defined (MULTIBYTE_CHARS)
50 #ifdef MULTIBYTE_CHARS
56 typedef unsigned char U_CHAR
;
58 /* This is used for communicating lists of keywords with cccp.c. */
66 /* Define a generic NULL if one hasn't already been defined. */
73 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
74 #define GENERIC_PTR void *
76 #define GENERIC_PTR char *
81 #define NULL_PTR ((GENERIC_PTR) 0)
84 /* Find the largest host integer type and set its size and type.
85 Don't blindly use `long'; on some crazy hosts it is shorter than `int'. */
87 #ifndef HOST_BITS_PER_WIDE_INT
89 #if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
90 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
91 #define HOST_WIDE_INT long
93 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
94 #define HOST_WIDE_INT int
99 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
100 # define __attribute__(x)
104 # if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
105 # define PROTO(ARGS) ARGS
107 # define PROTO(ARGS) ()
111 #if defined (__STDC__) && defined (HAVE_VPRINTF)
113 # define VA_START(va_list, var) va_start (va_list, var)
114 # define PRINTF_ALIST(msg) char *msg, ...
115 # define PRINTF_DCL(msg)
116 # define PRINTF_PROTO(ARGS, m, n) PROTO (ARGS) __attribute__ ((format (__printf__, m, n)))
118 # include <varargs.h>
119 # define VA_START(va_list, var) va_start (va_list)
120 # define PRINTF_ALIST(msg) msg, va_alist
121 # define PRINTF_DCL(msg) char *msg; va_dcl
122 # define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (__printf__, m, n)))
123 # define vfprintf(file, msg, args) \
125 char *a0 = va_arg(args, char *); \
126 char *a1 = va_arg(args, char *); \
127 char *a2 = va_arg(args, char *); \
128 char *a3 = va_arg(args, char *); \
129 fprintf (file, msg, a0, a1, a2, a3); \
133 #define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2)
135 HOST_WIDE_INT parse_c_expression
PROTO((char *));
137 static int yylex
PROTO((void));
138 static void yyerror
PROTO((char *)) __attribute__ ((noreturn
));
139 static HOST_WIDE_INT expression_value
;
141 static jmp_buf parse_return_error
;
143 /* Nonzero means count most punctuation as part of a name. */
144 static int keyword_parsing
= 0;
146 /* Nonzero means do not evaluate this expression.
147 This is a count, since unevaluated expressions can nest. */
148 static int skip_evaluation
;
150 /* some external tables of character types */
151 extern unsigned char is_idstart
[], is_idchar
[], is_space
[];
153 /* Flag for -pedantic. */
156 /* Flag for -traditional. */
157 extern int traditional
;
159 /* Flag for -lang-c89. */
162 /* Flag for -Wundef. */
163 extern int warn_undef
;
165 #ifndef CHAR_TYPE_SIZE
166 #define CHAR_TYPE_SIZE BITS_PER_UNIT
169 #ifndef INT_TYPE_SIZE
170 #define INT_TYPE_SIZE BITS_PER_WORD
173 #ifndef LONG_TYPE_SIZE
174 #define LONG_TYPE_SIZE BITS_PER_WORD
177 #ifndef WCHAR_TYPE_SIZE
178 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
181 #ifndef MAX_CHAR_TYPE_SIZE
182 #define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE
185 #ifndef MAX_INT_TYPE_SIZE
186 #define MAX_INT_TYPE_SIZE INT_TYPE_SIZE
189 #ifndef MAX_LONG_TYPE_SIZE
190 #define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE
193 #ifndef MAX_WCHAR_TYPE_SIZE
194 #define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
197 #if MAX_CHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT
198 #define MAX_CHAR_TYPE_MASK (~ (~ (HOST_WIDE_INT) 0 << MAX_CHAR_TYPE_SIZE))
200 #define MAX_CHAR_TYPE_MASK (~ (HOST_WIDE_INT) 0)
203 #if MAX_WCHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT
204 #define MAX_WCHAR_TYPE_MASK (~ (~ (HOST_WIDE_INT) 0 << MAX_WCHAR_TYPE_SIZE))
206 #define MAX_WCHAR_TYPE_MASK (~ (HOST_WIDE_INT) 0)
209 /* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
210 Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
211 Suppose SIGNEDP is negative if the result is signed, zero if unsigned.
212 Then this yields nonzero if overflow occurred during the addition.
213 Overflow occurs if A and B have the same sign, but A and SUM differ in sign,
214 and SIGNEDP is negative.
215 Use `^' to test whether signs differ, and `< 0' to isolate the sign. */
216 #define overflow_sum_sign(a, b, sum, signedp) \
217 ((~((a) ^ (b)) & ((a) ^ (sum)) & (signedp)) < 0)
221 GENERIC_PTR xmalloc
PROTO((size_t));
222 HOST_WIDE_INT parse_escape
PROTO((char **, HOST_WIDE_INT
));
223 int check_assertion
PROTO((U_CHAR
*, int, int, struct arglist
*));
224 struct hashnode
*lookup
PROTO((U_CHAR
*, int, int));
225 void error
PRINTF_PROTO_1((char *, ...));
226 void pedwarn
PRINTF_PROTO_1((char *, ...));
227 void warning
PRINTF_PROTO_1((char *, ...));
229 static int parse_number
PROTO((int));
230 static HOST_WIDE_INT left_shift
PROTO((struct constant
*, unsigned HOST_WIDE_INT
));
231 static HOST_WIDE_INT right_shift
PROTO((struct constant
*, unsigned HOST_WIDE_INT
));
232 static void integer_overflow
PROTO((void));
234 /* `signedp' values */
240 struct constant
{HOST_WIDE_INT value
; int signedp
;} integer
;
241 struct name
{U_CHAR
*address
; int length
;} name
;
242 struct arglist
*keywords
;
258 #define YYLTYPE yyltype
272 #define YYFLAG -32768
275 #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 43)
277 static const char yytranslate
[] = { 0,
278 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
279 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
280 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
281 2, 2, 29, 2, 31, 2, 27, 14, 2, 32,
282 33, 25, 23, 9, 24, 2, 26, 2, 2, 2,
283 2, 2, 2, 2, 2, 2, 2, 8, 2, 17,
284 2, 18, 7, 2, 2, 2, 2, 2, 2, 2,
285 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
286 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
287 2, 2, 2, 13, 2, 2, 2, 2, 2, 2,
288 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
289 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
290 2, 2, 2, 12, 2, 30, 2, 2, 2, 2,
291 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
292 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
293 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
294 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
295 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
296 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
297 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
298 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
299 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
300 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
301 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
302 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
303 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
304 6, 10, 11, 15, 16, 19, 20, 21, 22, 28
308 static const short yyprhs
[] = { 0,
309 0, 2, 4, 8, 11, 14, 17, 20, 23, 24,
310 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
311 71, 75, 79, 83, 87, 91, 95, 99, 100, 105,
312 106, 111, 112, 113, 121, 123, 125, 127, 128, 133
315 static const short yyrhs
[] = { 35,
316 0, 36, 0, 35, 9, 36, 0, 24, 36, 0,
317 29, 36, 0, 23, 36, 0, 30, 36, 0, 31,
318 5, 0, 0, 31, 5, 37, 32, 42, 33, 0,
319 32, 35, 33, 0, 36, 25, 36, 0, 36, 26,
320 36, 0, 36, 27, 36, 0, 36, 23, 36, 0,
321 36, 24, 36, 0, 36, 21, 36, 0, 36, 22,
322 36, 0, 36, 15, 36, 0, 36, 16, 36, 0,
323 36, 19, 36, 0, 36, 20, 36, 0, 36, 17,
324 36, 0, 36, 18, 36, 0, 36, 14, 36, 0,
325 36, 13, 36, 0, 36, 12, 36, 0, 0, 36,
326 11, 38, 36, 0, 0, 36, 10, 39, 36, 0,
327 0, 0, 36, 7, 40, 36, 8, 41, 36, 0,
328 3, 0, 4, 0, 5, 0, 0, 32, 42, 33,
335 static const short yyrline
[] = { 0,
336 274, 279, 280, 287, 292, 295, 297, 300, 304, 306,
337 311, 316, 329, 346, 359, 365, 371, 377, 383, 386,
338 389, 396, 403, 410, 417, 420, 423, 426, 429, 432,
339 435, 438, 440, 443, 446, 448, 450, 458, 460, 473
342 static const char * const yytname
[] = { "$","error","$undefined.","INT","CHAR",
343 "NAME","ERROR","'?'","':'","','","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL",
344 "'<'","'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'","UNARY","'!'",
345 "'~'","'#'","'('","')'","start","exp1","exp","@1","@2","@3","@4","@5","keywords",
350 static const short yyr1
[] = { 0,
351 34, 35, 35, 36, 36, 36, 36, 36, 37, 36,
352 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
353 36, 36, 36, 36, 36, 36, 36, 38, 36, 39,
354 36, 40, 41, 36, 36, 36, 36, 42, 42, 42
357 static const short yyr2
[] = { 0,
358 1, 1, 3, 2, 2, 2, 2, 2, 0, 6,
359 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
360 3, 3, 3, 3, 3, 3, 3, 0, 4, 0,
361 4, 0, 0, 7, 1, 1, 1, 0, 4, 2
364 static const short yydefact
[] = { 0,
365 35, 36, 37, 0, 0, 0, 0, 0, 0, 1,
366 2, 6, 4, 5, 7, 8, 0, 0, 32, 30,
367 28, 0, 0, 0, 0, 0, 0, 0, 0, 0,
368 0, 0, 0, 0, 0, 0, 0, 0, 11, 3,
369 0, 0, 0, 27, 26, 25, 19, 20, 23, 24,
370 21, 22, 17, 18, 15, 16, 12, 13, 14, 38,
371 0, 31, 29, 38, 38, 0, 33, 40, 0, 10,
372 0, 38, 34, 39, 0, 0, 0
375 static const short yydefgoto
[] = { 75,
376 10, 11, 38, 43, 42, 41, 71, 66
379 static const short yypact
[] = { 12,
380 -32768,-32768,-32768, 12, 12, 12, 12, 1, 12, 4,
381 79,-32768,-32768,-32768,-32768, -21, 31, 12,-32768,-32768,
382 -32768, 12, 12, 12, 12, 12, 12, 12, 12, 12,
383 12, 12, 12, 12, 12, 12, 12, 30,-32768, 79,
384 12, 12, 12, 110, 124, 137, 148, 148, 155, 155,
385 155, 155, 160, 160, -17, -17,-32768,-32768,-32768, 2,
386 58, 34, 95, 2, 2, 54,-32768,-32768, 55,-32768,
387 12, 2, 79,-32768, 63, 188,-32768
390 static const short yypgoto
[] = {-32768,
391 180, -4,-32768,-32768,-32768,-32768,-32768, -60
398 static const short yytable
[] = { 12,
399 13, 14, 15, 68, 69, 16, 64, 35, 36, 37,
400 -9, 74, 18, 40, 1, 2, 3, 44, 45, 46,
401 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
402 57, 58, 59, 65, 4, 5, 61, 62, 63, 18,
403 6, 7, 8, 9, 21, 22, 23, 24, 25, 26,
404 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
405 37, 60, 76, 39, 19, 67, 73, 20, 21, 22,
406 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
407 33, 34, 35, 36, 37, 19, 70, 72, 20, 21,
408 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
409 32, 33, 34, 35, 36, 37, 22, 23, 24, 25,
410 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
411 36, 37, 23, 24, 25, 26, 27, 28, 29, 30,
412 31, 32, 33, 34, 35, 36, 37, 24, 25, 26,
413 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
414 37, 25, 26, 27, 28, 29, 30, 31, 32, 33,
415 34, 35, 36, 37, 27, 28, 29, 30, 31, 32,
416 33, 34, 35, 36, 37, 31, 32, 33, 34, 35,
417 36, 37, 33, 34, 35, 36, 37, 77, 17
420 static const short yycheck
[] = { 4,
421 5, 6, 7, 64, 65, 5, 5, 25, 26, 27,
422 32, 72, 9, 18, 3, 4, 5, 22, 23, 24,
423 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
424 35, 36, 37, 32, 23, 24, 41, 42, 43, 9,
425 29, 30, 31, 32, 11, 12, 13, 14, 15, 16,
426 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
427 27, 32, 0, 33, 7, 8, 71, 10, 11, 12,
428 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
429 23, 24, 25, 26, 27, 7, 33, 33, 10, 11,
430 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
431 22, 23, 24, 25, 26, 27, 12, 13, 14, 15,
432 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
433 26, 27, 13, 14, 15, 16, 17, 18, 19, 20,
434 21, 22, 23, 24, 25, 26, 27, 14, 15, 16,
435 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
436 27, 15, 16, 17, 18, 19, 20, 21, 22, 23,
437 24, 25, 26, 27, 17, 18, 19, 20, 21, 22,
438 23, 24, 25, 26, 27, 21, 22, 23, 24, 25,
439 26, 27, 23, 24, 25, 26, 27, 0, 9
441 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
442 #line 3 "/usr/local/share/bison.simple"
444 /* Skeleton output parser for bison,
445 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
447 This program is free software; you can redistribute it and/or modify
448 it under the terms of the GNU General Public License as published by
449 the Free Software Foundation; either version 2, or (at your option)
452 This program is distributed in the hope that it will be useful,
453 but WITHOUT ANY WARRANTY; without even the implied warranty of
454 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
455 GNU General Public License for more details.
457 You should have received a copy of the GNU General Public License
458 along with this program; if not, write to the Free Software
459 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
461 /* As a special exception, when this file is copied by Bison into a
462 Bison output file, you may use that output file without restriction.
463 This special exception was added by the Free Software Foundation
464 in version 1.24 of Bison. */
468 #define alloca __builtin_alloca
469 #else /* not GNU C. */
470 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
472 #else /* not sparc */
473 #if defined (MSDOS) && !defined (__TURBOC__)
475 #else /* not MSDOS, or __TURBOC__ */
479 #else /* not MSDOS, __TURBOC__, or _AIX */
483 void *alloca (unsigned int);
485 #else /* not __cplusplus */
487 #endif /* not __cplusplus */
489 #endif /* not _AIX */
490 #endif /* not MSDOS, or __TURBOC__ */
491 #endif /* not sparc. */
492 #endif /* not GNU C. */
493 #endif /* alloca not defined. */
495 /* This is the parser code that is written into each bison parser
496 when the %semantic_parser declaration is not specified in the grammar.
497 It was written by Richard Stallman by simplifying the hairy parser
498 used when %semantic_parser is specified. */
500 /* Note: there must be only one dollar sign in this file.
501 It is replaced by the list of actions, each action
502 as one case of the switch. */
504 #define yyerrok (yyerrstatus = 0)
505 #define yyclearin (yychar = YYEMPTY)
508 #define YYACCEPT return(0)
509 #define YYABORT return(1)
510 #define YYERROR goto yyerrlab1
511 /* Like YYERROR except do call yyerror.
512 This remains here temporarily to ease the
513 transition to the new meaning of YYERROR, for GCC.
514 Once GCC version 2 has supplanted version 1, this can go. */
515 #define YYFAIL goto yyerrlab
516 #define YYRECOVERING() (!!yyerrstatus)
517 #define YYBACKUP(token, value) \
519 if (yychar == YYEMPTY && yylen == 1) \
520 { yychar = (token), yylval = (value); \
521 yychar1 = YYTRANSLATE (yychar); \
526 { yyerror ("syntax error: cannot back up"); YYERROR; } \
530 #define YYERRCODE 256
533 #define YYLEX yylex()
539 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
541 #define YYLEX yylex(&yylval, &yylloc)
543 #else /* not YYLSP_NEEDED */
545 #define YYLEX yylex(&yylval, YYLEX_PARAM)
547 #define YYLEX yylex(&yylval)
549 #endif /* not YYLSP_NEEDED */
552 /* If nonreentrant, generate the variables here */
556 int yychar
; /* the lookahead symbol */
557 YYSTYPE yylval
; /* the semantic value of the */
558 /* lookahead symbol */
561 YYLTYPE yylloc
; /* location data for the lookahead */
565 int yynerrs
; /* number of parse errors so far */
566 #endif /* not YYPURE */
569 int yydebug
; /* nonzero means print parse trace */
570 /* Since this is uninitialized, it does not stop multiple parsers
574 /* YYINITDEPTH indicates the initial size of the parser's stacks */
577 #define YYINITDEPTH 200
580 /* YYMAXDEPTH is the maximum size the stacks can grow to
581 (effective only if the built-in stack extension method is used). */
588 #define YYMAXDEPTH 10000
591 /* Prevent warning if -Wstrict-prototypes. */
596 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
597 #define __yy_memcpy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
598 #else /* not GNU C or C++ */
601 /* This is the most reliable way to avoid incompatibilities
602 in available built-in functions on various systems. */
604 __yy_memcpy (from
, to
, count
)
609 register char *f
= from
;
610 register char *t
= to
;
611 register int i
= count
;
617 #else /* __cplusplus */
619 /* This is the most reliable way to avoid incompatibilities
620 in available built-in functions on various systems. */
622 __yy_memcpy (char *from
, char *to
, int count
)
624 register char *f
= from
;
625 register char *t
= to
;
626 register int i
= count
;
635 #line 192 "/usr/local/share/bison.simple"
637 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
638 into yyparse. The argument should have type void *.
639 It should actually point to an object.
640 Grammar actions can access the variable by casting it
641 to the proper pointer type. */
644 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
646 #define YYPARSE_PARAM
647 #define YYPARSE_PARAM_DECL
651 yyparse(YYPARSE_PARAM
)
654 register int yystate
;
656 register short *yyssp
;
657 register YYSTYPE
*yyvsp
;
658 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
659 int yychar1
= 0; /* lookahead token as an internal (translated) token number */
661 short yyssa
[YYINITDEPTH
]; /* the state stack */
662 YYSTYPE yyvsa
[YYINITDEPTH
]; /* the semantic value stack */
664 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
665 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
668 YYLTYPE yylsa
[YYINITDEPTH
]; /* the location stack */
669 YYLTYPE
*yyls
= yylsa
;
672 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
674 #define YYPOPSTACK (yyvsp--, yyssp--)
677 int yystacksize
= YYINITDEPTH
;
688 YYSTYPE yyval
; /* the variable used to return */
689 /* semantic values from the action */
696 fprintf(stderr
, "Starting parse\n");
702 yychar
= YYEMPTY
; /* Cause a token to be read. */
704 /* Initialize stack pointers.
705 Waste one element of value and location stack
706 so that they stay on the same level as the state stack.
707 The wasted elements are never initialized. */
715 /* Push a new state, which is found in yystate . */
716 /* In all cases, when you get here, the value and location stacks
717 have just been pushed. so pushing a state here evens the stacks. */
722 if (yyssp
>= yyss
+ yystacksize
- 1)
724 /* Give user a chance to reallocate the stack */
725 /* Use copies of these so that the &'s don't force the real ones into memory. */
726 YYSTYPE
*yyvs1
= yyvs
;
729 YYLTYPE
*yyls1
= yyls
;
732 /* Get the current used size of the three stacks, in elements. */
733 int size
= yyssp
- yyss
+ 1;
736 /* Each stack pointer address is followed by the size of
737 the data in use in that stack, in bytes. */
739 /* This used to be a conditional around just the two extra args,
740 but that might be undefined if yyoverflow is a macro. */
741 yyoverflow("parser stack overflow",
742 &yyss1
, size
* sizeof (*yyssp
),
743 &yyvs1
, size
* sizeof (*yyvsp
),
744 &yyls1
, size
* sizeof (*yylsp
),
747 yyoverflow("parser stack overflow",
748 &yyss1
, size
* sizeof (*yyssp
),
749 &yyvs1
, size
* sizeof (*yyvsp
),
753 yyss
= yyss1
; yyvs
= yyvs1
;
757 #else /* no yyoverflow */
758 /* Extend the stack our own way. */
759 if (yystacksize
>= YYMAXDEPTH
)
761 yyerror("parser stack overflow");
765 if (yystacksize
> YYMAXDEPTH
)
766 yystacksize
= YYMAXDEPTH
;
767 yyss
= (short *) alloca (yystacksize
* sizeof (*yyssp
));
768 __yy_memcpy ((char *)yyss1
, (char *)yyss
, size
* sizeof (*yyssp
));
769 yyvs
= (YYSTYPE
*) alloca (yystacksize
* sizeof (*yyvsp
));
770 __yy_memcpy ((char *)yyvs1
, (char *)yyvs
, size
* sizeof (*yyvsp
));
772 yyls
= (YYLTYPE
*) alloca (yystacksize
* sizeof (*yylsp
));
773 __yy_memcpy ((char *)yyls1
, (char *)yyls
, size
* sizeof (*yylsp
));
775 #endif /* no yyoverflow */
777 yyssp
= yyss
+ size
- 1;
778 yyvsp
= yyvs
+ size
- 1;
780 yylsp
= yyls
+ size
- 1;
785 fprintf(stderr
, "Stack size increased to %d\n", yystacksize
);
788 if (yyssp
>= yyss
+ yystacksize
- 1)
794 fprintf(stderr
, "Entering state %d\n", yystate
);
800 /* Do appropriate processing given the current state. */
801 /* Read a lookahead token if we need one and don't already have one. */
804 /* First try to decide what to do without reference to lookahead token. */
806 yyn
= yypact
[yystate
];
810 /* Not known => get a lookahead token if don't already have one. */
812 /* yychar is either YYEMPTY or YYEOF
813 or a valid token in external form. */
815 if (yychar
== YYEMPTY
)
819 fprintf(stderr
, "Reading a token: ");
824 /* Convert token to internal form (in yychar1) for indexing tables with */
826 if (yychar
<= 0) /* This means end of input. */
829 yychar
= YYEOF
; /* Don't call YYLEX any more */
833 fprintf(stderr
, "Now at end of input.\n");
838 yychar1
= YYTRANSLATE(yychar
);
843 fprintf (stderr
, "Next token is %d (%s", yychar
, yytname
[yychar1
]);
844 /* Give the individual parser a way to print the precise meaning
845 of a token, for further debugging info. */
847 YYPRINT (stderr
, yychar
, yylval
);
849 fprintf (stderr
, ")\n");
855 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
860 /* yyn is what to do for this token type in this state.
861 Negative => reduce, -yyn is rule number.
862 Positive => shift, yyn is new state.
863 New state is final state => don't bother to shift,
865 0, or most negative number => error. */
880 /* Shift the lookahead token. */
884 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
887 /* Discard the token being shifted unless it is eof. */
896 /* count tokens shifted since error; after three, turn off error status. */
897 if (yyerrstatus
) yyerrstatus
--;
902 /* Do the default action for the current state. */
905 yyn
= yydefact
[yystate
];
909 /* Do a reduction. yyn is the number of a rule to reduce with. */
913 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
920 fprintf (stderr
, "Reducing via rule %d (line %d), ",
923 /* Print the symbols being reduced, and their result. */
924 for (i
= yyprhs
[yyn
]; yyrhs
[i
] > 0; i
++)
925 fprintf (stderr
, "%s ", yytname
[yyrhs
[i
]]);
926 fprintf (stderr
, " -> %s\n", yytname
[yyr1
[yyn
]]);
935 { expression_value
= yyvsp
[0].integer
.value
; ;
940 pedwarn ("comma operator in operand of `#if'");
941 yyval
.integer
= yyvsp
[0].integer
; ;
945 { yyval
.integer
.value
= - yyvsp
[0].integer
.value
;
946 yyval
.integer
.signedp
= yyvsp
[0].integer
.signedp
;
947 if ((yyval
.integer
.value
& yyvsp
[0].integer
.value
& yyval
.integer
.signedp
) < 0)
948 integer_overflow (); ;
952 { yyval
.integer
.value
= ! yyvsp
[0].integer
.value
;
953 yyval
.integer
.signedp
= SIGNED
; ;
957 { yyval
.integer
= yyvsp
[0].integer
; ;
961 { yyval
.integer
.value
= ~ yyvsp
[0].integer
.value
;
962 yyval
.integer
.signedp
= yyvsp
[0].integer
.signedp
; ;
966 { yyval
.integer
.value
= check_assertion (yyvsp
[0].name
.address
, yyvsp
[0].name
.length
,
968 yyval
.integer
.signedp
= SIGNED
; ;
972 { keyword_parsing
= 1; ;
976 { yyval
.integer
.value
= check_assertion (yyvsp
[-4].name
.address
, yyvsp
[-4].name
.length
,
977 1, yyvsp
[-1].keywords
);
979 yyval
.integer
.signedp
= SIGNED
; ;
983 { yyval
.integer
= yyvsp
[-1].integer
; ;
987 { yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
988 if (yyval
.integer
.signedp
)
990 yyval
.integer
.value
= yyvsp
[-2].integer
.value
* yyvsp
[0].integer
.value
;
991 if (yyvsp
[-2].integer
.value
992 && (yyval
.integer
.value
/ yyvsp
[-2].integer
.value
!= yyvsp
[0].integer
.value
993 || (yyval
.integer
.value
& yyvsp
[-2].integer
.value
& yyvsp
[0].integer
.value
) < 0))
997 yyval
.integer
.value
= ((unsigned HOST_WIDE_INT
) yyvsp
[-2].integer
.value
998 * yyvsp
[0].integer
.value
); ;
1002 { if (yyvsp
[0].integer
.value
== 0)
1004 if (!skip_evaluation
)
1005 error ("division by zero in #if");
1006 yyvsp
[0].integer
.value
= 1;
1008 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
1009 if (yyval
.integer
.signedp
)
1011 yyval
.integer
.value
= yyvsp
[-2].integer
.value
/ yyvsp
[0].integer
.value
;
1012 if ((yyval
.integer
.value
& yyvsp
[-2].integer
.value
& yyvsp
[0].integer
.value
) < 0)
1013 integer_overflow ();
1016 yyval
.integer
.value
= ((unsigned HOST_WIDE_INT
) yyvsp
[-2].integer
.value
1017 / yyvsp
[0].integer
.value
); ;
1021 { if (yyvsp
[0].integer
.value
== 0)
1023 if (!skip_evaluation
)
1024 error ("division by zero in #if");
1025 yyvsp
[0].integer
.value
= 1;
1027 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
1028 if (yyval
.integer
.signedp
)
1029 yyval
.integer
.value
= yyvsp
[-2].integer
.value
% yyvsp
[0].integer
.value
;
1031 yyval
.integer
.value
= ((unsigned HOST_WIDE_INT
) yyvsp
[-2].integer
.value
1032 % yyvsp
[0].integer
.value
); ;
1036 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
+ yyvsp
[0].integer
.value
;
1037 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
1038 if (overflow_sum_sign (yyvsp
[-2].integer
.value
, yyvsp
[0].integer
.value
,
1039 yyval
.integer
.value
, yyval
.integer
.signedp
))
1040 integer_overflow (); ;
1044 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
- yyvsp
[0].integer
.value
;
1045 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
;
1046 if (overflow_sum_sign (yyval
.integer
.value
, yyvsp
[0].integer
.value
,
1047 yyvsp
[-2].integer
.value
, yyval
.integer
.signedp
))
1048 integer_overflow (); ;
1052 { yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
;
1053 if ((yyvsp
[0].integer
.value
& yyvsp
[0].integer
.signedp
) < 0)
1054 yyval
.integer
.value
= right_shift (&yyvsp
[-2].integer
, -yyvsp
[0].integer
.value
);
1056 yyval
.integer
.value
= left_shift (&yyvsp
[-2].integer
, yyvsp
[0].integer
.value
); ;
1060 { yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
;
1061 if ((yyvsp
[0].integer
.value
& yyvsp
[0].integer
.signedp
) < 0)
1062 yyval
.integer
.value
= left_shift (&yyvsp
[-2].integer
, -yyvsp
[0].integer
.value
);
1064 yyval
.integer
.value
= right_shift (&yyvsp
[-2].integer
, yyvsp
[0].integer
.value
); ;
1068 { yyval
.integer
.value
= (yyvsp
[-2].integer
.value
== yyvsp
[0].integer
.value
);
1069 yyval
.integer
.signedp
= SIGNED
; ;
1073 { yyval
.integer
.value
= (yyvsp
[-2].integer
.value
!= yyvsp
[0].integer
.value
);
1074 yyval
.integer
.signedp
= SIGNED
; ;
1078 { yyval
.integer
.signedp
= SIGNED
;
1079 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
1080 yyval
.integer
.value
= yyvsp
[-2].integer
.value
<= yyvsp
[0].integer
.value
;
1082 yyval
.integer
.value
= ((unsigned HOST_WIDE_INT
) yyvsp
[-2].integer
.value
1083 <= yyvsp
[0].integer
.value
); ;
1087 { yyval
.integer
.signedp
= SIGNED
;
1088 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
1089 yyval
.integer
.value
= yyvsp
[-2].integer
.value
>= yyvsp
[0].integer
.value
;
1091 yyval
.integer
.value
= ((unsigned HOST_WIDE_INT
) yyvsp
[-2].integer
.value
1092 >= yyvsp
[0].integer
.value
); ;
1096 { yyval
.integer
.signedp
= SIGNED
;
1097 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
1098 yyval
.integer
.value
= yyvsp
[-2].integer
.value
< yyvsp
[0].integer
.value
;
1100 yyval
.integer
.value
= ((unsigned HOST_WIDE_INT
) yyvsp
[-2].integer
.value
1101 < yyvsp
[0].integer
.value
); ;
1105 { yyval
.integer
.signedp
= SIGNED
;
1106 if (yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
)
1107 yyval
.integer
.value
= yyvsp
[-2].integer
.value
> yyvsp
[0].integer
.value
;
1109 yyval
.integer
.value
= ((unsigned HOST_WIDE_INT
) yyvsp
[-2].integer
.value
1110 > yyvsp
[0].integer
.value
); ;
1114 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
& yyvsp
[0].integer
.value
;
1115 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1119 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
^ yyvsp
[0].integer
.value
;
1120 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1124 { yyval
.integer
.value
= yyvsp
[-2].integer
.value
| yyvsp
[0].integer
.value
;
1125 yyval
.integer
.signedp
= yyvsp
[-2].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1129 { skip_evaluation
+= !yyvsp
[-1].integer
.value
; ;
1133 { skip_evaluation
-= !yyvsp
[-3].integer
.value
;
1134 yyval
.integer
.value
= (yyvsp
[-3].integer
.value
&& yyvsp
[0].integer
.value
);
1135 yyval
.integer
.signedp
= SIGNED
; ;
1139 { skip_evaluation
+= !!yyvsp
[-1].integer
.value
; ;
1143 { skip_evaluation
-= !!yyvsp
[-3].integer
.value
;
1144 yyval
.integer
.value
= (yyvsp
[-3].integer
.value
|| yyvsp
[0].integer
.value
);
1145 yyval
.integer
.signedp
= SIGNED
; ;
1149 { skip_evaluation
+= !yyvsp
[-1].integer
.value
; ;
1153 { skip_evaluation
+= !!yyvsp
[-4].integer
.value
- !yyvsp
[-4].integer
.value
; ;
1157 { skip_evaluation
-= !!yyvsp
[-6].integer
.value
;
1158 yyval
.integer
.value
= yyvsp
[-6].integer
.value
? yyvsp
[-3].integer
.value
: yyvsp
[0].integer
.value
;
1159 yyval
.integer
.signedp
= yyvsp
[-3].integer
.signedp
& yyvsp
[0].integer
.signedp
; ;
1163 { yyval
.integer
= yylval
.integer
; ;
1167 { yyval
.integer
= yylval
.integer
; ;
1171 { if (warn_undef
&& !skip_evaluation
)
1172 warning ("`%.*s' is not defined",
1173 yyvsp
[0].name
.length
, yyvsp
[0].name
.address
);
1174 yyval
.integer
.value
= 0;
1175 yyval
.integer
.signedp
= SIGNED
; ;
1179 { yyval
.keywords
= 0; ;
1183 { struct arglist
*temp
;
1184 yyval
.keywords
= (struct arglist
*) xmalloc (sizeof (struct arglist
));
1185 yyval
.keywords
->next
= yyvsp
[-2].keywords
;
1186 yyval
.keywords
->name
= (U_CHAR
*) "(";
1187 yyval
.keywords
->length
= 1;
1188 temp
= yyval
.keywords
;
1189 while (temp
!= 0 && temp
->next
!= 0)
1191 temp
->next
= (struct arglist
*) xmalloc (sizeof (struct arglist
));
1192 temp
->next
->next
= yyvsp
[0].keywords
;
1193 temp
->next
->name
= (U_CHAR
*) ")";
1194 temp
->next
->length
= 1; ;
1198 { yyval
.keywords
= (struct arglist
*) xmalloc (sizeof (struct arglist
));
1199 yyval
.keywords
->name
= yyvsp
[-1].name
.address
;
1200 yyval
.keywords
->length
= yyvsp
[-1].name
.length
;
1201 yyval
.keywords
->next
= yyvsp
[0].keywords
; ;
1204 /* the action file gets copied in in place of this dollarsign */
1205 #line 487 "/usr/local/share/bison.simple"
1216 short *ssp1
= yyss
- 1;
1217 fprintf (stderr
, "state stack now");
1218 while (ssp1
!= yyssp
)
1219 fprintf (stderr
, " %d", *++ssp1
);
1220 fprintf (stderr
, "\n");
1230 yylsp
->first_line
= yylloc
.first_line
;
1231 yylsp
->first_column
= yylloc
.first_column
;
1232 yylsp
->last_line
= (yylsp
-1)->last_line
;
1233 yylsp
->last_column
= (yylsp
-1)->last_column
;
1238 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
1239 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
1243 /* Now "shift" the result of the reduction.
1244 Determine what state that goes to,
1245 based on the state we popped back to
1246 and the rule number reduced by. */
1250 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
1251 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1252 yystate
= yytable
[yystate
];
1254 yystate
= yydefgoto
[yyn
- YYNTBASE
];
1258 yyerrlab
: /* here on detecting error */
1261 /* If not already recovering from an error, report this error. */
1265 #ifdef YYERROR_VERBOSE
1266 yyn
= yypact
[yystate
];
1268 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
1275 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1276 for (x
= (yyn
< 0 ? -yyn
: 0);
1277 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
1278 if (yycheck
[x
+ yyn
] == x
)
1279 size
+= strlen(yytname
[x
]) + 15, count
++;
1280 msg
= (char *) malloc(size
+ 15);
1283 strcpy(msg
, "parse error");
1288 for (x
= (yyn
< 0 ? -yyn
: 0);
1289 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
1290 if (yycheck
[x
+ yyn
] == x
)
1292 strcat(msg
, count
== 0 ? ", expecting `" : " or `");
1293 strcat(msg
, yytname
[x
]);
1302 yyerror ("parse error; also virtual memory exceeded");
1305 #endif /* YYERROR_VERBOSE */
1306 yyerror("parse error");
1310 yyerrlab1
: /* here on error raised explicitly by an action */
1312 if (yyerrstatus
== 3)
1314 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1316 /* return failure if at end of input */
1317 if (yychar
== YYEOF
)
1322 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
1328 /* Else will try to reuse lookahead token
1329 after shifting the error token. */
1331 yyerrstatus
= 3; /* Each real token shifted decrements this */
1335 yyerrdefault
: /* current state does not do anything special for the error token. */
1338 /* This is wrong; only states that explicitly want error tokens
1339 should shift them. */
1340 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1341 if (yyn
) goto yydefault
;
1344 yyerrpop
: /* pop the current state because it cannot handle the error token */
1346 if (yyssp
== yyss
) YYABORT
;
1356 short *ssp1
= yyss
- 1;
1357 fprintf (stderr
, "Error: state stack now");
1358 while (ssp1
!= yyssp
)
1359 fprintf (stderr
, " %d", *++ssp1
);
1360 fprintf (stderr
, "\n");
1366 yyn
= yypact
[yystate
];
1371 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
1390 fprintf(stderr
, "Shifting error token, ");
1404 /* During parsing of a C expression, the pointer to the next character
1405 is in this variable. */
1407 static char *lexptr
;
1409 /* Take care of parsing a number (anything that starts with a digit).
1410 Set yylval and return the token type; update lexptr.
1411 LEN is the number of characters in it. */
1413 /* maybe needs to actually deal with floating point numbers */
1419 register char *p
= lexptr
;
1421 register unsigned HOST_WIDE_INT n
= 0, nd
, max_over_base
;
1422 register int base
= 10;
1423 register int len
= olen
;
1424 register int overflow
= 0;
1425 register int digit
, largest_digit
= 0;
1428 yylval
.integer
.signedp
= SIGNED
;
1432 if (len
>= 3 && (p
[1] == 'x' || p
[1] == 'X')) {
1439 max_over_base
= (unsigned HOST_WIDE_INT
) -1 / base
;
1441 for (; len
> 0; len
--) {
1444 if (c
>= '0' && c
<= '9')
1446 else if (base
== 16 && c
>= 'a' && c
<= 'f')
1447 digit
= c
- 'a' + 10;
1448 else if (base
== 16 && c
>= 'A' && c
<= 'F')
1449 digit
= c
- 'A' + 10;
1451 /* `l' means long, and `u' means unsigned. */
1453 if (c
== 'l' || c
== 'L')
1455 if (!pedantic
< spec_long
)
1456 yyerror ("too many `l's in integer constant");
1459 else if (c
== 'u' || c
== 'U')
1461 if (! yylval
.integer
.signedp
)
1462 yyerror ("two `u's in integer constant");
1463 yylval
.integer
.signedp
= UNSIGNED
;
1466 if (c
== '.' || c
== 'e' || c
== 'E' || c
== 'p' || c
== 'P')
1467 yyerror ("Floating point numbers not allowed in #if expressions");
1469 char *buf
= (char *) alloca (p
- lexptr
+ 40);
1470 sprintf (buf
, "missing white space after number `%.*s'",
1471 (int) (p
- lexptr
- 1), lexptr
);
1480 /* Don't look for any more digits after the suffixes. */
1483 if (largest_digit
< digit
)
1484 largest_digit
= digit
;
1485 nd
= n
* base
+ digit
;
1486 overflow
|= (max_over_base
< n
) | (nd
< n
);
1490 if (base
<= largest_digit
)
1491 pedwarn ("integer constant contains digits beyond the radix");
1494 pedwarn ("integer constant out of range");
1496 /* If too big to be signed, consider it unsigned. */
1497 if (((HOST_WIDE_INT
) n
& yylval
.integer
.signedp
) < 0)
1500 warning ("integer constant is so large that it is unsigned");
1501 yylval
.integer
.signedp
= UNSIGNED
;
1505 yylval
.integer
.value
= n
;
1514 static struct token tokentab2
[] = {
1528 /* Read one token, getting characters through lexptr. */
1534 register int namelen
;
1535 register unsigned char *tokstart
;
1536 register struct token
*toktab
;
1542 tokstart
= (unsigned char *) lexptr
;
1544 /* See if it is a special token of length 2. */
1545 if (! keyword_parsing
)
1546 for (toktab
= tokentab2
; toktab
->operator != NULL
; toktab
++)
1547 if (c
== *toktab
->operator && tokstart
[1] == toktab
->operator[1]) {
1549 if (toktab
->token
== ERROR
)
1551 char *buf
= (char *) alloca (40);
1552 sprintf (buf
, "`%s' not allowed in operand of `#if'", toktab
->operator);
1555 return toktab
->token
;
1569 /* Capital L may start a wide-string or wide-character constant. */
1570 if (lexptr
[1] == '\'')
1574 mask
= MAX_WCHAR_TYPE_MASK
;
1577 if (lexptr
[1] == '"')
1581 mask
= MAX_WCHAR_TYPE_MASK
;
1582 goto string_constant
;
1588 mask
= MAX_CHAR_TYPE_MASK
;
1591 if (keyword_parsing
) {
1592 char *start_ptr
= lexptr
- 1;
1596 c
= parse_escape (&lexptr
, mask
);
1600 yylval
.name
.address
= tokstart
;
1601 yylval
.name
.length
= lexptr
- start_ptr
;
1605 /* This code for reading a character constant
1606 handles multicharacter constants and wide characters.
1607 It is mostly copied from c-lex.c. */
1609 register HOST_WIDE_INT result
= 0;
1610 register num_chars
= 0;
1611 unsigned width
= MAX_CHAR_TYPE_SIZE
;
1617 width
= MAX_WCHAR_TYPE_SIZE
;
1618 #ifdef MULTIBYTE_CHARS
1619 max_chars
= MB_CUR_MAX
;
1625 max_chars
= MAX_LONG_TYPE_SIZE
/ width
;
1627 token_buffer
= (char *) alloca (max_chars
+ 1);
1633 if (c
== '\'' || c
== EOF
)
1638 c
= parse_escape (&lexptr
, mask
);
1643 /* Merge character into result; ignore excess chars. */
1644 if (num_chars
<= max_chars
)
1646 if (width
< HOST_BITS_PER_WIDE_INT
)
1647 result
= (result
<< width
) | c
;
1650 token_buffer
[num_chars
- 1] = c
;
1654 token_buffer
[num_chars
] = 0;
1657 error ("malformatted character constant");
1658 else if (num_chars
== 0)
1659 error ("empty character constant");
1660 else if (num_chars
> max_chars
)
1662 num_chars
= max_chars
;
1663 error ("character constant too long");
1665 else if (num_chars
!= 1 && ! traditional
)
1666 warning ("multi-character character constant");
1668 /* If char type is signed, sign-extend the constant. */
1671 int num_bits
= num_chars
* width
;
1673 if (lookup ((U_CHAR
*) "__CHAR_UNSIGNED__",
1674 sizeof ("__CHAR_UNSIGNED__") - 1, -1)
1675 || ((result
>> (num_bits
- 1)) & 1) == 0)
1676 yylval
.integer
.value
1677 = result
& (~ (unsigned HOST_WIDE_INT
) 0
1678 >> (HOST_BITS_PER_WIDE_INT
- num_bits
));
1680 yylval
.integer
.value
1681 = result
| ~(~ (unsigned HOST_WIDE_INT
) 0
1682 >> (HOST_BITS_PER_WIDE_INT
- num_bits
));
1686 #ifdef MULTIBYTE_CHARS
1687 /* Set the initial shift state and convert the next sequence. */
1689 /* In all locales L'\0' is zero and mbtowc will return zero,
1692 || (num_chars
== 1 && token_buffer
[0] != '\0'))
1695 (void) mbtowc (NULL_PTR
, NULL_PTR
, 0);
1696 if (mbtowc (& wc
, token_buffer
, num_chars
) == num_chars
)
1699 pedwarn ("Ignoring invalid multibyte character");
1702 yylval
.integer
.value
= result
;
1706 /* This is always a signed type. */
1707 yylval
.integer
.signedp
= SIGNED
;
1711 /* some of these chars are invalid in constant expressions;
1712 maybe do something about them later */
1736 if (keyword_parsing
)
1744 mask
= MAX_CHAR_TYPE_MASK
;
1746 if (keyword_parsing
) {
1747 char *start_ptr
= lexptr
;
1752 c
= parse_escape (&lexptr
, mask
);
1756 yylval
.name
.address
= tokstart
;
1757 yylval
.name
.length
= lexptr
- start_ptr
;
1760 yyerror ("string constants not allowed in #if expressions");
1764 if (c
>= '0' && c
<= '9' && !keyword_parsing
) {
1766 for (namelen
= 1; ; namelen
++) {
1767 int d
= tokstart
[namelen
];
1768 if (! ((is_idchar
[d
] || d
== '.')
1769 || ((d
== '-' || d
== '+')
1770 && (c
== 'e' || c
== 'E'
1771 || ((c
== 'p' || c
== 'P') && ! c89
))
1776 return parse_number (namelen
);
1779 /* It is a name. See how long it is. */
1781 if (keyword_parsing
) {
1782 for (namelen
= 0;; namelen
++) {
1783 if (is_space
[tokstart
[namelen
]])
1785 if (tokstart
[namelen
] == '(' || tokstart
[namelen
] == ')')
1787 if (tokstart
[namelen
] == '"' || tokstart
[namelen
] == '\'')
1791 if (!is_idstart
[c
]) {
1792 yyerror ("Invalid token in expression");
1796 for (namelen
= 0; is_idchar
[tokstart
[namelen
]]; namelen
++)
1801 yylval
.name
.address
= tokstart
;
1802 yylval
.name
.length
= namelen
;
1807 /* Parse a C escape sequence. STRING_PTR points to a variable
1808 containing a pointer to the string to parse. That pointer
1809 is updated past the characters we use. The value of the
1810 escape sequence is returned.
1812 RESULT_MASK is used to mask out the result;
1813 an error is reported if bits are lost thereby.
1815 A negative value means the sequence \ newline was seen,
1816 which is supposed to be equivalent to nothing at all.
1818 If \ is followed by a null character, we return a negative
1819 value and leave the string pointer pointing at the null character.
1821 If \ is followed by 000, we return 0 and leave the string pointer
1822 after the zeros. A value of 0 does not mean end of string. */
1825 parse_escape (string_ptr
, result_mask
)
1827 HOST_WIDE_INT result_mask
;
1829 register int c
= *(*string_ptr
)++;
1839 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c
);
1844 return TARGET_NEWLINE
;
1866 register HOST_WIDE_INT i
= c
- '0';
1867 register int count
= 0;
1870 c
= *(*string_ptr
)++;
1871 if (c
>= '0' && c
<= '7')
1872 i
= (i
<< 3) + c
- '0';
1879 if (i
!= (i
& result_mask
))
1882 pedwarn ("octal escape sequence out of range");
1888 register unsigned HOST_WIDE_INT i
= 0, overflow
= 0;
1889 register int digits_found
= 0, digit
;
1892 c
= *(*string_ptr
)++;
1893 if (c
>= '0' && c
<= '9')
1895 else if (c
>= 'a' && c
<= 'f')
1896 digit
= c
- 'a' + 10;
1897 else if (c
>= 'A' && c
<= 'F')
1898 digit
= c
- 'A' + 10;
1904 overflow
|= i
^ (i
<< 4 >> 4);
1905 i
= (i
<< 4) + digit
;
1909 yyerror ("\\x used with no following hex digits");
1910 if (overflow
| (i
!= (i
& result_mask
)))
1913 pedwarn ("hex escape sequence out of range");
1927 skip_evaluation
= 0;
1928 longjmp (parse_return_error
, 1);
1934 if (!skip_evaluation
&& pedantic
)
1935 pedwarn ("integer overflow in preprocessor expression");
1938 static HOST_WIDE_INT
1941 unsigned HOST_WIDE_INT b
;
1943 /* It's unclear from the C standard whether shifts can overflow.
1944 The following code ignores overflow; perhaps a C standard
1945 interpretation ruling is needed. */
1946 if (b
>= HOST_BITS_PER_WIDE_INT
)
1949 return (unsigned HOST_WIDE_INT
) a
->value
<< b
;
1952 static HOST_WIDE_INT
1955 unsigned HOST_WIDE_INT b
;
1957 if (b
>= HOST_BITS_PER_WIDE_INT
)
1958 return a
->signedp
? a
->value
>> (HOST_BITS_PER_WIDE_INT
- 1) : 0;
1959 else if (a
->signedp
)
1960 return a
->value
>> b
;
1962 return (unsigned HOST_WIDE_INT
) a
->value
>> b
;
1965 /* This page contains the entry point to this file. */
1967 /* Parse STRING as an expression, and complain if this fails
1968 to use up all of the contents of STRING. */
1969 /* STRING may contain '\0' bytes; it is terminated by the first '\n'
1970 outside a string constant, so that we can diagnose '\0' properly. */
1971 /* We do not support C comments. They should be removed before
1972 this function is called. */
1975 parse_c_expression (string
)
1980 /* if there is some sort of scanning error, just return 0 and assume
1981 the parsing routine has printed an error message somewhere.
1982 there is surely a better thing to do than this. */
1983 if (setjmp (parse_return_error
))
1986 if (yyparse () != 0)
1989 if (*lexptr
!= '\n')
1990 error ("Junk after end of expression.");
1992 return expression_value
; /* set by yyparse () */
1995 #ifdef TEST_EXP_READER
2004 int main
PROTO((int, char **));
2005 static void initialize_random_junk
PROTO((void));
2007 /* Main program for testing purposes. */
2016 pedantic
= 1 < argc
;
2017 traditional
= 2 < argc
;
2021 initialize_random_junk ();
2024 printf ("enter expression: ");
2026 while ((buf
[n
] = c
= getchar ()) != '\n' && c
!= EOF
)
2030 printf ("parser returned %ld\n", (long) parse_c_expression (buf
));
2036 /* table to tell if char can be part of a C identifier. */
2037 unsigned char is_idchar
[256];
2038 /* table to tell if char can be first char of a c identifier. */
2039 unsigned char is_idstart
[256];
2040 /* table to tell if c is horizontal or vertical space. */
2041 unsigned char is_space
[256];
2044 * initialize random junk in the hash table and maybe other places
2047 initialize_random_junk ()
2052 * Set up is_idchar and is_idstart tables. These should be
2053 * faster than saying (is_alpha (c) || c == '_'), etc.
2054 * Must do set up these things before calling any routines tthat
2057 for (i
= 'a'; i
<= 'z'; i
++) {
2058 ++is_idchar
[i
- 'a' + 'A'];
2060 ++is_idstart
[i
- 'a' + 'A'];
2063 for (i
= '0'; i
<= '9'; i
++)
2079 error (PRINTF_ALIST (msg
))
2084 VA_START (args
, msg
);
2085 fprintf (stderr
, "error: ");
2086 vfprintf (stderr
, msg
, args
);
2087 fprintf (stderr
, "\n");
2092 pedwarn (PRINTF_ALIST (msg
))
2097 VA_START (args
, msg
);
2098 fprintf (stderr
, "pedwarn: ");
2099 vfprintf (stderr
, msg
, args
);
2100 fprintf (stderr
, "\n");
2105 warning (PRINTF_ALIST (msg
))
2110 VA_START (args
, msg
);
2111 fprintf (stderr
, "warning: ");
2112 vfprintf (stderr
, msg
, args
);
2113 fprintf (stderr
, "\n");
2118 check_assertion (name
, sym_length
, tokens_specified
, tokens
)
2121 int tokens_specified
;
2122 struct arglist
*tokens
;
2128 lookup (name
, len
, hash
)
2133 return (DEFAULT_SIGNED_CHAR
) ? 0 : ((struct hashnode
*) -1);
2140 return (GENERIC_PTR
) malloc (size
);