define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / tools / cxref / cpp / cexp.c
blobfbed695ac0a74ba99f9996aaceb7226482b01199
2 /* A Bison parser, made from cexp.y with Bison version GNU Bison version 1.22
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
22 #include "config.h"
23 #include <setjmp.h>
24 /* #define YYDEBUG 1 */
26 #ifdef MULTIBYTE_CHARS
27 #include <stdlib.h>
28 #include <locale.h>
29 #endif
31 #include <stdio.h>
33 typedef unsigned char U_CHAR;
35 /* This is used for communicating lists of keywords with cccp.c. */
36 struct arglist {
37 struct arglist *next;
38 U_CHAR *name;
39 int length;
40 int argno;
43 /* Define a generic NULL if one hasn't already been defined. */
45 #ifndef NULL
46 #define NULL 0
47 #endif
49 #ifndef GENERIC_PTR
50 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
51 #define GENERIC_PTR void *
52 #else
53 #define GENERIC_PTR char *
54 #endif
55 #endif
57 /* Find the largest host integer type and set its size and type. */
59 #ifndef HOST_BITS_PER_WIDE_INT
61 #if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
62 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
63 #define HOST_WIDE_INT long
64 #else
65 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
66 #define HOST_WIDE_INT int
67 #endif
69 #endif
71 #ifndef NULL_PTR
72 #define NULL_PTR ((GENERIC_PTR)0)
73 #endif
75 int yylex ();
76 void yyerror ();
77 HOST_WIDE_INT expression_value;
79 static jmp_buf parse_return_error;
81 /* Nonzero means count most punctuation as part of a name. */
82 static int keyword_parsing = 0;
84 /* Nonzero means do not evaluate this expression.
85 This is a count, since unevaluated expressions can nest. */
86 static int skip_evaluation;
88 /* some external tables of character types */
89 extern unsigned char is_idstart[], is_idchar[], is_hor_space[];
91 extern char *xmalloc ();
93 /* Flag for -pedantic. */
94 extern int pedantic;
96 /* Flag for -traditional. */
97 extern int traditional;
99 #ifndef CHAR_TYPE_SIZE
100 #define CHAR_TYPE_SIZE BITS_PER_UNIT
101 #endif
103 #ifndef INT_TYPE_SIZE
104 #define INT_TYPE_SIZE BITS_PER_WORD
105 #endif
107 #ifndef LONG_TYPE_SIZE
108 #define LONG_TYPE_SIZE BITS_PER_WORD
109 #endif
111 #ifndef WCHAR_TYPE_SIZE
112 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
113 #endif
115 #ifndef MAX_CHAR_TYPE_SIZE
116 #define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE
117 #endif
119 #ifndef MAX_INT_TYPE_SIZE
120 #define MAX_INT_TYPE_SIZE INT_TYPE_SIZE
121 #endif
123 #ifndef MAX_LONG_TYPE_SIZE
124 #define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE
125 #endif
127 #ifndef MAX_WCHAR_TYPE_SIZE
128 #define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
129 #endif
131 /* Yield nonzero if adding two numbers with A's and B's signs can yield a
132 number with SUM's sign, where A, B, and SUM are all C integers. */
133 #define possible_sum_sign(a, b, sum) ((((a) ^ (b)) | ~ ((a) ^ (sum))) < 0)
135 static void integer_overflow ();
136 static long left_shift ();
137 static long right_shift ();
139 typedef union {
140 struct constant {long value; int unsignedp;} integer;
141 struct name {U_CHAR *address; int length;} name;
142 struct arglist *keywords;
143 } YYSTYPE;
145 #ifndef YYLTYPE
146 typedef
147 struct yyltype
149 int timestamp;
150 int first_line;
151 int first_column;
152 int last_line;
153 int last_column;
154 char *text;
156 yyltype;
158 #define YYLTYPE yyltype
159 #endif
161 #include <stdio.h>
163 #ifndef __cplusplus
164 #ifndef __STDC__
165 #define const
166 #endif
167 #endif
171 #define YYFINAL 77
172 #define YYFLAG -32768
173 #define YYNTBASE 34
175 #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 43)
177 static const char yytranslate[] = { 0,
178 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
179 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
180 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
181 2, 2, 29, 2, 31, 2, 27, 14, 2, 32,
182 33, 25, 23, 9, 24, 2, 26, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 2, 8, 2, 17,
184 2, 18, 7, 2, 2, 2, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
187 2, 2, 2, 13, 2, 2, 2, 2, 2, 2,
188 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
189 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
190 2, 2, 2, 12, 2, 30, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
194 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
195 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
196 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
197 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
198 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
199 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
200 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
201 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
202 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
203 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
204 6, 10, 11, 15, 16, 19, 20, 21, 22, 28
207 #if YYDEBUG != 0
208 static const short yyprhs[] = { 0,
209 0, 2, 4, 8, 11, 14, 17, 20, 23, 24,
210 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
211 71, 75, 79, 83, 87, 91, 95, 99, 100, 105,
212 106, 111, 112, 113, 121, 123, 125, 127, 128, 133
215 static const short yyrhs[] = { 35,
216 0, 36, 0, 35, 9, 36, 0, 24, 36, 0,
217 29, 36, 0, 23, 36, 0, 30, 36, 0, 31,
218 5, 0, 0, 31, 5, 37, 32, 42, 33, 0,
219 32, 35, 33, 0, 36, 25, 36, 0, 36, 26,
220 36, 0, 36, 27, 36, 0, 36, 23, 36, 0,
221 36, 24, 36, 0, 36, 21, 36, 0, 36, 22,
222 36, 0, 36, 15, 36, 0, 36, 16, 36, 0,
223 36, 19, 36, 0, 36, 20, 36, 0, 36, 17,
224 36, 0, 36, 18, 36, 0, 36, 14, 36, 0,
225 36, 13, 36, 0, 36, 12, 36, 0, 0, 36,
226 11, 38, 36, 0, 0, 36, 10, 39, 36, 0,
227 0, 0, 36, 7, 40, 36, 8, 41, 36, 0,
228 3, 0, 4, 0, 5, 0, 0, 32, 42, 33,
229 42, 0, 5, 42, 0
232 #endif
234 #if YYDEBUG != 0
235 static const short yyrline[] = { 0,
236 176, 181, 182, 189, 194, 197, 199, 202, 206, 208,
237 213, 218, 230, 246, 258, 265, 272, 278, 284, 287,
238 290, 296, 302, 308, 314, 317, 320, 323, 326, 329,
239 332, 335, 337, 340, 343, 345, 347, 352, 354, 367
242 static const char * const yytname[] = { "$","error","$illegal.","INT","CHAR",
243 "NAME","ERROR","'?'","':'","','","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL",
244 "'<'","'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'","UNARY","'!'",
245 "'~'","'#'","'('","')'","start","exp1","exp","@1","@2","@3","@4","@5","keywords",
248 #endif
250 static const short yyr1[] = { 0,
251 34, 35, 35, 36, 36, 36, 36, 36, 37, 36,
252 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
253 36, 36, 36, 36, 36, 36, 36, 38, 36, 39,
254 36, 40, 41, 36, 36, 36, 36, 42, 42, 42
257 static const short yyr2[] = { 0,
258 1, 1, 3, 2, 2, 2, 2, 2, 0, 6,
259 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
260 3, 3, 3, 3, 3, 3, 3, 0, 4, 0,
261 4, 0, 0, 7, 1, 1, 1, 0, 4, 2
264 static const short yydefact[] = { 0,
265 35, 36, 37, 0, 0, 0, 0, 0, 0, 1,
266 2, 6, 4, 5, 7, 8, 0, 0, 32, 30,
267 28, 0, 0, 0, 0, 0, 0, 0, 0, 0,
268 0, 0, 0, 0, 0, 0, 0, 0, 11, 3,
269 0, 0, 0, 27, 26, 25, 19, 20, 23, 24,
270 21, 22, 17, 18, 15, 16, 12, 13, 14, 38,
271 0, 31, 29, 38, 38, 0, 33, 40, 0, 10,
272 0, 38, 34, 39, 0, 0, 0
275 static const short yydefgoto[] = { 75,
276 10, 11, 38, 43, 42, 41, 71, 66
279 static const short yypact[] = { 12,
280 -32768,-32768,-32768, 12, 12, 12, 12, 1, 12, 4,
281 79,-32768,-32768,-32768,-32768, -21, 31, 12,-32768,-32768,
282 -32768, 12, 12, 12, 12, 12, 12, 12, 12, 12,
283 12, 12, 12, 12, 12, 12, 12, 30,-32768, 79,
284 12, 12, 12, 110, 124, 137, 148, 148, 155, 155,
285 155, 155, 160, 160, -17, -17,-32768,-32768,-32768, 2,
286 58, 34, 95, 2, 2, 54,-32768,-32768, 55,-32768,
287 12, 2, 79,-32768, 63, 188,-32768
290 static const short yypgoto[] = {-32768,
291 180, -4,-32768,-32768,-32768,-32768,-32768, -60
295 #define YYLAST 189
298 static const short yytable[] = { 12,
299 13, 14, 15, 68, 69, 16, 64, 35, 36, 37,
300 -9, 74, 18, 40, 1, 2, 3, 44, 45, 46,
301 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
302 57, 58, 59, 65, 4, 5, 61, 62, 63, 18,
303 6, 7, 8, 9, 21, 22, 23, 24, 25, 26,
304 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
305 37, 60, 76, 39, 19, 67, 73, 20, 21, 22,
306 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
307 33, 34, 35, 36, 37, 19, 70, 72, 20, 21,
308 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
309 32, 33, 34, 35, 36, 37, 22, 23, 24, 25,
310 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
311 36, 37, 23, 24, 25, 26, 27, 28, 29, 30,
312 31, 32, 33, 34, 35, 36, 37, 24, 25, 26,
313 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
314 37, 25, 26, 27, 28, 29, 30, 31, 32, 33,
315 34, 35, 36, 37, 27, 28, 29, 30, 31, 32,
316 33, 34, 35, 36, 37, 31, 32, 33, 34, 35,
317 36, 37, 33, 34, 35, 36, 37, 77, 17
320 static const short yycheck[] = { 4,
321 5, 6, 7, 64, 65, 5, 5, 25, 26, 27,
322 32, 72, 9, 18, 3, 4, 5, 22, 23, 24,
323 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
324 35, 36, 37, 32, 23, 24, 41, 42, 43, 9,
325 29, 30, 31, 32, 11, 12, 13, 14, 15, 16,
326 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
327 27, 32, 0, 33, 7, 8, 71, 10, 11, 12,
328 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
329 23, 24, 25, 26, 27, 7, 33, 33, 10, 11,
330 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
331 22, 23, 24, 25, 26, 27, 12, 13, 14, 15,
332 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
333 26, 27, 13, 14, 15, 16, 17, 18, 19, 20,
334 21, 22, 23, 24, 25, 26, 27, 14, 15, 16,
335 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
336 27, 15, 16, 17, 18, 19, 20, 21, 22, 23,
337 24, 25, 26, 27, 17, 18, 19, 20, 21, 22,
338 23, 24, 25, 26, 27, 21, 22, 23, 24, 25,
339 26, 27, 23, 24, 25, 26, 27, 0, 9
341 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
344 /* Skeleton output parser for bison,
345 Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
347 This program is free software; you can redistribute it and/or modify
348 it under the terms of the GNU General Public License as published by
349 the Free Software Foundation; either version 1, or (at your option)
350 any later version.
352 This program is distributed in the hope that it will be useful,
353 but WITHOUT ANY WARRANTY; without even the implied warranty of
354 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
355 GNU General Public License for more details.
357 You should have received a copy of the GNU General Public License
358 along with this program; if not, write to the Free Software
359 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
362 #ifndef alloca
363 #ifdef __GNUC__
364 #define alloca __builtin_alloca
365 #else /* not GNU C. */
366 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
367 #include <alloca.h>
368 #else /* not sparc */
369 #if defined (MSDOS) && !defined (__TURBOC__)
370 #include <malloc.h>
371 #else /* not MSDOS, or __TURBOC__ */
372 #if defined(_AIX)
373 #include <malloc.h>
374 #pragma alloca
375 #else /* not MSDOS, __TURBOC__, or _AIX */
376 #ifdef __hpux
377 #ifdef __cplusplus
378 extern "C" {
379 void *alloca (unsigned int);
381 #else /* not __cplusplus */
382 void *alloca ();
383 #endif /* not __cplusplus */
384 #endif /* __hpux */
385 #endif /* not _AIX */
386 #endif /* not MSDOS, or __TURBOC__ */
387 #endif /* not sparc. */
388 #endif /* not GNU C. */
389 #endif /* alloca not defined. */
391 /* This is the parser code that is written into each bison parser
392 when the %semantic_parser declaration is not specified in the grammar.
393 It was written by Richard Stallman by simplifying the hairy parser
394 used when %semantic_parser is specified. */
396 /* Note: there must be only one dollar sign in this file.
397 It is replaced by the list of actions, each action
398 as one case of the switch. */
400 #define yyerrok (yyerrstatus = 0)
401 #define yyclearin (yychar = YYEMPTY)
402 #define YYEMPTY -2
403 #define YYEOF 0
404 #define YYACCEPT return(0)
405 #define YYABORT return(1)
406 #define YYERROR goto yyerrlab1
407 /* Like YYERROR except do call yyerror.
408 This remains here temporarily to ease the
409 transition to the new meaning of YYERROR, for GCC.
410 Once GCC version 2 has supplanted version 1, this can go. */
411 #define YYFAIL goto yyerrlab
412 #define YYRECOVERING() (!!yyerrstatus)
413 #define YYBACKUP(token, value) \
414 do \
415 if (yychar == YYEMPTY && yylen == 1) \
416 { yychar = (token), yylval = (value); \
417 yychar1 = YYTRANSLATE (yychar); \
418 YYPOPSTACK; \
419 goto yybackup; \
421 else \
422 { yyerror ("syntax error: cannot back up"); YYERROR; } \
423 while (0)
425 #define YYTERROR 1
426 #define YYERRCODE 256
428 #ifndef YYPURE
429 #define YYLEX yylex()
430 #endif
432 #ifdef YYPURE
433 #ifdef YYLSP_NEEDED
434 #define YYLEX yylex(&yylval, &yylloc)
435 #else
436 #define YYLEX yylex(&yylval)
437 #endif
438 #endif
440 /* If nonreentrant, generate the variables here */
442 #ifndef YYPURE
444 int yychar; /* the lookahead symbol */
445 YYSTYPE yylval; /* the semantic value of the */
446 /* lookahead symbol */
448 #ifdef YYLSP_NEEDED
449 YYLTYPE yylloc; /* location data for the lookahead */
450 /* symbol */
451 #endif
453 int yynerrs; /* number of parse errors so far */
454 #endif /* not YYPURE */
456 #if YYDEBUG != 0
457 int yydebug; /* nonzero means print parse trace */
458 /* Since this is uninitialized, it does not stop multiple parsers
459 from coexisting. */
460 #endif
462 /* YYINITDEPTH indicates the initial size of the parser's stacks */
464 #ifndef YYINITDEPTH
465 #define YYINITDEPTH 200
466 #endif
468 /* YYMAXDEPTH is the maximum size the stacks can grow to
469 (effective only if the built-in stack extension method is used). */
471 #if YYMAXDEPTH == 0
472 #undef YYMAXDEPTH
473 #endif
475 #ifndef YYMAXDEPTH
476 #define YYMAXDEPTH 10000
477 #endif
479 /* Prevent warning if -Wstrict-prototypes. */
480 #ifdef __GNUC__
481 int yyparse (void);
482 #endif
484 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
485 #define __yy_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
486 #else /* not GNU C or C++ */
487 #ifndef __cplusplus
489 /* This is the most reliable way to avoid incompatibilities
490 in available built-in functions on various systems. */
491 static void
492 __yy_bcopy (from, to, count)
493 char *from;
494 char *to;
495 int count;
497 register char *f = from;
498 register char *t = to;
499 register int i = count;
501 while (i-- > 0)
502 *t++ = *f++;
505 #else /* __cplusplus */
507 /* This is the most reliable way to avoid incompatibilities
508 in available built-in functions on various systems. */
509 static void
510 __yy_bcopy (char *from, char *to, int count)
512 register char *f = from;
513 register char *t = to;
514 register int i = count;
516 while (i-- > 0)
517 *t++ = *f++;
520 #endif
521 #endif
525 yyparse()
527 register int yystate;
528 register int yyn;
529 register short *yyssp;
530 register YYSTYPE *yyvsp;
531 int yyerrstatus; /* number of tokens to shift before error messages enabled */
532 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
534 short yyssa[YYINITDEPTH]; /* the state stack */
535 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
537 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
538 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
540 #ifdef YYLSP_NEEDED
541 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
542 YYLTYPE *yyls = yylsa;
543 YYLTYPE *yylsp;
545 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
546 #else
547 #define YYPOPSTACK (yyvsp--, yyssp--)
548 #endif
550 int yystacksize = YYINITDEPTH;
552 #ifdef YYPURE
553 int yychar;
554 YYSTYPE yylval;
555 int yynerrs;
556 #ifdef YYLSP_NEEDED
557 YYLTYPE yylloc;
558 #endif
559 #endif
561 YYSTYPE yyval; /* the variable used to return */
562 /* semantic values from the action */
563 /* routines */
565 int yylen;
567 #if YYDEBUG != 0
568 if (yydebug)
569 fprintf(stderr, "Starting parse\n");
570 #endif
572 yystate = 0;
573 yyerrstatus = 0;
574 yynerrs = 0;
575 yychar = YYEMPTY; /* Cause a token to be read. */
577 /* Initialize stack pointers.
578 Waste one element of value and location stack
579 so that they stay on the same level as the state stack.
580 The wasted elements are never initialized. */
582 yyssp = yyss - 1;
583 yyvsp = yyvs;
584 #ifdef YYLSP_NEEDED
585 yylsp = yyls;
586 #endif
588 /* Push a new state, which is found in yystate . */
589 /* In all cases, when you get here, the value and location stacks
590 have just been pushed. so pushing a state here evens the stacks. */
591 yynewstate:
593 *++yyssp = yystate;
595 if (yyssp >= yyss + yystacksize - 1)
597 /* Give user a chance to reallocate the stack */
598 /* Use copies of these so that the &'s don't force the real ones into memory. */
599 YYSTYPE *yyvs1 = yyvs;
600 short *yyss1 = yyss;
601 #ifdef YYLSP_NEEDED
602 YYLTYPE *yyls1 = yyls;
603 #endif
605 /* Get the current used size of the three stacks, in elements. */
606 int size = yyssp - yyss + 1;
608 #ifdef yyoverflow
609 /* Each stack pointer address is followed by the size of
610 the data in use in that stack, in bytes. */
611 #ifdef YYLSP_NEEDED
612 /* This used to be a conditional around just the two extra args,
613 but that might be undefined if yyoverflow is a macro. */
614 yyoverflow("parser stack overflow",
615 &yyss1, size * sizeof (*yyssp),
616 &yyvs1, size * sizeof (*yyvsp),
617 &yyls1, size * sizeof (*yylsp),
618 &yystacksize);
619 #else
620 yyoverflow("parser stack overflow",
621 &yyss1, size * sizeof (*yyssp),
622 &yyvs1, size * sizeof (*yyvsp),
623 &yystacksize);
624 #endif
626 yyss = yyss1; yyvs = yyvs1;
627 #ifdef YYLSP_NEEDED
628 yyls = yyls1;
629 #endif
630 #else /* no yyoverflow */
631 /* Extend the stack our own way. */
632 if (yystacksize >= YYMAXDEPTH)
634 yyerror("parser stack overflow");
635 return 2;
637 yystacksize *= 2;
638 if (yystacksize > YYMAXDEPTH)
639 yystacksize = YYMAXDEPTH;
640 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
641 __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
642 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
643 __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
644 #ifdef YYLSP_NEEDED
645 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
646 __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
647 #endif
648 #endif /* no yyoverflow */
650 yyssp = yyss + size - 1;
651 yyvsp = yyvs + size - 1;
652 #ifdef YYLSP_NEEDED
653 yylsp = yyls + size - 1;
654 #endif
656 #if YYDEBUG != 0
657 if (yydebug)
658 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
659 #endif
661 if (yyssp >= yyss + yystacksize - 1)
662 YYABORT;
665 #if YYDEBUG != 0
666 if (yydebug)
667 fprintf(stderr, "Entering state %d\n", yystate);
668 #endif
670 goto yybackup;
671 yybackup:
673 /* Do appropriate processing given the current state. */
674 /* Read a lookahead token if we need one and don't already have one. */
675 /* yyresume: */
677 /* First try to decide what to do without reference to lookahead token. */
679 yyn = yypact[yystate];
680 if (yyn == YYFLAG)
681 goto yydefault;
683 /* Not known => get a lookahead token if don't already have one. */
685 /* yychar is either YYEMPTY or YYEOF
686 or a valid token in external form. */
688 if (yychar == YYEMPTY)
690 #if YYDEBUG != 0
691 if (yydebug)
692 fprintf(stderr, "Reading a token: ");
693 #endif
694 yychar = YYLEX;
697 /* Convert token to internal form (in yychar1) for indexing tables with */
699 if (yychar <= 0) /* This means end of input. */
701 yychar1 = 0;
702 yychar = YYEOF; /* Don't call YYLEX any more */
704 #if YYDEBUG != 0
705 if (yydebug)
706 fprintf(stderr, "Now at end of input.\n");
707 #endif
709 else
711 yychar1 = YYTRANSLATE(yychar);
713 #if YYDEBUG != 0
714 if (yydebug)
716 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
717 /* Give the individual parser a way to print the precise meaning
718 of a token, for further debugging info. */
719 #ifdef YYPRINT
720 YYPRINT (stderr, yychar, yylval);
721 #endif
722 fprintf (stderr, ")\n");
724 #endif
727 yyn += yychar1;
728 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
729 goto yydefault;
731 yyn = yytable[yyn];
733 /* yyn is what to do for this token type in this state.
734 Negative => reduce, -yyn is rule number.
735 Positive => shift, yyn is new state.
736 New state is final state => don't bother to shift,
737 just return success.
738 0, or most negative number => error. */
740 if (yyn < 0)
742 if (yyn == YYFLAG)
743 goto yyerrlab;
744 yyn = -yyn;
745 goto yyreduce;
747 else if (yyn == 0)
748 goto yyerrlab;
750 if (yyn == YYFINAL)
751 YYACCEPT;
753 /* Shift the lookahead token. */
755 #if YYDEBUG != 0
756 if (yydebug)
757 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
758 #endif
760 /* Discard the token being shifted unless it is eof. */
761 if (yychar != YYEOF)
762 yychar = YYEMPTY;
764 *++yyvsp = yylval;
765 #ifdef YYLSP_NEEDED
766 *++yylsp = yylloc;
767 #endif
769 /* count tokens shifted since error; after three, turn off error status. */
770 if (yyerrstatus) yyerrstatus--;
772 yystate = yyn;
773 goto yynewstate;
775 /* Do the default action for the current state. */
776 yydefault:
778 yyn = yydefact[yystate];
779 if (yyn == 0)
780 goto yyerrlab;
782 /* Do a reduction. yyn is the number of a rule to reduce with. */
783 yyreduce:
784 yylen = yyr2[yyn];
785 if (yylen > 0)
786 yyval = yyvsp[1-yylen]; /* implement default value of the action */
788 #if YYDEBUG != 0
789 if (yydebug)
791 int i;
793 fprintf (stderr, "Reducing via rule %d (line %d), ",
794 yyn, yyrline[yyn]);
796 /* Print the symbols being reduced, and their result. */
797 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
798 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
799 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
801 #endif
804 switch (yyn) {
806 case 1:
807 { expression_value = yyvsp[0].integer.value; ;
808 break;}
809 case 3:
810 { if (pedantic)
811 pedwarn ("comma operator in operand of `#if'");
812 yyval.integer = yyvsp[0].integer; ;
813 break;}
814 case 4:
815 { yyval.integer.value = - yyvsp[0].integer.value;
816 if ((yyval.integer.value & yyvsp[0].integer.value) < 0 && ! yyvsp[0].integer.unsignedp)
817 integer_overflow ();
818 yyval.integer.unsignedp = yyvsp[0].integer.unsignedp; ;
819 break;}
820 case 5:
821 { yyval.integer.value = ! yyvsp[0].integer.value;
822 yyval.integer.unsignedp = 0; ;
823 break;}
824 case 6:
825 { yyval.integer = yyvsp[0].integer; ;
826 break;}
827 case 7:
828 { yyval.integer.value = ~ yyvsp[0].integer.value;
829 yyval.integer.unsignedp = yyvsp[0].integer.unsignedp; ;
830 break;}
831 case 8:
832 { yyval.integer.value = check_assertion (yyvsp[0].name.address, yyvsp[0].name.length,
833 0, NULL_PTR);
834 yyval.integer.unsignedp = 0; ;
835 break;}
836 case 9:
837 { keyword_parsing = 1; ;
838 break;}
839 case 10:
840 { yyval.integer.value = check_assertion (yyvsp[-4].name.address, yyvsp[-4].name.length,
841 1, yyvsp[-1].keywords);
842 keyword_parsing = 0;
843 yyval.integer.unsignedp = 0; ;
844 break;}
845 case 11:
846 { yyval.integer = yyvsp[-1].integer; ;
847 break;}
848 case 12:
849 { yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
850 if (yyval.integer.unsignedp)
851 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value * yyvsp[0].integer.value;
852 else
854 yyval.integer.value = yyvsp[-2].integer.value * yyvsp[0].integer.value;
855 if (yyvsp[-2].integer.value
856 && (yyval.integer.value / yyvsp[-2].integer.value != yyvsp[0].integer.value
857 || (yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0))
858 integer_overflow ();
860 break;}
861 case 13:
862 { if (yyvsp[0].integer.value == 0)
864 if (!skip_evaluation)
865 error ("division by zero in #if");
866 yyvsp[0].integer.value = 1;
868 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
869 if (yyval.integer.unsignedp)
870 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value / yyvsp[0].integer.value;
871 else
873 yyval.integer.value = yyvsp[-2].integer.value / yyvsp[0].integer.value;
874 if ((yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0)
875 integer_overflow ();
877 break;}
878 case 14:
879 { if (yyvsp[0].integer.value == 0)
881 if (!skip_evaluation)
882 error ("division by zero in #if");
883 yyvsp[0].integer.value = 1;
885 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
886 if (yyval.integer.unsignedp)
887 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value % yyvsp[0].integer.value;
888 else
889 yyval.integer.value = yyvsp[-2].integer.value % yyvsp[0].integer.value; ;
890 break;}
891 case 15:
892 { yyval.integer.value = yyvsp[-2].integer.value + yyvsp[0].integer.value;
893 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
894 if (! yyval.integer.unsignedp
895 && ! possible_sum_sign (yyvsp[-2].integer.value, yyvsp[0].integer.value,
896 yyval.integer.value))
897 integer_overflow (); ;
898 break;}
899 case 16:
900 { yyval.integer.value = yyvsp[-2].integer.value - yyvsp[0].integer.value;
901 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
902 if (! yyval.integer.unsignedp
903 && ! possible_sum_sign (yyval.integer.value, yyvsp[0].integer.value,
904 yyvsp[-2].integer.value))
905 integer_overflow (); ;
906 break;}
907 case 17:
908 { yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp;
909 if (yyvsp[0].integer.value < 0 && ! yyvsp[0].integer.unsignedp)
910 yyval.integer.value = right_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
911 else
912 yyval.integer.value = left_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
913 break;}
914 case 18:
915 { yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp;
916 if (yyvsp[0].integer.value < 0 && ! yyvsp[0].integer.unsignedp)
917 yyval.integer.value = left_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
918 else
919 yyval.integer.value = right_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
920 break;}
921 case 19:
922 { yyval.integer.value = (yyvsp[-2].integer.value == yyvsp[0].integer.value);
923 yyval.integer.unsignedp = 0; ;
924 break;}
925 case 20:
926 { yyval.integer.value = (yyvsp[-2].integer.value != yyvsp[0].integer.value);
927 yyval.integer.unsignedp = 0; ;
928 break;}
929 case 21:
930 { yyval.integer.unsignedp = 0;
931 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
932 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value <= yyvsp[0].integer.value;
933 else
934 yyval.integer.value = yyvsp[-2].integer.value <= yyvsp[0].integer.value; ;
935 break;}
936 case 22:
937 { yyval.integer.unsignedp = 0;
938 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
939 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value >= yyvsp[0].integer.value;
940 else
941 yyval.integer.value = yyvsp[-2].integer.value >= yyvsp[0].integer.value; ;
942 break;}
943 case 23:
944 { yyval.integer.unsignedp = 0;
945 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
946 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value < yyvsp[0].integer.value;
947 else
948 yyval.integer.value = yyvsp[-2].integer.value < yyvsp[0].integer.value; ;
949 break;}
950 case 24:
951 { yyval.integer.unsignedp = 0;
952 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
953 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value > yyvsp[0].integer.value;
954 else
955 yyval.integer.value = yyvsp[-2].integer.value > yyvsp[0].integer.value; ;
956 break;}
957 case 25:
958 { yyval.integer.value = yyvsp[-2].integer.value & yyvsp[0].integer.value;
959 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; ;
960 break;}
961 case 26:
962 { yyval.integer.value = yyvsp[-2].integer.value ^ yyvsp[0].integer.value;
963 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; ;
964 break;}
965 case 27:
966 { yyval.integer.value = yyvsp[-2].integer.value | yyvsp[0].integer.value;
967 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; ;
968 break;}
969 case 28:
970 { skip_evaluation += !yyvsp[-1].integer.value; ;
971 break;}
972 case 29:
973 { skip_evaluation -= !yyvsp[-3].integer.value;
974 yyval.integer.value = (yyvsp[-3].integer.value && yyvsp[0].integer.value);
975 yyval.integer.unsignedp = 0; ;
976 break;}
977 case 30:
978 { skip_evaluation += !!yyvsp[-1].integer.value; ;
979 break;}
980 case 31:
981 { skip_evaluation -= !!yyvsp[-3].integer.value;
982 yyval.integer.value = (yyvsp[-3].integer.value || yyvsp[0].integer.value);
983 yyval.integer.unsignedp = 0; ;
984 break;}
985 case 32:
986 { skip_evaluation += !yyvsp[-1].integer.value; ;
987 break;}
988 case 33:
989 { skip_evaluation += !!yyvsp[-4].integer.value - !yyvsp[-4].integer.value; ;
990 break;}
991 case 34:
992 { skip_evaluation -= !!yyvsp[-6].integer.value;
993 yyval.integer.value = yyvsp[-6].integer.value ? yyvsp[-3].integer.value : yyvsp[0].integer.value;
994 yyval.integer.unsignedp = yyvsp[-3].integer.unsignedp || yyvsp[0].integer.unsignedp; ;
995 break;}
996 case 35:
997 { yyval.integer = yylval.integer; ;
998 break;}
999 case 36:
1000 { yyval.integer = yylval.integer; ;
1001 break;}
1002 case 37:
1003 { yyval.integer.value = 0;
1004 yyval.integer.unsignedp = 0; ;
1005 break;}
1006 case 38:
1007 { yyval.keywords = 0; ;
1008 break;}
1009 case 39:
1010 { struct arglist *temp;
1011 yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1012 yyval.keywords->next = yyvsp[-2].keywords;
1013 yyval.keywords->name = (U_CHAR *) "(";
1014 yyval.keywords->length = 1;
1015 temp = yyval.keywords;
1016 while (temp != 0 && temp->next != 0)
1017 temp = temp->next;
1018 temp->next = (struct arglist *) xmalloc (sizeof (struct arglist));
1019 temp->next->next = yyvsp[0].keywords;
1020 temp->next->name = (U_CHAR *) ")";
1021 temp->next->length = 1; ;
1022 break;}
1023 case 40:
1024 { yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1025 yyval.keywords->name = yyvsp[-1].name.address;
1026 yyval.keywords->length = yyvsp[-1].name.length;
1027 yyval.keywords->next = yyvsp[0].keywords; ;
1028 break;}
1030 /* the action file gets copied in in place of this dollarsign */
1033 yyvsp -= yylen;
1034 yyssp -= yylen;
1035 #ifdef YYLSP_NEEDED
1036 yylsp -= yylen;
1037 #endif
1039 #if YYDEBUG != 0
1040 if (yydebug)
1042 short *ssp1 = yyss - 1;
1043 fprintf (stderr, "state stack now");
1044 while (ssp1 != yyssp)
1045 fprintf (stderr, " %d", *++ssp1);
1046 fprintf (stderr, "\n");
1048 #endif
1050 *++yyvsp = yyval;
1052 #ifdef YYLSP_NEEDED
1053 yylsp++;
1054 if (yylen == 0)
1056 yylsp->first_line = yylloc.first_line;
1057 yylsp->first_column = yylloc.first_column;
1058 yylsp->last_line = (yylsp-1)->last_line;
1059 yylsp->last_column = (yylsp-1)->last_column;
1060 yylsp->text = 0;
1062 else
1064 yylsp->last_line = (yylsp+yylen-1)->last_line;
1065 yylsp->last_column = (yylsp+yylen-1)->last_column;
1067 #endif
1069 /* Now "shift" the result of the reduction.
1070 Determine what state that goes to,
1071 based on the state we popped back to
1072 and the rule number reduced by. */
1074 yyn = yyr1[yyn];
1076 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1077 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1078 yystate = yytable[yystate];
1079 else
1080 yystate = yydefgoto[yyn - YYNTBASE];
1082 goto yynewstate;
1084 yyerrlab: /* here on detecting error */
1086 if (! yyerrstatus)
1087 /* If not already recovering from an error, report this error. */
1089 ++yynerrs;
1091 #ifdef YYERROR_VERBOSE
1092 yyn = yypact[yystate];
1094 if (yyn > YYFLAG && yyn < YYLAST)
1096 int size = 0;
1097 char *msg;
1098 int x, count;
1100 count = 0;
1101 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1102 for (x = (yyn < 0 ? -yyn : 0);
1103 x < (sizeof(yytname) / sizeof(char *)); x++)
1104 if (yycheck[x + yyn] == x)
1105 size += strlen(yytname[x]) + 15, count++;
1106 msg = (char *) malloc(size + 15);
1107 if (msg != 0)
1109 strcpy(msg, "parse error");
1111 if (count < 5)
1113 count = 0;
1114 for (x = (yyn < 0 ? -yyn : 0);
1115 x < (sizeof(yytname) / sizeof(char *)); x++)
1116 if (yycheck[x + yyn] == x)
1118 strcat(msg, count == 0 ? ", expecting `" : " or `");
1119 strcat(msg, yytname[x]);
1120 strcat(msg, "'");
1121 count++;
1124 yyerror(msg);
1125 free(msg);
1127 else
1128 yyerror ("parse error; also virtual memory exceeded");
1130 else
1131 #endif /* YYERROR_VERBOSE */
1132 yyerror("parse error");
1135 goto yyerrlab1;
1136 yyerrlab1: /* here on error raised explicitly by an action */
1138 if (yyerrstatus == 3)
1140 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1142 /* return failure if at end of input */
1143 if (yychar == YYEOF)
1144 YYABORT;
1146 #if YYDEBUG != 0
1147 if (yydebug)
1148 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1149 #endif
1151 yychar = YYEMPTY;
1154 /* Else will try to reuse lookahead token
1155 after shifting the error token. */
1157 yyerrstatus = 3; /* Each real token shifted decrements this */
1159 goto yyerrhandle;
1161 yyerrdefault: /* current state does not do anything special for the error token. */
1163 #if 0
1164 /* This is wrong; only states that explicitly want error tokens
1165 should shift them. */
1166 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1167 if (yyn) goto yydefault;
1168 #endif
1170 yyerrpop: /* pop the current state because it cannot handle the error token */
1172 if (yyssp == yyss) YYABORT;
1173 yyvsp--;
1174 yystate = *--yyssp;
1175 #ifdef YYLSP_NEEDED
1176 yylsp--;
1177 #endif
1179 #if YYDEBUG != 0
1180 if (yydebug)
1182 short *ssp1 = yyss - 1;
1183 fprintf (stderr, "Error: state stack now");
1184 while (ssp1 != yyssp)
1185 fprintf (stderr, " %d", *++ssp1);
1186 fprintf (stderr, "\n");
1188 #endif
1190 yyerrhandle:
1192 yyn = yypact[yystate];
1193 if (yyn == YYFLAG)
1194 goto yyerrdefault;
1196 yyn += YYTERROR;
1197 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1198 goto yyerrdefault;
1200 yyn = yytable[yyn];
1201 if (yyn < 0)
1203 if (yyn == YYFLAG)
1204 goto yyerrpop;
1205 yyn = -yyn;
1206 goto yyreduce;
1208 else if (yyn == 0)
1209 goto yyerrpop;
1211 if (yyn == YYFINAL)
1212 YYACCEPT;
1214 #if YYDEBUG != 0
1215 if (yydebug)
1216 fprintf(stderr, "Shifting error token, ");
1217 #endif
1219 *++yyvsp = yylval;
1220 #ifdef YYLSP_NEEDED
1221 *++yylsp = yylloc;
1222 #endif
1224 yystate = yyn;
1225 goto yynewstate;
1229 /* During parsing of a C expression, the pointer to the next character
1230 is in this variable. */
1232 static char *lexptr;
1234 /* Take care of parsing a number (anything that starts with a digit).
1235 Set yylval and return the token type; update lexptr.
1236 LEN is the number of characters in it. */
1238 /* maybe needs to actually deal with floating point numbers */
1241 parse_number (olen)
1242 int olen;
1244 register char *p = lexptr;
1245 register int c;
1246 register unsigned long n = 0, nd, ULONG_MAX_over_base;
1247 register int base = 10;
1248 register int len = olen;
1249 register int overflow = 0;
1250 register int digit, largest_digit = 0;
1251 int spec_long = 0;
1253 for (c = 0; c < len; c++)
1254 if (p[c] == '.') {
1255 /* It's a float since it contains a point. */
1256 yyerror ("floating point numbers not allowed in #if expressions");
1257 return ERROR;
1260 yylval.integer.unsignedp = 0;
1262 if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) {
1263 p += 2;
1264 base = 16;
1265 len -= 2;
1267 else if (*p == '0')
1268 base = 8;
1270 ULONG_MAX_over_base = (unsigned long) -1 / base;
1272 for (; len > 0; len--) {
1273 c = *p++;
1275 if (c >= '0' && c <= '9')
1276 digit = c - '0';
1277 else if (base == 16 && c >= 'a' && c <= 'f')
1278 digit = c - 'a' + 10;
1279 else if (base == 16 && c >= 'A' && c <= 'F')
1280 digit = c - 'A' + 10;
1281 else {
1282 /* `l' means long, and `u' means unsigned. */
1283 while (1) {
1284 if (c == 'l' || c == 'L')
1286 if (spec_long)
1287 yyerror ("two `l's in integer constant");
1288 spec_long = 1;
1290 else if (c == 'u' || c == 'U')
1292 if (yylval.integer.unsignedp)
1293 yyerror ("two `u's in integer constant");
1294 yylval.integer.unsignedp = 1;
1296 else
1297 break;
1299 if (--len == 0)
1300 break;
1301 c = *p++;
1303 /* Don't look for any more digits after the suffixes. */
1304 break;
1306 if (largest_digit < digit)
1307 largest_digit = digit;
1308 nd = n * base + digit;
1309 overflow |= ULONG_MAX_over_base < n | nd < n;
1310 n = nd;
1313 if (len != 0) {
1314 yyerror ("Invalid number in #if expression");
1315 return ERROR;
1318 if (base <= largest_digit)
1319 warning ("integer constant contains digits beyond the radix");
1321 if (overflow)
1322 warning ("integer constant out of range");
1324 /* If too big to be signed, consider it unsigned. */
1325 if ((long) n < 0 && ! yylval.integer.unsignedp)
1327 if (base == 10)
1328 warning ("integer constant is so large that it is unsigned");
1329 yylval.integer.unsignedp = 1;
1332 lexptr = p;
1333 yylval.integer.value = n;
1334 return INT;
1337 struct token {
1338 char *operator;
1339 int token;
1342 static struct token tokentab2[] = {
1343 {"&&", AND},
1344 {"||", OR},
1345 {"<<", LSH},
1346 {">>", RSH},
1347 {"==", EQUAL},
1348 {"!=", NOTEQUAL},
1349 {"<=", LEQ},
1350 {">=", GEQ},
1351 {"++", ERROR},
1352 {"--", ERROR},
1353 {NULL, ERROR}
1356 /* Read one token, getting characters through lexptr. */
1359 yylex ()
1361 register int c;
1362 register int namelen;
1363 register unsigned char *tokstart;
1364 register struct token *toktab;
1365 int wide_flag;
1367 retry:
1369 tokstart = (unsigned char *) lexptr;
1370 c = *tokstart;
1371 /* See if it is a special token of length 2. */
1372 if (! keyword_parsing)
1373 for (toktab = tokentab2; toktab->operator != NULL; toktab++)
1374 if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) {
1375 lexptr += 2;
1376 if (toktab->token == ERROR)
1378 char *buf = (char *) alloca (40);
1379 sprintf (buf, "`%s' not allowed in operand of `#if'", toktab->operator);
1380 yyerror (buf);
1382 return toktab->token;
1385 switch (c) {
1386 case 0:
1387 return 0;
1389 case ' ':
1390 case '\t':
1391 case '\r':
1392 case '\n':
1393 lexptr++;
1394 goto retry;
1396 case 'L':
1397 /* Capital L may start a wide-string or wide-character constant. */
1398 if (lexptr[1] == '\'')
1400 lexptr++;
1401 wide_flag = 1;
1402 goto char_constant;
1404 if (lexptr[1] == '"')
1406 lexptr++;
1407 wide_flag = 1;
1408 goto string_constant;
1410 break;
1412 case '\'':
1413 wide_flag = 0;
1414 char_constant:
1415 lexptr++;
1416 if (keyword_parsing) {
1417 char *start_ptr = lexptr - 1;
1418 while (1) {
1419 c = *lexptr++;
1420 if (c == '\\')
1421 c = parse_escape (&lexptr);
1422 else if (c == '\'')
1423 break;
1425 yylval.name.address = tokstart;
1426 yylval.name.length = lexptr - start_ptr;
1427 return NAME;
1430 /* This code for reading a character constant
1431 handles multicharacter constants and wide characters.
1432 It is mostly copied from c-lex.c. */
1434 register int result = 0;
1435 register num_chars = 0;
1436 unsigned width = MAX_CHAR_TYPE_SIZE;
1437 int max_chars;
1438 char *token_buffer;
1440 if (wide_flag)
1442 width = MAX_WCHAR_TYPE_SIZE;
1443 #ifdef MULTIBYTE_CHARS
1444 max_chars = MB_CUR_MAX;
1445 #else
1446 max_chars = 1;
1447 #endif
1449 else
1450 max_chars = MAX_LONG_TYPE_SIZE / width;
1452 token_buffer = (char *) alloca (max_chars + 1);
1454 while (1)
1456 c = *lexptr++;
1458 if (c == '\'' || c == EOF)
1459 break;
1461 if (c == '\\')
1463 c = parse_escape (&lexptr);
1464 if (width < HOST_BITS_PER_INT
1465 && (unsigned) c >= (1 << width))
1466 pedwarn ("escape sequence out of range for character");
1469 num_chars++;
1471 /* Merge character into result; ignore excess chars. */
1472 if (num_chars < max_chars + 1)
1474 if (width < HOST_BITS_PER_INT)
1475 result = (result << width) | (c & ((1 << width) - 1));
1476 else
1477 result = c;
1478 token_buffer[num_chars - 1] = c;
1482 token_buffer[num_chars] = 0;
1484 if (c != '\'')
1485 error ("malformatted character constant");
1486 else if (num_chars == 0)
1487 error ("empty character constant");
1488 else if (num_chars > max_chars)
1490 num_chars = max_chars;
1491 error ("character constant too long");
1493 else if (num_chars != 1 && ! traditional)
1494 warning ("multi-character character constant");
1496 /* If char type is signed, sign-extend the constant. */
1497 if (! wide_flag)
1499 int num_bits = num_chars * width;
1501 if (lookup ("__CHAR_UNSIGNED__", sizeof ("__CHAR_UNSIGNED__")-1, -1)
1502 || ((result >> (num_bits - 1)) & 1) == 0)
1503 yylval.integer.value
1504 = result & ((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits));
1505 else
1506 yylval.integer.value
1507 = result | ~((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits));
1509 else
1511 #ifdef MULTIBYTE_CHARS
1512 /* Set the initial shift state and convert the next sequence. */
1513 result = 0;
1514 /* In all locales L'\0' is zero and mbtowc will return zero,
1515 so don't use it. */
1516 if (num_chars > 1
1517 || (num_chars == 1 && token_buffer[0] != '\0'))
1519 wchar_t wc;
1520 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1521 if (mbtowc (& wc, token_buffer, num_chars) == num_chars)
1522 result = wc;
1523 else
1524 warning ("Ignoring invalid multibyte character");
1526 #endif
1527 yylval.integer.value = result;
1531 /* This is always a signed type. */
1532 yylval.integer.unsignedp = 0;
1534 return CHAR;
1536 /* some of these chars are invalid in constant expressions;
1537 maybe do something about them later */
1538 case '/':
1539 case '+':
1540 case '-':
1541 case '*':
1542 case '%':
1543 case '|':
1544 case '&':
1545 case '^':
1546 case '~':
1547 case '!':
1548 case '@':
1549 case '<':
1550 case '>':
1551 case '[':
1552 case ']':
1553 case '.':
1554 case '?':
1555 case ':':
1556 case '=':
1557 case '{':
1558 case '}':
1559 case ',':
1560 case '#':
1561 if (keyword_parsing)
1562 break;
1563 case '(':
1564 case ')':
1565 lexptr++;
1566 return c;
1568 case '"':
1569 string_constant:
1570 if (keyword_parsing) {
1571 char *start_ptr = lexptr;
1572 lexptr++;
1573 while (1) {
1574 c = *lexptr++;
1575 if (c == '\\')
1576 c = parse_escape (&lexptr);
1577 else if (c == '"')
1578 break;
1580 yylval.name.address = tokstart;
1581 yylval.name.length = lexptr - start_ptr;
1582 return NAME;
1584 yyerror ("string constants not allowed in #if expressions");
1585 return ERROR;
1588 if (c >= '0' && c <= '9' && !keyword_parsing) {
1589 /* It's a number */
1590 for (namelen = 0;
1591 c = tokstart[namelen], is_idchar[c] || c == '.';
1592 namelen++)
1594 return parse_number (namelen);
1597 /* It is a name. See how long it is. */
1599 if (keyword_parsing) {
1600 for (namelen = 0;; namelen++) {
1601 if (is_hor_space[tokstart[namelen]])
1602 break;
1603 if (tokstart[namelen] == '(' || tokstart[namelen] == ')')
1604 break;
1605 if (tokstart[namelen] == '"' || tokstart[namelen] == '\'')
1606 break;
1608 } else {
1609 if (!is_idstart[c]) {
1610 yyerror ("Invalid token in expression");
1611 return ERROR;
1614 for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
1618 lexptr += namelen;
1619 yylval.name.address = tokstart;
1620 yylval.name.length = namelen;
1621 return NAME;
1625 /* Parse a C escape sequence. STRING_PTR points to a variable
1626 containing a pointer to the string to parse. That pointer
1627 is updated past the characters we use. The value of the
1628 escape sequence is returned.
1630 A negative value means the sequence \ newline was seen,
1631 which is supposed to be equivalent to nothing at all.
1633 If \ is followed by a null character, we return a negative
1634 value and leave the string pointer pointing at the null character.
1636 If \ is followed by 000, we return 0 and leave the string pointer
1637 after the zeros. A value of 0 does not mean end of string. */
1640 parse_escape (string_ptr)
1641 char **string_ptr;
1643 register int c = *(*string_ptr)++;
1644 switch (c)
1646 case 'a':
1647 return TARGET_BELL;
1648 case 'b':
1649 return TARGET_BS;
1650 case 'e':
1651 case 'E':
1652 if (pedantic)
1653 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1654 return 033;
1655 case 'f':
1656 return TARGET_FF;
1657 case 'n':
1658 return TARGET_NEWLINE;
1659 case 'r':
1660 return TARGET_CR;
1661 case 't':
1662 return TARGET_TAB;
1663 case 'v':
1664 return TARGET_VT;
1665 case '\n':
1666 return -2;
1667 case 0:
1668 (*string_ptr)--;
1669 return 0;
1671 case '0':
1672 case '1':
1673 case '2':
1674 case '3':
1675 case '4':
1676 case '5':
1677 case '6':
1678 case '7':
1680 register int i = c - '0';
1681 register int count = 0;
1682 while (++count < 3)
1684 c = *(*string_ptr)++;
1685 if (c >= '0' && c <= '7')
1686 i = (i << 3) + c - '0';
1687 else
1689 (*string_ptr)--;
1690 break;
1693 if ((i & ~((1 << MAX_CHAR_TYPE_SIZE) - 1)) != 0)
1695 i &= (1 << MAX_CHAR_TYPE_SIZE) - 1;
1696 warning ("octal character constant does not fit in a byte");
1698 return i;
1700 case 'x':
1702 register unsigned i = 0, overflow = 0, digits_found = 0, digit;
1703 for (;;)
1705 c = *(*string_ptr)++;
1706 if (c >= '0' && c <= '9')
1707 digit = c - '0';
1708 else if (c >= 'a' && c <= 'f')
1709 digit = c - 'a' + 10;
1710 else if (c >= 'A' && c <= 'F')
1711 digit = c - 'A' + 10;
1712 else
1714 (*string_ptr)--;
1715 break;
1717 overflow |= i ^ (i << 4 >> 4);
1718 i = (i << 4) + digit;
1719 digits_found = 1;
1721 if (!digits_found)
1722 yyerror ("\\x used with no following hex digits");
1723 if (overflow | (i & ~((1 << BITS_PER_UNIT) - 1)))
1725 i &= (1 << BITS_PER_UNIT) - 1;
1726 warning ("hex character constant does not fit in a byte");
1728 return i;
1730 default:
1731 return c;
1735 void
1736 yyerror (s)
1737 char *s;
1739 error (s);
1740 skip_evaluation = 0;
1741 longjmp (parse_return_error, 1);
1744 static void
1745 integer_overflow ()
1747 if (!skip_evaluation && pedantic)
1748 pedwarn ("integer overflow in preprocessor expression");
1751 static long
1752 left_shift (a, b)
1753 struct constant *a;
1754 unsigned long b;
1756 /* It's unclear from the C standard whether shifts can overflow.
1757 The following code ignores overflow; perhaps a C standard
1758 interpretation ruling is needed. */
1759 if (b >= HOST_BITS_PER_LONG)
1760 return 0;
1761 else if (a->unsignedp)
1762 return (unsigned long) a->value << b;
1763 else
1764 return a->value << b;
1767 static long
1768 right_shift (a, b)
1769 struct constant *a;
1770 unsigned long b;
1772 if (b >= HOST_BITS_PER_LONG)
1773 return a->unsignedp ? 0 : a->value >> (HOST_BITS_PER_LONG - 1);
1774 else if (a->unsignedp)
1775 return (unsigned long) a->value >> b;
1776 else
1777 return a->value >> b;
1780 /* This page contains the entry point to this file. */
1782 /* Parse STRING as an expression, and complain if this fails
1783 to use up all of the contents of STRING. */
1784 /* We do not support C comments. They should be removed before
1785 this function is called. */
1787 HOST_WIDE_INT
1788 parse_c_expression (string)
1789 char *string;
1791 lexptr = string;
1793 if (lexptr == 0 || *lexptr == 0) {
1794 error ("empty #if expression");
1795 return 0; /* don't include the #if group */
1798 /* if there is some sort of scanning error, just return 0 and assume
1799 the parsing routine has printed an error message somewhere.
1800 there is surely a better thing to do than this. */
1801 if (setjmp (parse_return_error))
1802 return 0;
1804 if (yyparse ())
1805 return 0; /* actually this is never reached
1806 the way things stand. */
1807 if (*lexptr)
1808 error ("Junk after end of expression.");
1810 return expression_value; /* set by yyparse () */
1813 #ifdef TEST_EXP_READER
1814 extern int yydebug;
1816 /* Main program for testing purposes. */
1818 main ()
1820 int n, c;
1821 char buf[1024];
1824 yydebug = 1;
1826 initialize_random_junk ();
1828 for (;;) {
1829 printf ("enter expression: ");
1830 n = 0;
1831 while ((buf[n] = getchar ()) != '\n' && buf[n] != EOF)
1832 n++;
1833 if (buf[n] == EOF)
1834 break;
1835 buf[n] = '\0';
1836 printf ("parser returned %ld\n", parse_c_expression (buf));
1839 return 0;
1842 /* table to tell if char can be part of a C identifier. */
1843 unsigned char is_idchar[256];
1844 /* table to tell if char can be first char of a c identifier. */
1845 unsigned char is_idstart[256];
1846 /* table to tell if c is horizontal space. isspace () thinks that
1847 newline is space; this is not a good idea for this program. */
1848 char is_hor_space[256];
1851 * initialize random junk in the hash table and maybe other places
1853 initialize_random_junk ()
1855 register int i;
1858 * Set up is_idchar and is_idstart tables. These should be
1859 * faster than saying (is_alpha (c) || c == '_'), etc.
1860 * Must do set up these things before calling any routines tthat
1861 * refer to them.
1863 for (i = 'a'; i <= 'z'; i++) {
1864 ++is_idchar[i - 'a' + 'A'];
1865 ++is_idchar[i];
1866 ++is_idstart[i - 'a' + 'A'];
1867 ++is_idstart[i];
1869 for (i = '0'; i <= '9'; i++)
1870 ++is_idchar[i];
1871 ++is_idchar['_'];
1872 ++is_idstart['_'];
1873 #if DOLLARS_IN_IDENTIFIERS
1874 ++is_idchar['$'];
1875 ++is_idstart['$'];
1876 #endif
1878 /* horizontal space table */
1879 ++is_hor_space[' '];
1880 ++is_hor_space['\t'];
1883 error (msg)
1885 printf ("error: %s\n", msg);
1888 warning (msg)
1890 printf ("warning: %s\n", msg);
1893 struct hashnode *
1894 lookup (name, len, hash)
1895 char *name;
1896 int len;
1897 int hash;
1899 return (DEFAULT_SIGNED_CHAR) ? 0 : ((struct hashnode *) -1);
1901 #endif