Initial revision
[official-gcc.git] / gcc / cexp.c
bloba4f2cc530292b696e485e5d2721b1e444dde9946
2 /* A Bison parser, made from cexp.y with Bison version GNU Bison version 1.24
3 */
5 #define YYBISON 1 /* Identify Bison output. */
7 #define INT 258
8 #define CHAR 259
9 #define NAME 260
10 #define ERROR 261
11 #define OR 262
12 #define AND 263
13 #define EQUAL 264
14 #define NOTEQUAL 265
15 #define LEQ 266
16 #define GEQ 267
17 #define LSH 268
18 #define RSH 269
19 #define UNARY 270
21 #line 27 "cexp.y"
23 #include "config.h"
24 #include <setjmp.h>
25 /* #define YYDEBUG 1 */
27 /* The following symbols should be autoconfigured:
28 HAVE_STDLIB_H
29 STDC_HEADERS
30 In the mean time, we'll get by with approximations based
31 on existing GCC configuration symbols. */
33 #ifdef POSIX
34 # ifndef HAVE_STDLIB_H
35 # define HAVE_STDLIB_H 1
36 # endif
37 # ifndef STDC_HEADERS
38 # define STDC_HEADERS 1
39 # endif
40 #endif /* defined (POSIX) */
42 #if STDC_HEADERS
43 # include <string.h>
44 #endif
46 #if HAVE_STDLIB_H || defined (MULTIBYTE_CHARS)
47 # include <stdlib.h>
48 #endif
50 #ifdef MULTIBYTE_CHARS
51 #include <locale.h>
52 #endif
54 #include <stdio.h>
56 typedef unsigned char U_CHAR;
58 /* This is used for communicating lists of keywords with cccp.c. */
59 struct arglist {
60 struct arglist *next;
61 U_CHAR *name;
62 int length;
63 int argno;
66 /* Define a generic NULL if one hasn't already been defined. */
68 #ifndef NULL
69 #define NULL 0
70 #endif
72 #ifndef GENERIC_PTR
73 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
74 #define GENERIC_PTR void *
75 #else
76 #define GENERIC_PTR char *
77 #endif
78 #endif
80 #ifndef NULL_PTR
81 #define NULL_PTR ((GENERIC_PTR) 0)
82 #endif
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
92 #else
93 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
94 #define HOST_WIDE_INT int
95 #endif
97 #endif
99 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
100 # define __attribute__(x)
101 #endif
103 #ifndef PROTO
104 # if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
105 # define PROTO(ARGS) ARGS
106 # else
107 # define PROTO(ARGS) ()
108 # endif
109 #endif
111 #if defined (__STDC__) && defined (HAVE_VPRINTF)
112 # include <stdarg.h>
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)))
117 #else
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); \
131 #endif
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. */
154 extern int pedantic;
156 /* Flag for -traditional. */
157 extern int traditional;
159 /* Flag for -lang-c89. */
160 extern int c89;
162 /* Flag for -Wundef. */
163 extern int warn_undef;
165 #ifndef CHAR_TYPE_SIZE
166 #define CHAR_TYPE_SIZE BITS_PER_UNIT
167 #endif
169 #ifndef INT_TYPE_SIZE
170 #define INT_TYPE_SIZE BITS_PER_WORD
171 #endif
173 #ifndef LONG_TYPE_SIZE
174 #define LONG_TYPE_SIZE BITS_PER_WORD
175 #endif
177 #ifndef WCHAR_TYPE_SIZE
178 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
179 #endif
181 #ifndef MAX_CHAR_TYPE_SIZE
182 #define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE
183 #endif
185 #ifndef MAX_INT_TYPE_SIZE
186 #define MAX_INT_TYPE_SIZE INT_TYPE_SIZE
187 #endif
189 #ifndef MAX_LONG_TYPE_SIZE
190 #define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE
191 #endif
193 #ifndef MAX_WCHAR_TYPE_SIZE
194 #define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
195 #endif
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))
199 #else
200 #define MAX_CHAR_TYPE_MASK (~ (HOST_WIDE_INT) 0)
201 #endif
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))
205 #else
206 #define MAX_WCHAR_TYPE_MASK (~ (HOST_WIDE_INT) 0)
207 #endif
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)
219 struct constant;
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 */
235 #define SIGNED (~0)
236 #define UNSIGNED 0
238 #line 244 "cexp.y"
239 typedef union {
240 struct constant {HOST_WIDE_INT value; int signedp;} integer;
241 struct name {U_CHAR *address; int length;} name;
242 struct arglist *keywords;
243 } YYSTYPE;
245 #ifndef YYLTYPE
246 typedef
247 struct yyltype
249 int timestamp;
250 int first_line;
251 int first_column;
252 int last_line;
253 int last_column;
254 char *text;
256 yyltype;
258 #define YYLTYPE yyltype
259 #endif
261 #include <stdio.h>
263 #ifndef __cplusplus
264 #ifndef __STDC__
265 #define const
266 #endif
267 #endif
271 #define YYFINAL 77
272 #define YYFLAG -32768
273 #define YYNTBASE 34
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
307 #if YYDEBUG != 0
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,
329 42, 0, 5, 42, 0
332 #endif
334 #if YYDEBUG != 0
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",
348 #endif
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
395 #define YYLAST 189
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)
450 any later version.
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. */
466 #ifndef alloca
467 #ifdef __GNUC__
468 #define alloca __builtin_alloca
469 #else /* not GNU C. */
470 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
471 #include <alloca.h>
472 #else /* not sparc */
473 #if defined (MSDOS) && !defined (__TURBOC__)
474 #include <malloc.h>
475 #else /* not MSDOS, or __TURBOC__ */
476 #if defined(_AIX)
477 #include <malloc.h>
478 #pragma alloca
479 #else /* not MSDOS, __TURBOC__, or _AIX */
480 #ifdef __hpux
481 #ifdef __cplusplus
482 extern "C" {
483 void *alloca (unsigned int);
485 #else /* not __cplusplus */
486 void *alloca ();
487 #endif /* not __cplusplus */
488 #endif /* __hpux */
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)
506 #define YYEMPTY -2
507 #define YYEOF 0
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) \
518 do \
519 if (yychar == YYEMPTY && yylen == 1) \
520 { yychar = (token), yylval = (value); \
521 yychar1 = YYTRANSLATE (yychar); \
522 YYPOPSTACK; \
523 goto yybackup; \
525 else \
526 { yyerror ("syntax error: cannot back up"); YYERROR; } \
527 while (0)
529 #define YYTERROR 1
530 #define YYERRCODE 256
532 #ifndef YYPURE
533 #define YYLEX yylex()
534 #endif
536 #ifdef YYPURE
537 #ifdef YYLSP_NEEDED
538 #ifdef YYLEX_PARAM
539 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
540 #else
541 #define YYLEX yylex(&yylval, &yylloc)
542 #endif
543 #else /* not YYLSP_NEEDED */
544 #ifdef YYLEX_PARAM
545 #define YYLEX yylex(&yylval, YYLEX_PARAM)
546 #else
547 #define YYLEX yylex(&yylval)
548 #endif
549 #endif /* not YYLSP_NEEDED */
550 #endif
552 /* If nonreentrant, generate the variables here */
554 #ifndef YYPURE
556 int yychar; /* the lookahead symbol */
557 YYSTYPE yylval; /* the semantic value of the */
558 /* lookahead symbol */
560 #ifdef YYLSP_NEEDED
561 YYLTYPE yylloc; /* location data for the lookahead */
562 /* symbol */
563 #endif
565 int yynerrs; /* number of parse errors so far */
566 #endif /* not YYPURE */
568 #if YYDEBUG != 0
569 int yydebug; /* nonzero means print parse trace */
570 /* Since this is uninitialized, it does not stop multiple parsers
571 from coexisting. */
572 #endif
574 /* YYINITDEPTH indicates the initial size of the parser's stacks */
576 #ifndef YYINITDEPTH
577 #define YYINITDEPTH 200
578 #endif
580 /* YYMAXDEPTH is the maximum size the stacks can grow to
581 (effective only if the built-in stack extension method is used). */
583 #if YYMAXDEPTH == 0
584 #undef YYMAXDEPTH
585 #endif
587 #ifndef YYMAXDEPTH
588 #define YYMAXDEPTH 10000
589 #endif
591 /* Prevent warning if -Wstrict-prototypes. */
592 #ifdef __GNUC__
593 int yyparse (void);
594 #endif
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++ */
599 #ifndef __cplusplus
601 /* This is the most reliable way to avoid incompatibilities
602 in available built-in functions on various systems. */
603 static void
604 __yy_memcpy (from, to, count)
605 char *from;
606 char *to;
607 int count;
609 register char *f = from;
610 register char *t = to;
611 register int i = count;
613 while (i-- > 0)
614 *t++ = *f++;
617 #else /* __cplusplus */
619 /* This is the most reliable way to avoid incompatibilities
620 in available built-in functions on various systems. */
621 static void
622 __yy_memcpy (char *from, char *to, int count)
624 register char *f = from;
625 register char *t = to;
626 register int i = count;
628 while (i-- > 0)
629 *t++ = *f++;
632 #endif
633 #endif
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. */
643 #ifdef YYPARSE_PARAM
644 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
645 #else
646 #define YYPARSE_PARAM
647 #define YYPARSE_PARAM_DECL
648 #endif
651 yyparse(YYPARSE_PARAM)
652 YYPARSE_PARAM_DECL
654 register int yystate;
655 register int yyn;
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 */
667 #ifdef YYLSP_NEEDED
668 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
669 YYLTYPE *yyls = yylsa;
670 YYLTYPE *yylsp;
672 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
673 #else
674 #define YYPOPSTACK (yyvsp--, yyssp--)
675 #endif
677 int yystacksize = YYINITDEPTH;
679 #ifdef YYPURE
680 int yychar;
681 YYSTYPE yylval;
682 int yynerrs;
683 #ifdef YYLSP_NEEDED
684 YYLTYPE yylloc;
685 #endif
686 #endif
688 YYSTYPE yyval; /* the variable used to return */
689 /* semantic values from the action */
690 /* routines */
692 int yylen;
694 #if YYDEBUG != 0
695 if (yydebug)
696 fprintf(stderr, "Starting parse\n");
697 #endif
699 yystate = 0;
700 yyerrstatus = 0;
701 yynerrs = 0;
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. */
709 yyssp = yyss - 1;
710 yyvsp = yyvs;
711 #ifdef YYLSP_NEEDED
712 yylsp = yyls;
713 #endif
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. */
718 yynewstate:
720 *++yyssp = yystate;
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;
727 short *yyss1 = yyss;
728 #ifdef YYLSP_NEEDED
729 YYLTYPE *yyls1 = yyls;
730 #endif
732 /* Get the current used size of the three stacks, in elements. */
733 int size = yyssp - yyss + 1;
735 #ifdef yyoverflow
736 /* Each stack pointer address is followed by the size of
737 the data in use in that stack, in bytes. */
738 #ifdef YYLSP_NEEDED
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),
745 &yystacksize);
746 #else
747 yyoverflow("parser stack overflow",
748 &yyss1, size * sizeof (*yyssp),
749 &yyvs1, size * sizeof (*yyvsp),
750 &yystacksize);
751 #endif
753 yyss = yyss1; yyvs = yyvs1;
754 #ifdef YYLSP_NEEDED
755 yyls = yyls1;
756 #endif
757 #else /* no yyoverflow */
758 /* Extend the stack our own way. */
759 if (yystacksize >= YYMAXDEPTH)
761 yyerror("parser stack overflow");
762 return 2;
764 yystacksize *= 2;
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));
771 #ifdef YYLSP_NEEDED
772 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
773 __yy_memcpy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
774 #endif
775 #endif /* no yyoverflow */
777 yyssp = yyss + size - 1;
778 yyvsp = yyvs + size - 1;
779 #ifdef YYLSP_NEEDED
780 yylsp = yyls + size - 1;
781 #endif
783 #if YYDEBUG != 0
784 if (yydebug)
785 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
786 #endif
788 if (yyssp >= yyss + yystacksize - 1)
789 YYABORT;
792 #if YYDEBUG != 0
793 if (yydebug)
794 fprintf(stderr, "Entering state %d\n", yystate);
795 #endif
797 goto yybackup;
798 yybackup:
800 /* Do appropriate processing given the current state. */
801 /* Read a lookahead token if we need one and don't already have one. */
802 /* yyresume: */
804 /* First try to decide what to do without reference to lookahead token. */
806 yyn = yypact[yystate];
807 if (yyn == YYFLAG)
808 goto yydefault;
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)
817 #if YYDEBUG != 0
818 if (yydebug)
819 fprintf(stderr, "Reading a token: ");
820 #endif
821 yychar = YYLEX;
824 /* Convert token to internal form (in yychar1) for indexing tables with */
826 if (yychar <= 0) /* This means end of input. */
828 yychar1 = 0;
829 yychar = YYEOF; /* Don't call YYLEX any more */
831 #if YYDEBUG != 0
832 if (yydebug)
833 fprintf(stderr, "Now at end of input.\n");
834 #endif
836 else
838 yychar1 = YYTRANSLATE(yychar);
840 #if YYDEBUG != 0
841 if (yydebug)
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. */
846 #ifdef YYPRINT
847 YYPRINT (stderr, yychar, yylval);
848 #endif
849 fprintf (stderr, ")\n");
851 #endif
854 yyn += yychar1;
855 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
856 goto yydefault;
858 yyn = yytable[yyn];
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,
864 just return success.
865 0, or most negative number => error. */
867 if (yyn < 0)
869 if (yyn == YYFLAG)
870 goto yyerrlab;
871 yyn = -yyn;
872 goto yyreduce;
874 else if (yyn == 0)
875 goto yyerrlab;
877 if (yyn == YYFINAL)
878 YYACCEPT;
880 /* Shift the lookahead token. */
882 #if YYDEBUG != 0
883 if (yydebug)
884 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
885 #endif
887 /* Discard the token being shifted unless it is eof. */
888 if (yychar != YYEOF)
889 yychar = YYEMPTY;
891 *++yyvsp = yylval;
892 #ifdef YYLSP_NEEDED
893 *++yylsp = yylloc;
894 #endif
896 /* count tokens shifted since error; after three, turn off error status. */
897 if (yyerrstatus) yyerrstatus--;
899 yystate = yyn;
900 goto yynewstate;
902 /* Do the default action for the current state. */
903 yydefault:
905 yyn = yydefact[yystate];
906 if (yyn == 0)
907 goto yyerrlab;
909 /* Do a reduction. yyn is the number of a rule to reduce with. */
910 yyreduce:
911 yylen = yyr2[yyn];
912 if (yylen > 0)
913 yyval = yyvsp[1-yylen]; /* implement default value of the action */
915 #if YYDEBUG != 0
916 if (yydebug)
918 int i;
920 fprintf (stderr, "Reducing via rule %d (line %d), ",
921 yyn, yyrline[yyn]);
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]]);
928 #endif
931 switch (yyn) {
933 case 1:
934 #line 275 "cexp.y"
935 { expression_value = yyvsp[0].integer.value; ;
936 break;}
937 case 3:
938 #line 281 "cexp.y"
939 { if (pedantic)
940 pedwarn ("comma operator in operand of `#if'");
941 yyval.integer = yyvsp[0].integer; ;
942 break;}
943 case 4:
944 #line 288 "cexp.y"
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 (); ;
949 break;}
950 case 5:
951 #line 293 "cexp.y"
952 { yyval.integer.value = ! yyvsp[0].integer.value;
953 yyval.integer.signedp = SIGNED; ;
954 break;}
955 case 6:
956 #line 296 "cexp.y"
957 { yyval.integer = yyvsp[0].integer; ;
958 break;}
959 case 7:
960 #line 298 "cexp.y"
961 { yyval.integer.value = ~ yyvsp[0].integer.value;
962 yyval.integer.signedp = yyvsp[0].integer.signedp; ;
963 break;}
964 case 8:
965 #line 301 "cexp.y"
966 { yyval.integer.value = check_assertion (yyvsp[0].name.address, yyvsp[0].name.length,
967 0, NULL_PTR);
968 yyval.integer.signedp = SIGNED; ;
969 break;}
970 case 9:
971 #line 305 "cexp.y"
972 { keyword_parsing = 1; ;
973 break;}
974 case 10:
975 #line 307 "cexp.y"
976 { yyval.integer.value = check_assertion (yyvsp[-4].name.address, yyvsp[-4].name.length,
977 1, yyvsp[-1].keywords);
978 keyword_parsing = 0;
979 yyval.integer.signedp = SIGNED; ;
980 break;}
981 case 11:
982 #line 312 "cexp.y"
983 { yyval.integer = yyvsp[-1].integer; ;
984 break;}
985 case 12:
986 #line 317 "cexp.y"
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))
994 integer_overflow ();
996 else
997 yyval.integer.value = ((unsigned HOST_WIDE_INT) yyvsp[-2].integer.value
998 * yyvsp[0].integer.value); ;
999 break;}
1000 case 13:
1001 #line 330 "cexp.y"
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 ();
1015 else
1016 yyval.integer.value = ((unsigned HOST_WIDE_INT) yyvsp[-2].integer.value
1017 / yyvsp[0].integer.value); ;
1018 break;}
1019 case 14:
1020 #line 347 "cexp.y"
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;
1030 else
1031 yyval.integer.value = ((unsigned HOST_WIDE_INT) yyvsp[-2].integer.value
1032 % yyvsp[0].integer.value); ;
1033 break;}
1034 case 15:
1035 #line 360 "cexp.y"
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 (); ;
1041 break;}
1042 case 16:
1043 #line 366 "cexp.y"
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 (); ;
1049 break;}
1050 case 17:
1051 #line 372 "cexp.y"
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);
1055 else
1056 yyval.integer.value = left_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
1057 break;}
1058 case 18:
1059 #line 378 "cexp.y"
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);
1063 else
1064 yyval.integer.value = right_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
1065 break;}
1066 case 19:
1067 #line 384 "cexp.y"
1068 { yyval.integer.value = (yyvsp[-2].integer.value == yyvsp[0].integer.value);
1069 yyval.integer.signedp = SIGNED; ;
1070 break;}
1071 case 20:
1072 #line 387 "cexp.y"
1073 { yyval.integer.value = (yyvsp[-2].integer.value != yyvsp[0].integer.value);
1074 yyval.integer.signedp = SIGNED; ;
1075 break;}
1076 case 21:
1077 #line 390 "cexp.y"
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;
1081 else
1082 yyval.integer.value = ((unsigned HOST_WIDE_INT) yyvsp[-2].integer.value
1083 <= yyvsp[0].integer.value); ;
1084 break;}
1085 case 22:
1086 #line 397 "cexp.y"
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;
1090 else
1091 yyval.integer.value = ((unsigned HOST_WIDE_INT) yyvsp[-2].integer.value
1092 >= yyvsp[0].integer.value); ;
1093 break;}
1094 case 23:
1095 #line 404 "cexp.y"
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;
1099 else
1100 yyval.integer.value = ((unsigned HOST_WIDE_INT) yyvsp[-2].integer.value
1101 < yyvsp[0].integer.value); ;
1102 break;}
1103 case 24:
1104 #line 411 "cexp.y"
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;
1108 else
1109 yyval.integer.value = ((unsigned HOST_WIDE_INT) yyvsp[-2].integer.value
1110 > yyvsp[0].integer.value); ;
1111 break;}
1112 case 25:
1113 #line 418 "cexp.y"
1114 { yyval.integer.value = yyvsp[-2].integer.value & yyvsp[0].integer.value;
1115 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1116 break;}
1117 case 26:
1118 #line 421 "cexp.y"
1119 { yyval.integer.value = yyvsp[-2].integer.value ^ yyvsp[0].integer.value;
1120 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1121 break;}
1122 case 27:
1123 #line 424 "cexp.y"
1124 { yyval.integer.value = yyvsp[-2].integer.value | yyvsp[0].integer.value;
1125 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1126 break;}
1127 case 28:
1128 #line 427 "cexp.y"
1129 { skip_evaluation += !yyvsp[-1].integer.value; ;
1130 break;}
1131 case 29:
1132 #line 429 "cexp.y"
1133 { skip_evaluation -= !yyvsp[-3].integer.value;
1134 yyval.integer.value = (yyvsp[-3].integer.value && yyvsp[0].integer.value);
1135 yyval.integer.signedp = SIGNED; ;
1136 break;}
1137 case 30:
1138 #line 433 "cexp.y"
1139 { skip_evaluation += !!yyvsp[-1].integer.value; ;
1140 break;}
1141 case 31:
1142 #line 435 "cexp.y"
1143 { skip_evaluation -= !!yyvsp[-3].integer.value;
1144 yyval.integer.value = (yyvsp[-3].integer.value || yyvsp[0].integer.value);
1145 yyval.integer.signedp = SIGNED; ;
1146 break;}
1147 case 32:
1148 #line 439 "cexp.y"
1149 { skip_evaluation += !yyvsp[-1].integer.value; ;
1150 break;}
1151 case 33:
1152 #line 441 "cexp.y"
1153 { skip_evaluation += !!yyvsp[-4].integer.value - !yyvsp[-4].integer.value; ;
1154 break;}
1155 case 34:
1156 #line 443 "cexp.y"
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; ;
1160 break;}
1161 case 35:
1162 #line 447 "cexp.y"
1163 { yyval.integer = yylval.integer; ;
1164 break;}
1165 case 36:
1166 #line 449 "cexp.y"
1167 { yyval.integer = yylval.integer; ;
1168 break;}
1169 case 37:
1170 #line 451 "cexp.y"
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; ;
1176 break;}
1177 case 38:
1178 #line 459 "cexp.y"
1179 { yyval.keywords = 0; ;
1180 break;}
1181 case 39:
1182 #line 461 "cexp.y"
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)
1190 temp = temp->next;
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; ;
1195 break;}
1196 case 40:
1197 #line 474 "cexp.y"
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; ;
1202 break;}
1204 /* the action file gets copied in in place of this dollarsign */
1205 #line 487 "/usr/local/share/bison.simple"
1207 yyvsp -= yylen;
1208 yyssp -= yylen;
1209 #ifdef YYLSP_NEEDED
1210 yylsp -= yylen;
1211 #endif
1213 #if YYDEBUG != 0
1214 if (yydebug)
1216 short *ssp1 = yyss - 1;
1217 fprintf (stderr, "state stack now");
1218 while (ssp1 != yyssp)
1219 fprintf (stderr, " %d", *++ssp1);
1220 fprintf (stderr, "\n");
1222 #endif
1224 *++yyvsp = yyval;
1226 #ifdef YYLSP_NEEDED
1227 yylsp++;
1228 if (yylen == 0)
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;
1234 yylsp->text = 0;
1236 else
1238 yylsp->last_line = (yylsp+yylen-1)->last_line;
1239 yylsp->last_column = (yylsp+yylen-1)->last_column;
1241 #endif
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. */
1248 yyn = yyr1[yyn];
1250 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1251 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1252 yystate = yytable[yystate];
1253 else
1254 yystate = yydefgoto[yyn - YYNTBASE];
1256 goto yynewstate;
1258 yyerrlab: /* here on detecting error */
1260 if (! yyerrstatus)
1261 /* If not already recovering from an error, report this error. */
1263 ++yynerrs;
1265 #ifdef YYERROR_VERBOSE
1266 yyn = yypact[yystate];
1268 if (yyn > YYFLAG && yyn < YYLAST)
1270 int size = 0;
1271 char *msg;
1272 int x, count;
1274 count = 0;
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);
1281 if (msg != 0)
1283 strcpy(msg, "parse error");
1285 if (count < 5)
1287 count = 0;
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]);
1294 strcat(msg, "'");
1295 count++;
1298 yyerror(msg);
1299 free(msg);
1301 else
1302 yyerror ("parse error; also virtual memory exceeded");
1304 else
1305 #endif /* YYERROR_VERBOSE */
1306 yyerror("parse error");
1309 goto yyerrlab1;
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)
1318 YYABORT;
1320 #if YYDEBUG != 0
1321 if (yydebug)
1322 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1323 #endif
1325 yychar = YYEMPTY;
1328 /* Else will try to reuse lookahead token
1329 after shifting the error token. */
1331 yyerrstatus = 3; /* Each real token shifted decrements this */
1333 goto yyerrhandle;
1335 yyerrdefault: /* current state does not do anything special for the error token. */
1337 #if 0
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;
1342 #endif
1344 yyerrpop: /* pop the current state because it cannot handle the error token */
1346 if (yyssp == yyss) YYABORT;
1347 yyvsp--;
1348 yystate = *--yyssp;
1349 #ifdef YYLSP_NEEDED
1350 yylsp--;
1351 #endif
1353 #if YYDEBUG != 0
1354 if (yydebug)
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");
1362 #endif
1364 yyerrhandle:
1366 yyn = yypact[yystate];
1367 if (yyn == YYFLAG)
1368 goto yyerrdefault;
1370 yyn += YYTERROR;
1371 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1372 goto yyerrdefault;
1374 yyn = yytable[yyn];
1375 if (yyn < 0)
1377 if (yyn == YYFLAG)
1378 goto yyerrpop;
1379 yyn = -yyn;
1380 goto yyreduce;
1382 else if (yyn == 0)
1383 goto yyerrpop;
1385 if (yyn == YYFINAL)
1386 YYACCEPT;
1388 #if YYDEBUG != 0
1389 if (yydebug)
1390 fprintf(stderr, "Shifting error token, ");
1391 #endif
1393 *++yyvsp = yylval;
1394 #ifdef YYLSP_NEEDED
1395 *++yylsp = yylloc;
1396 #endif
1398 yystate = yyn;
1399 goto yynewstate;
1401 #line 479 "cexp.y"
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 */
1415 static int
1416 parse_number (olen)
1417 int olen;
1419 register char *p = lexptr;
1420 register int c;
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;
1426 int spec_long = 0;
1428 yylval.integer.signedp = SIGNED;
1430 if (*p == '0') {
1431 base = 8;
1432 if (len >= 3 && (p[1] == 'x' || p[1] == 'X')) {
1433 p += 2;
1434 base = 16;
1435 len -= 2;
1439 max_over_base = (unsigned HOST_WIDE_INT) -1 / base;
1441 for (; len > 0; len--) {
1442 c = *p++;
1444 if (c >= '0' && c <= '9')
1445 digit = c - '0';
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;
1450 else {
1451 /* `l' means long, and `u' means unsigned. */
1452 while (1) {
1453 if (c == 'l' || c == 'L')
1455 if (!pedantic < spec_long)
1456 yyerror ("too many `l's in integer constant");
1457 spec_long++;
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;
1465 else {
1466 if (c == '.' || c == 'e' || c == 'E' || c == 'p' || c == 'P')
1467 yyerror ("Floating point numbers not allowed in #if expressions");
1468 else {
1469 char *buf = (char *) alloca (p - lexptr + 40);
1470 sprintf (buf, "missing white space after number `%.*s'",
1471 (int) (p - lexptr - 1), lexptr);
1472 yyerror (buf);
1476 if (--len == 0)
1477 break;
1478 c = *p++;
1480 /* Don't look for any more digits after the suffixes. */
1481 break;
1483 if (largest_digit < digit)
1484 largest_digit = digit;
1485 nd = n * base + digit;
1486 overflow |= (max_over_base < n) | (nd < n);
1487 n = nd;
1490 if (base <= largest_digit)
1491 pedwarn ("integer constant contains digits beyond the radix");
1493 if (overflow)
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)
1499 if (base == 10)
1500 warning ("integer constant is so large that it is unsigned");
1501 yylval.integer.signedp = UNSIGNED;
1504 lexptr = p;
1505 yylval.integer.value = n;
1506 return INT;
1509 struct token {
1510 char *operator;
1511 int token;
1514 static struct token tokentab2[] = {
1515 {"&&", AND},
1516 {"||", OR},
1517 {"<<", LSH},
1518 {">>", RSH},
1519 {"==", EQUAL},
1520 {"!=", NOTEQUAL},
1521 {"<=", LEQ},
1522 {">=", GEQ},
1523 {"++", ERROR},
1524 {"--", ERROR},
1525 {NULL, ERROR}
1528 /* Read one token, getting characters through lexptr. */
1530 static int
1531 yylex ()
1533 register int c;
1534 register int namelen;
1535 register unsigned char *tokstart;
1536 register struct token *toktab;
1537 int wide_flag;
1538 HOST_WIDE_INT mask;
1540 retry:
1542 tokstart = (unsigned char *) lexptr;
1543 c = *tokstart;
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]) {
1548 lexptr += 2;
1549 if (toktab->token == ERROR)
1551 char *buf = (char *) alloca (40);
1552 sprintf (buf, "`%s' not allowed in operand of `#if'", toktab->operator);
1553 yyerror (buf);
1555 return toktab->token;
1558 switch (c) {
1559 case '\n':
1560 return 0;
1562 case ' ':
1563 case '\t':
1564 case '\r':
1565 lexptr++;
1566 goto retry;
1568 case 'L':
1569 /* Capital L may start a wide-string or wide-character constant. */
1570 if (lexptr[1] == '\'')
1572 lexptr++;
1573 wide_flag = 1;
1574 mask = MAX_WCHAR_TYPE_MASK;
1575 goto char_constant;
1577 if (lexptr[1] == '"')
1579 lexptr++;
1580 wide_flag = 1;
1581 mask = MAX_WCHAR_TYPE_MASK;
1582 goto string_constant;
1584 break;
1586 case '\'':
1587 wide_flag = 0;
1588 mask = MAX_CHAR_TYPE_MASK;
1589 char_constant:
1590 lexptr++;
1591 if (keyword_parsing) {
1592 char *start_ptr = lexptr - 1;
1593 while (1) {
1594 c = *lexptr++;
1595 if (c == '\\')
1596 c = parse_escape (&lexptr, mask);
1597 else if (c == '\'')
1598 break;
1600 yylval.name.address = tokstart;
1601 yylval.name.length = lexptr - start_ptr;
1602 return NAME;
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;
1612 int max_chars;
1613 char *token_buffer;
1615 if (wide_flag)
1617 width = MAX_WCHAR_TYPE_SIZE;
1618 #ifdef MULTIBYTE_CHARS
1619 max_chars = MB_CUR_MAX;
1620 #else
1621 max_chars = 1;
1622 #endif
1624 else
1625 max_chars = MAX_LONG_TYPE_SIZE / width;
1627 token_buffer = (char *) alloca (max_chars + 1);
1629 while (1)
1631 c = *lexptr++;
1633 if (c == '\'' || c == EOF)
1634 break;
1636 if (c == '\\')
1638 c = parse_escape (&lexptr, mask);
1641 num_chars++;
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;
1648 else
1649 result = c;
1650 token_buffer[num_chars - 1] = c;
1654 token_buffer[num_chars] = 0;
1656 if (c != '\'')
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. */
1669 if (! wide_flag)
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));
1679 else
1680 yylval.integer.value
1681 = result | ~(~ (unsigned HOST_WIDE_INT) 0
1682 >> (HOST_BITS_PER_WIDE_INT - num_bits));
1684 else
1686 #ifdef MULTIBYTE_CHARS
1687 /* Set the initial shift state and convert the next sequence. */
1688 result = 0;
1689 /* In all locales L'\0' is zero and mbtowc will return zero,
1690 so don't use it. */
1691 if (num_chars > 1
1692 || (num_chars == 1 && token_buffer[0] != '\0'))
1694 wchar_t wc;
1695 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1696 if (mbtowc (& wc, token_buffer, num_chars) == num_chars)
1697 result = wc;
1698 else
1699 pedwarn ("Ignoring invalid multibyte character");
1701 #endif
1702 yylval.integer.value = result;
1706 /* This is always a signed type. */
1707 yylval.integer.signedp = SIGNED;
1709 return CHAR;
1711 /* some of these chars are invalid in constant expressions;
1712 maybe do something about them later */
1713 case '/':
1714 case '+':
1715 case '-':
1716 case '*':
1717 case '%':
1718 case '|':
1719 case '&':
1720 case '^':
1721 case '~':
1722 case '!':
1723 case '@':
1724 case '<':
1725 case '>':
1726 case '[':
1727 case ']':
1728 case '.':
1729 case '?':
1730 case ':':
1731 case '=':
1732 case '{':
1733 case '}':
1734 case ',':
1735 case '#':
1736 if (keyword_parsing)
1737 break;
1738 case '(':
1739 case ')':
1740 lexptr++;
1741 return c;
1743 case '"':
1744 mask = MAX_CHAR_TYPE_MASK;
1745 string_constant:
1746 if (keyword_parsing) {
1747 char *start_ptr = lexptr;
1748 lexptr++;
1749 while (1) {
1750 c = *lexptr++;
1751 if (c == '\\')
1752 c = parse_escape (&lexptr, mask);
1753 else if (c == '"')
1754 break;
1756 yylval.name.address = tokstart;
1757 yylval.name.length = lexptr - start_ptr;
1758 return NAME;
1760 yyerror ("string constants not allowed in #if expressions");
1761 return ERROR;
1764 if (c >= '0' && c <= '9' && !keyword_parsing) {
1765 /* It's a number */
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))
1772 && ! traditional)))
1773 break;
1774 c = d;
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]])
1784 break;
1785 if (tokstart[namelen] == '(' || tokstart[namelen] == ')')
1786 break;
1787 if (tokstart[namelen] == '"' || tokstart[namelen] == '\'')
1788 break;
1790 } else {
1791 if (!is_idstart[c]) {
1792 yyerror ("Invalid token in expression");
1793 return ERROR;
1796 for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
1800 lexptr += namelen;
1801 yylval.name.address = tokstart;
1802 yylval.name.length = namelen;
1803 return NAME;
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. */
1824 HOST_WIDE_INT
1825 parse_escape (string_ptr, result_mask)
1826 char **string_ptr;
1827 HOST_WIDE_INT result_mask;
1829 register int c = *(*string_ptr)++;
1830 switch (c)
1832 case 'a':
1833 return TARGET_BELL;
1834 case 'b':
1835 return TARGET_BS;
1836 case 'e':
1837 case 'E':
1838 if (pedantic)
1839 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1840 return 033;
1841 case 'f':
1842 return TARGET_FF;
1843 case 'n':
1844 return TARGET_NEWLINE;
1845 case 'r':
1846 return TARGET_CR;
1847 case 't':
1848 return TARGET_TAB;
1849 case 'v':
1850 return TARGET_VT;
1851 case '\n':
1852 return -2;
1853 case 0:
1854 (*string_ptr)--;
1855 return 0;
1857 case '0':
1858 case '1':
1859 case '2':
1860 case '3':
1861 case '4':
1862 case '5':
1863 case '6':
1864 case '7':
1866 register HOST_WIDE_INT i = c - '0';
1867 register int count = 0;
1868 while (++count < 3)
1870 c = *(*string_ptr)++;
1871 if (c >= '0' && c <= '7')
1872 i = (i << 3) + c - '0';
1873 else
1875 (*string_ptr)--;
1876 break;
1879 if (i != (i & result_mask))
1881 i &= result_mask;
1882 pedwarn ("octal escape sequence out of range");
1884 return i;
1886 case 'x':
1888 register unsigned HOST_WIDE_INT i = 0, overflow = 0;
1889 register int digits_found = 0, digit;
1890 for (;;)
1892 c = *(*string_ptr)++;
1893 if (c >= '0' && c <= '9')
1894 digit = c - '0';
1895 else if (c >= 'a' && c <= 'f')
1896 digit = c - 'a' + 10;
1897 else if (c >= 'A' && c <= 'F')
1898 digit = c - 'A' + 10;
1899 else
1901 (*string_ptr)--;
1902 break;
1904 overflow |= i ^ (i << 4 >> 4);
1905 i = (i << 4) + digit;
1906 digits_found = 1;
1908 if (!digits_found)
1909 yyerror ("\\x used with no following hex digits");
1910 if (overflow | (i != (i & result_mask)))
1912 i &= result_mask;
1913 pedwarn ("hex escape sequence out of range");
1915 return i;
1917 default:
1918 return c;
1922 static void
1923 yyerror (s)
1924 char *s;
1926 error ("%s", s);
1927 skip_evaluation = 0;
1928 longjmp (parse_return_error, 1);
1931 static void
1932 integer_overflow ()
1934 if (!skip_evaluation && pedantic)
1935 pedwarn ("integer overflow in preprocessor expression");
1938 static HOST_WIDE_INT
1939 left_shift (a, b)
1940 struct constant *a;
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)
1947 return 0;
1948 else
1949 return (unsigned HOST_WIDE_INT) a->value << b;
1952 static HOST_WIDE_INT
1953 right_shift (a, b)
1954 struct constant *a;
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;
1961 else
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. */
1974 HOST_WIDE_INT
1975 parse_c_expression (string)
1976 char *string;
1978 lexptr = 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))
1984 return 0;
1986 if (yyparse () != 0)
1987 abort ();
1989 if (*lexptr != '\n')
1990 error ("Junk after end of expression.");
1992 return expression_value; /* set by yyparse () */
1995 #ifdef TEST_EXP_READER
1997 #if YYDEBUG
1998 extern int yydebug;
1999 #endif
2001 int pedantic;
2002 int traditional;
2004 int main PROTO((int, char **));
2005 static void initialize_random_junk PROTO((void));
2007 /* Main program for testing purposes. */
2009 main (argc, argv)
2010 int argc;
2011 char **argv;
2013 int n, c;
2014 char buf[1024];
2016 pedantic = 1 < argc;
2017 traditional = 2 < argc;
2018 #if YYDEBUG
2019 yydebug = 3 < argc;
2020 #endif
2021 initialize_random_junk ();
2023 for (;;) {
2024 printf ("enter expression: ");
2025 n = 0;
2026 while ((buf[n] = c = getchar ()) != '\n' && c != EOF)
2027 n++;
2028 if (c == EOF)
2029 break;
2030 printf ("parser returned %ld\n", (long) parse_c_expression (buf));
2033 return 0;
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
2046 static void
2047 initialize_random_junk ()
2049 register int i;
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
2055 * refer to them.
2057 for (i = 'a'; i <= 'z'; i++) {
2058 ++is_idchar[i - 'a' + 'A'];
2059 ++is_idchar[i];
2060 ++is_idstart[i - 'a' + 'A'];
2061 ++is_idstart[i];
2063 for (i = '0'; i <= '9'; i++)
2064 ++is_idchar[i];
2065 ++is_idchar['_'];
2066 ++is_idstart['_'];
2067 ++is_idchar['$'];
2068 ++is_idstart['$'];
2070 ++is_space[' '];
2071 ++is_space['\t'];
2072 ++is_space['\v'];
2073 ++is_space['\f'];
2074 ++is_space['\n'];
2075 ++is_space['\r'];
2078 void
2079 error (PRINTF_ALIST (msg))
2080 PRINTF_DCL (msg)
2082 va_list args;
2084 VA_START (args, msg);
2085 fprintf (stderr, "error: ");
2086 vfprintf (stderr, msg, args);
2087 fprintf (stderr, "\n");
2088 va_end (args);
2091 void
2092 pedwarn (PRINTF_ALIST (msg))
2093 PRINTF_DCL (msg)
2095 va_list args;
2097 VA_START (args, msg);
2098 fprintf (stderr, "pedwarn: ");
2099 vfprintf (stderr, msg, args);
2100 fprintf (stderr, "\n");
2101 va_end (args);
2104 void
2105 warning (PRINTF_ALIST (msg))
2106 PRINTF_DCL (msg)
2108 va_list args;
2110 VA_START (args, msg);
2111 fprintf (stderr, "warning: ");
2112 vfprintf (stderr, msg, args);
2113 fprintf (stderr, "\n");
2114 va_end (args);
2118 check_assertion (name, sym_length, tokens_specified, tokens)
2119 U_CHAR *name;
2120 int sym_length;
2121 int tokens_specified;
2122 struct arglist *tokens;
2124 return 0;
2127 struct hashnode *
2128 lookup (name, len, hash)
2129 U_CHAR *name;
2130 int len;
2131 int hash;
2133 return (DEFAULT_SIGNED_CHAR) ? 0 : ((struct hashnode *) -1);
2136 GENERIC_PTR
2137 xmalloc (size)
2138 size_t size;
2140 return (GENERIC_PTR) malloc (size);
2142 #endif