oops - fixed typo in previous delta
[official-gcc.git] / gcc / cexp.c
blob577088755b7b75b7fb8b5a2cbba3603cece175db
2 /* A Bison parser, made from cexp.y
3 by GNU Bison version 1.25
4 */
6 #define YYBISON 1 /* Identify Bison output. */
8 #define INT 258
9 #define CHAR 259
10 #define NAME 260
11 #define ERROR 261
12 #define OR 262
13 #define AND 263
14 #define EQUAL 264
15 #define NOTEQUAL 265
16 #define LEQ 266
17 #define GEQ 267
18 #define LSH 268
19 #define RSH 269
20 #define UNARY 270
22 #line 27 "cexp.y"
24 #include "config.h"
26 #include "system.h"
27 #include "intl.h"
28 #include <setjmp.h>
29 /* #define YYDEBUG 1 */
31 #ifdef MULTIBYTE_CHARS
32 #include "mbchar.h"
33 #include <locale.h>
34 #endif /* MULTIBYTE_CHARS */
36 typedef unsigned char U_CHAR;
38 /* This is used for communicating lists of keywords with cccp.c. */
39 struct arglist {
40 struct arglist *next;
41 U_CHAR *name;
42 int length;
43 int argno;
46 HOST_WIDEST_INT parse_c_expression PARAMS ((char *, int));
48 static int yylex PARAMS ((void));
49 static void yyerror PARAMS ((const char *, ...))
50 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
51 static HOST_WIDEST_INT expression_value;
52 #ifdef TEST_EXP_READER
53 static int expression_signedp;
54 #endif
56 static jmp_buf parse_return_error;
58 /* Nonzero means count most punctuation as part of a name. */
59 static int keyword_parsing = 0;
61 /* Nonzero means do not evaluate this expression.
62 This is a count, since unevaluated expressions can nest. */
63 static int skip_evaluation;
65 /* Nonzero means warn if undefined identifiers are evaluated. */
66 static int warn_undef;
68 /* some external tables of character types */
69 extern unsigned char is_idstart[], is_idchar[], is_space[];
71 /* Flag for -pedantic. */
72 extern int pedantic;
74 /* Flag for -traditional. */
75 extern int traditional;
77 /* Flag for -lang-c89. */
78 extern int c89;
80 #ifndef CHAR_TYPE_SIZE
81 #define CHAR_TYPE_SIZE BITS_PER_UNIT
82 #endif
84 #ifndef INT_TYPE_SIZE
85 #define INT_TYPE_SIZE BITS_PER_WORD
86 #endif
88 #ifndef LONG_TYPE_SIZE
89 #define LONG_TYPE_SIZE BITS_PER_WORD
90 #endif
92 #ifndef WCHAR_TYPE_SIZE
93 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
94 #endif
96 #ifndef MAX_CHAR_TYPE_SIZE
97 #define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE
98 #endif
100 #ifndef MAX_INT_TYPE_SIZE
101 #define MAX_INT_TYPE_SIZE INT_TYPE_SIZE
102 #endif
104 #ifndef MAX_LONG_TYPE_SIZE
105 #define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE
106 #endif
108 #ifndef MAX_WCHAR_TYPE_SIZE
109 #define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
110 #endif
112 #define MAX_CHAR_TYPE_MASK (MAX_CHAR_TYPE_SIZE < HOST_BITS_PER_WIDEST_INT \
113 ? (~ (~ (HOST_WIDEST_INT) 0 << MAX_CHAR_TYPE_SIZE)) \
114 : ~ (HOST_WIDEST_INT) 0)
116 #define MAX_WCHAR_TYPE_MASK (MAX_WCHAR_TYPE_SIZE < HOST_BITS_PER_WIDEST_INT \
117 ? ~ (~ (HOST_WIDEST_INT) 0 << MAX_WCHAR_TYPE_SIZE) \
118 : ~ (HOST_WIDEST_INT) 0)
120 /* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
121 Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
122 Suppose SIGNEDP is negative if the result is signed, zero if unsigned.
123 Then this yields nonzero if overflow occurred during the addition.
124 Overflow occurs if A and B have the same sign, but A and SUM differ in sign,
125 and SIGNEDP is negative.
126 Use `^' to test whether signs differ, and `< 0' to isolate the sign. */
127 #define overflow_sum_sign(a, b, sum, signedp) \
128 ((~((a) ^ (b)) & ((a) ^ (sum)) & (signedp)) < 0)
130 struct constant;
132 HOST_WIDEST_INT parse_escape PARAMS ((char **, HOST_WIDEST_INT));
133 int check_assertion PARAMS ((U_CHAR *, int, int, struct arglist *));
134 struct hashnode *lookup PARAMS ((U_CHAR *, int, int));
135 void error PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
136 void verror PARAMS ((const char *, va_list));
137 void pedwarn PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
138 void warning PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
140 static int parse_number PARAMS ((int));
141 static HOST_WIDEST_INT left_shift PARAMS ((struct constant *, unsigned HOST_WIDEST_INT));
142 static HOST_WIDEST_INT right_shift PARAMS ((struct constant *, unsigned HOST_WIDEST_INT));
143 static void integer_overflow PARAMS ((void));
145 /* `signedp' values */
146 #define SIGNED (~0)
147 #define UNSIGNED 0
149 #line 154 "cexp.y"
150 typedef union {
151 struct constant {HOST_WIDEST_INT value; int signedp;} integer;
152 struct name {U_CHAR *address; int length;} name;
153 struct arglist *keywords;
154 } YYSTYPE;
155 #include <stdio.h>
157 #ifndef __cplusplus
158 #ifndef __STDC__
159 #define const
160 #endif
161 #endif
165 #define YYFINAL 77
166 #define YYFLAG -32768
167 #define YYNTBASE 34
169 #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 43)
171 static const char yytranslate[] = { 0,
172 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
173 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
174 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
175 2, 2, 29, 2, 31, 2, 27, 14, 2, 32,
176 33, 25, 23, 9, 24, 2, 26, 2, 2, 2,
177 2, 2, 2, 2, 2, 2, 2, 8, 2, 17,
178 2, 18, 7, 2, 2, 2, 2, 2, 2, 2,
179 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
180 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
181 2, 2, 2, 13, 2, 2, 2, 2, 2, 2,
182 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
184 2, 2, 2, 12, 2, 30, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
187 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
188 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
189 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
190 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
194 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
195 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
196 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
197 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
198 6, 10, 11, 15, 16, 19, 20, 21, 22, 28
201 #if YYDEBUG != 0
202 static const short yyprhs[] = { 0,
203 0, 2, 4, 8, 11, 14, 17, 20, 23, 24,
204 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
205 71, 75, 79, 83, 87, 91, 95, 99, 100, 105,
206 106, 111, 112, 113, 121, 123, 125, 127, 128, 133
209 static const short yyrhs[] = { 35,
210 0, 36, 0, 35, 9, 36, 0, 24, 36, 0,
211 29, 36, 0, 23, 36, 0, 30, 36, 0, 31,
212 5, 0, 0, 31, 5, 37, 32, 42, 33, 0,
213 32, 35, 33, 0, 36, 25, 36, 0, 36, 26,
214 36, 0, 36, 27, 36, 0, 36, 23, 36, 0,
215 36, 24, 36, 0, 36, 21, 36, 0, 36, 22,
216 36, 0, 36, 15, 36, 0, 36, 16, 36, 0,
217 36, 19, 36, 0, 36, 20, 36, 0, 36, 17,
218 36, 0, 36, 18, 36, 0, 36, 14, 36, 0,
219 36, 13, 36, 0, 36, 12, 36, 0, 0, 36,
220 11, 38, 36, 0, 0, 36, 10, 39, 36, 0,
221 0, 0, 36, 7, 40, 36, 8, 41, 36, 0,
222 3, 0, 4, 0, 5, 0, 0, 32, 42, 33,
223 42, 0, 5, 42, 0
226 #endif
228 #if YYDEBUG != 0
229 static const short yyrline[] = { 0,
230 184, 194, 195, 202, 207, 210, 212, 215, 219, 221,
231 226, 231, 244, 261, 274, 280, 286, 292, 298, 301,
232 304, 311, 318, 325, 332, 335, 338, 341, 344, 347,
233 350, 353, 355, 358, 361, 363, 365, 373, 375, 388
235 #endif
238 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
240 static const char * const yytname[] = { "$","error","$undefined.","INT","CHAR",
241 "NAME","ERROR","'?'","':'","','","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL",
242 "'<'","'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'","UNARY","'!'",
243 "'~'","'#'","'('","')'","start","exp1","exp","@1","@2","@3","@4","@5","keywords", NULL
245 #endif
247 static const short yyr1[] = { 0,
248 34, 35, 35, 36, 36, 36, 36, 36, 37, 36,
249 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
250 36, 36, 36, 36, 36, 36, 36, 38, 36, 39,
251 36, 40, 41, 36, 36, 36, 36, 42, 42, 42
254 static const short yyr2[] = { 0,
255 1, 1, 3, 2, 2, 2, 2, 2, 0, 6,
256 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
257 3, 3, 3, 3, 3, 3, 3, 0, 4, 0,
258 4, 0, 0, 7, 1, 1, 1, 0, 4, 2
261 static const short yydefact[] = { 0,
262 35, 36, 37, 0, 0, 0, 0, 0, 0, 1,
263 2, 6, 4, 5, 7, 8, 0, 0, 32, 30,
264 28, 0, 0, 0, 0, 0, 0, 0, 0, 0,
265 0, 0, 0, 0, 0, 0, 0, 0, 11, 3,
266 0, 0, 0, 27, 26, 25, 19, 20, 23, 24,
267 21, 22, 17, 18, 15, 16, 12, 13, 14, 38,
268 0, 31, 29, 38, 38, 0, 33, 40, 0, 10,
269 0, 38, 34, 39, 0, 0, 0
272 static const short yydefgoto[] = { 75,
273 10, 11, 38, 43, 42, 41, 71, 66
276 static const short yypact[] = { 12,
277 -32768,-32768,-32768, 12, 12, 12, 12, 1, 12, 4,
278 79,-32768,-32768,-32768,-32768, -21, 31, 12,-32768,-32768,
279 -32768, 12, 12, 12, 12, 12, 12, 12, 12, 12,
280 12, 12, 12, 12, 12, 12, 12, 30,-32768, 79,
281 12, 12, 12, 110, 124, 137, 148, 148, 155, 155,
282 155, 155, 160, 160, -17, -17,-32768,-32768,-32768, 2,
283 58, 34, 95, 2, 2, 54,-32768,-32768, 55,-32768,
284 12, 2, 79,-32768, 63, 188,-32768
287 static const short yypgoto[] = {-32768,
288 180, -4,-32768,-32768,-32768,-32768,-32768, -60
292 #define YYLAST 189
295 static const short yytable[] = { 12,
296 13, 14, 15, 68, 69, 16, 64, 35, 36, 37,
297 -9, 74, 18, 40, 1, 2, 3, 44, 45, 46,
298 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
299 57, 58, 59, 65, 4, 5, 61, 62, 63, 18,
300 6, 7, 8, 9, 21, 22, 23, 24, 25, 26,
301 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
302 37, 60, 76, 39, 19, 67, 73, 20, 21, 22,
303 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
304 33, 34, 35, 36, 37, 19, 70, 72, 20, 21,
305 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
306 32, 33, 34, 35, 36, 37, 22, 23, 24, 25,
307 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
308 36, 37, 23, 24, 25, 26, 27, 28, 29, 30,
309 31, 32, 33, 34, 35, 36, 37, 24, 25, 26,
310 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
311 37, 25, 26, 27, 28, 29, 30, 31, 32, 33,
312 34, 35, 36, 37, 27, 28, 29, 30, 31, 32,
313 33, 34, 35, 36, 37, 31, 32, 33, 34, 35,
314 36, 37, 33, 34, 35, 36, 37, 77, 17
317 static const short yycheck[] = { 4,
318 5, 6, 7, 64, 65, 5, 5, 25, 26, 27,
319 32, 72, 9, 18, 3, 4, 5, 22, 23, 24,
320 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
321 35, 36, 37, 32, 23, 24, 41, 42, 43, 9,
322 29, 30, 31, 32, 11, 12, 13, 14, 15, 16,
323 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
324 27, 32, 0, 33, 7, 8, 71, 10, 11, 12,
325 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
326 23, 24, 25, 26, 27, 7, 33, 33, 10, 11,
327 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
328 22, 23, 24, 25, 26, 27, 12, 13, 14, 15,
329 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
330 26, 27, 13, 14, 15, 16, 17, 18, 19, 20,
331 21, 22, 23, 24, 25, 26, 27, 14, 15, 16,
332 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
333 27, 15, 16, 17, 18, 19, 20, 21, 22, 23,
334 24, 25, 26, 27, 17, 18, 19, 20, 21, 22,
335 23, 24, 25, 26, 27, 21, 22, 23, 24, 25,
336 26, 27, 23, 24, 25, 26, 27, 0, 9
338 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
339 #line 3 "/usr/cygnus/TBD-TBD/share/bison.simple"
341 /* Skeleton output parser for bison,
342 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
344 This program is free software; you can redistribute it and/or modify
345 it under the terms of the GNU General Public License as published by
346 the Free Software Foundation; either version 2, or (at your option)
347 any later version.
349 This program is distributed in the hope that it will be useful,
350 but WITHOUT ANY WARRANTY; without even the implied warranty of
351 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
352 GNU General Public License for more details.
354 You should have received a copy of the GNU General Public License
355 along with this program; if not, write to the Free Software
356 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
358 /* As a special exception, when this file is copied by Bison into a
359 Bison output file, you may use that output file without restriction.
360 This special exception was added by the Free Software Foundation
361 in version 1.24 of Bison. */
363 #ifndef alloca
364 #ifdef __GNUC__
365 #define alloca __builtin_alloca
366 #else /* not GNU C. */
367 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
368 #include <alloca.h>
369 #else /* not sparc */
370 #if defined (MSDOS) && !defined (__TURBOC__)
371 #include <malloc.h>
372 #else /* not MSDOS, or __TURBOC__ */
373 #if defined(_AIX)
374 #include <malloc.h>
375 #pragma alloca
376 #else /* not MSDOS, __TURBOC__, or _AIX */
377 #ifdef __hpux
378 #ifdef __cplusplus
379 extern "C" {
380 void *alloca (unsigned int);
382 #else /* not __cplusplus */
383 void *alloca ();
384 #endif /* not __cplusplus */
385 #endif /* __hpux */
386 #endif /* not _AIX */
387 #endif /* not MSDOS, or __TURBOC__ */
388 #endif /* not sparc. */
389 #endif /* not GNU C. */
390 #endif /* alloca not defined. */
392 /* This is the parser code that is written into each bison parser
393 when the %semantic_parser declaration is not specified in the grammar.
394 It was written by Richard Stallman by simplifying the hairy parser
395 used when %semantic_parser is specified. */
397 /* Note: there must be only one dollar sign in this file.
398 It is replaced by the list of actions, each action
399 as one case of the switch. */
401 #define yyerrok (yyerrstatus = 0)
402 #define yyclearin (yychar = YYEMPTY)
403 #define YYEMPTY -2
404 #define YYEOF 0
405 #define YYACCEPT return(0)
406 #define YYABORT return(1)
407 #define YYERROR goto yyerrlab1
408 /* Like YYERROR except do call yyerror.
409 This remains here temporarily to ease the
410 transition to the new meaning of YYERROR, for GCC.
411 Once GCC version 2 has supplanted version 1, this can go. */
412 #define YYFAIL goto yyerrlab
413 #define YYRECOVERING() (!!yyerrstatus)
414 #define YYBACKUP(token, value) \
415 do \
416 if (yychar == YYEMPTY && yylen == 1) \
417 { yychar = (token), yylval = (value); \
418 yychar1 = YYTRANSLATE (yychar); \
419 YYPOPSTACK; \
420 goto yybackup; \
422 else \
423 { yyerror ("syntax error: cannot back up"); YYERROR; } \
424 while (0)
426 #define YYTERROR 1
427 #define YYERRCODE 256
429 #ifndef YYPURE
430 #define YYLEX yylex()
431 #endif
433 #ifdef YYPURE
434 #ifdef YYLSP_NEEDED
435 #ifdef YYLEX_PARAM
436 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
437 #else
438 #define YYLEX yylex(&yylval, &yylloc)
439 #endif
440 #else /* not YYLSP_NEEDED */
441 #ifdef YYLEX_PARAM
442 #define YYLEX yylex(&yylval, YYLEX_PARAM)
443 #else
444 #define YYLEX yylex(&yylval)
445 #endif
446 #endif /* not YYLSP_NEEDED */
447 #endif
449 /* If nonreentrant, generate the variables here */
451 #ifndef YYPURE
453 int yychar; /* the lookahead symbol */
454 YYSTYPE yylval; /* the semantic value of the */
455 /* lookahead symbol */
457 #ifdef YYLSP_NEEDED
458 YYLTYPE yylloc; /* location data for the lookahead */
459 /* symbol */
460 #endif
462 int yynerrs; /* number of parse errors so far */
463 #endif /* not YYPURE */
465 #if YYDEBUG != 0
466 int yydebug; /* nonzero means print parse trace */
467 /* Since this is uninitialized, it does not stop multiple parsers
468 from coexisting. */
469 #endif
471 /* YYINITDEPTH indicates the initial size of the parser's stacks */
473 #ifndef YYINITDEPTH
474 #define YYINITDEPTH 200
475 #endif
477 /* YYMAXDEPTH is the maximum size the stacks can grow to
478 (effective only if the built-in stack extension method is used). */
480 #if YYMAXDEPTH == 0
481 #undef YYMAXDEPTH
482 #endif
484 #ifndef YYMAXDEPTH
485 #define YYMAXDEPTH 10000
486 #endif
488 /* Prevent warning if -Wstrict-prototypes. */
489 #ifdef __GNUC__
490 int yyparse (void);
491 #endif
493 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
494 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
495 #else /* not GNU C or C++ */
496 #ifndef __cplusplus
498 /* This is the most reliable way to avoid incompatibilities
499 in available built-in functions on various systems. */
500 static void
501 __yy_memcpy (to, from, count)
502 char *to;
503 char *from;
504 int count;
506 register char *f = from;
507 register char *t = to;
508 register int i = count;
510 while (i-- > 0)
511 *t++ = *f++;
514 #else /* __cplusplus */
516 /* This is the most reliable way to avoid incompatibilities
517 in available built-in functions on various systems. */
518 static void
519 __yy_memcpy (char *to, char *from, int count)
521 register char *f = from;
522 register char *t = to;
523 register int i = count;
525 while (i-- > 0)
526 *t++ = *f++;
529 #endif
530 #endif
532 #line 196 "/usr/cygnus/TBD-TBD/share/bison.simple"
534 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
535 into yyparse. The argument should have type void *.
536 It should actually point to an object.
537 Grammar actions can access the variable by casting it
538 to the proper pointer type. */
540 #ifdef YYPARSE_PARAM
541 #ifdef __cplusplus
542 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
543 #define YYPARSE_PARAM_DECL
544 #else /* not __cplusplus */
545 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
546 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
547 #endif /* not __cplusplus */
548 #else /* not YYPARSE_PARAM */
549 #define YYPARSE_PARAM_ARG
550 #define YYPARSE_PARAM_DECL
551 #endif /* not YYPARSE_PARAM */
554 yyparse(YYPARSE_PARAM_ARG)
555 YYPARSE_PARAM_DECL
557 register int yystate;
558 register int yyn;
559 register short *yyssp;
560 register YYSTYPE *yyvsp;
561 int yyerrstatus; /* number of tokens to shift before error messages enabled */
562 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
564 short yyssa[YYINITDEPTH]; /* the state stack */
565 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
567 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
568 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
570 #ifdef YYLSP_NEEDED
571 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
572 YYLTYPE *yyls = yylsa;
573 YYLTYPE *yylsp;
575 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
576 #else
577 #define YYPOPSTACK (yyvsp--, yyssp--)
578 #endif
580 int yystacksize = YYINITDEPTH;
582 #ifdef YYPURE
583 int yychar;
584 YYSTYPE yylval;
585 int yynerrs;
586 #ifdef YYLSP_NEEDED
587 YYLTYPE yylloc;
588 #endif
589 #endif
591 YYSTYPE yyval; /* the variable used to return */
592 /* semantic values from the action */
593 /* routines */
595 int yylen;
597 #if YYDEBUG != 0
598 if (yydebug)
599 fprintf(stderr, "Starting parse\n");
600 #endif
602 yystate = 0;
603 yyerrstatus = 0;
604 yynerrs = 0;
605 yychar = YYEMPTY; /* Cause a token to be read. */
607 /* Initialize stack pointers.
608 Waste one element of value and location stack
609 so that they stay on the same level as the state stack.
610 The wasted elements are never initialized. */
612 yyssp = yyss - 1;
613 yyvsp = yyvs;
614 #ifdef YYLSP_NEEDED
615 yylsp = yyls;
616 #endif
618 /* Push a new state, which is found in yystate . */
619 /* In all cases, when you get here, the value and location stacks
620 have just been pushed. so pushing a state here evens the stacks. */
621 yynewstate:
623 *++yyssp = yystate;
625 if (yyssp >= yyss + yystacksize - 1)
627 /* Give user a chance to reallocate the stack */
628 /* Use copies of these so that the &'s don't force the real ones into memory. */
629 YYSTYPE *yyvs1 = yyvs;
630 short *yyss1 = yyss;
631 #ifdef YYLSP_NEEDED
632 YYLTYPE *yyls1 = yyls;
633 #endif
635 /* Get the current used size of the three stacks, in elements. */
636 int size = yyssp - yyss + 1;
638 #ifdef yyoverflow
639 /* Each stack pointer address is followed by the size of
640 the data in use in that stack, in bytes. */
641 #ifdef YYLSP_NEEDED
642 /* This used to be a conditional around just the two extra args,
643 but that might be undefined if yyoverflow is a macro. */
644 yyoverflow("parser stack overflow",
645 &yyss1, size * sizeof (*yyssp),
646 &yyvs1, size * sizeof (*yyvsp),
647 &yyls1, size * sizeof (*yylsp),
648 &yystacksize);
649 #else
650 yyoverflow("parser stack overflow",
651 &yyss1, size * sizeof (*yyssp),
652 &yyvs1, size * sizeof (*yyvsp),
653 &yystacksize);
654 #endif
656 yyss = yyss1; yyvs = yyvs1;
657 #ifdef YYLSP_NEEDED
658 yyls = yyls1;
659 #endif
660 #else /* no yyoverflow */
661 /* Extend the stack our own way. */
662 if (yystacksize >= YYMAXDEPTH)
664 yyerror("parser stack overflow");
665 return 2;
667 yystacksize *= 2;
668 if (yystacksize > YYMAXDEPTH)
669 yystacksize = YYMAXDEPTH;
670 yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
671 __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
672 yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
673 __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
674 #ifdef YYLSP_NEEDED
675 yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
676 __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
677 #endif
678 #endif /* no yyoverflow */
680 yyssp = yyss + size - 1;
681 yyvsp = yyvs + size - 1;
682 #ifdef YYLSP_NEEDED
683 yylsp = yyls + size - 1;
684 #endif
686 #if YYDEBUG != 0
687 if (yydebug)
688 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
689 #endif
691 if (yyssp >= yyss + yystacksize - 1)
692 YYABORT;
695 #if YYDEBUG != 0
696 if (yydebug)
697 fprintf(stderr, "Entering state %d\n", yystate);
698 #endif
700 goto yybackup;
701 yybackup:
703 /* Do appropriate processing given the current state. */
704 /* Read a lookahead token if we need one and don't already have one. */
705 /* yyresume: */
707 /* First try to decide what to do without reference to lookahead token. */
709 yyn = yypact[yystate];
710 if (yyn == YYFLAG)
711 goto yydefault;
713 /* Not known => get a lookahead token if don't already have one. */
715 /* yychar is either YYEMPTY or YYEOF
716 or a valid token in external form. */
718 if (yychar == YYEMPTY)
720 #if YYDEBUG != 0
721 if (yydebug)
722 fprintf(stderr, "Reading a token: ");
723 #endif
724 yychar = YYLEX;
727 /* Convert token to internal form (in yychar1) for indexing tables with */
729 if (yychar <= 0) /* This means end of input. */
731 yychar1 = 0;
732 yychar = YYEOF; /* Don't call YYLEX any more */
734 #if YYDEBUG != 0
735 if (yydebug)
736 fprintf(stderr, "Now at end of input.\n");
737 #endif
739 else
741 yychar1 = YYTRANSLATE(yychar);
743 #if YYDEBUG != 0
744 if (yydebug)
746 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
747 /* Give the individual parser a way to print the precise meaning
748 of a token, for further debugging info. */
749 #ifdef YYPRINT
750 YYPRINT (stderr, yychar, yylval);
751 #endif
752 fprintf (stderr, ")\n");
754 #endif
757 yyn += yychar1;
758 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
759 goto yydefault;
761 yyn = yytable[yyn];
763 /* yyn is what to do for this token type in this state.
764 Negative => reduce, -yyn is rule number.
765 Positive => shift, yyn is new state.
766 New state is final state => don't bother to shift,
767 just return success.
768 0, or most negative number => error. */
770 if (yyn < 0)
772 if (yyn == YYFLAG)
773 goto yyerrlab;
774 yyn = -yyn;
775 goto yyreduce;
777 else if (yyn == 0)
778 goto yyerrlab;
780 if (yyn == YYFINAL)
781 YYACCEPT;
783 /* Shift the lookahead token. */
785 #if YYDEBUG != 0
786 if (yydebug)
787 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
788 #endif
790 /* Discard the token being shifted unless it is eof. */
791 if (yychar != YYEOF)
792 yychar = YYEMPTY;
794 *++yyvsp = yylval;
795 #ifdef YYLSP_NEEDED
796 *++yylsp = yylloc;
797 #endif
799 /* count tokens shifted since error; after three, turn off error status. */
800 if (yyerrstatus) yyerrstatus--;
802 yystate = yyn;
803 goto yynewstate;
805 /* Do the default action for the current state. */
806 yydefault:
808 yyn = yydefact[yystate];
809 if (yyn == 0)
810 goto yyerrlab;
812 /* Do a reduction. yyn is the number of a rule to reduce with. */
813 yyreduce:
814 yylen = yyr2[yyn];
815 if (yylen > 0)
816 yyval = yyvsp[1-yylen]; /* implement default value of the action */
818 #if YYDEBUG != 0
819 if (yydebug)
821 int i;
823 fprintf (stderr, "Reducing via rule %d (line %d), ",
824 yyn, yyrline[yyn]);
826 /* Print the symbols being reduced, and their result. */
827 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
828 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
829 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
831 #endif
834 switch (yyn) {
836 case 1:
837 #line 185 "cexp.y"
839 expression_value = yyvsp[0].integer.value;
840 #ifdef TEST_EXP_READER
841 expression_signedp = yyvsp[0].integer.signedp;
842 #endif
844 break;}
845 case 3:
846 #line 196 "cexp.y"
847 { if (pedantic)
848 pedwarn ("comma operator in operand of `#if'");
849 yyval.integer = yyvsp[0].integer; ;
850 break;}
851 case 4:
852 #line 203 "cexp.y"
853 { yyval.integer.value = - yyvsp[0].integer.value;
854 yyval.integer.signedp = yyvsp[0].integer.signedp;
855 if ((yyval.integer.value & yyvsp[0].integer.value & yyval.integer.signedp) < 0)
856 integer_overflow (); ;
857 break;}
858 case 5:
859 #line 208 "cexp.y"
860 { yyval.integer.value = ! yyvsp[0].integer.value;
861 yyval.integer.signedp = SIGNED; ;
862 break;}
863 case 6:
864 #line 211 "cexp.y"
865 { yyval.integer = yyvsp[0].integer; ;
866 break;}
867 case 7:
868 #line 213 "cexp.y"
869 { yyval.integer.value = ~ yyvsp[0].integer.value;
870 yyval.integer.signedp = yyvsp[0].integer.signedp; ;
871 break;}
872 case 8:
873 #line 216 "cexp.y"
874 { yyval.integer.value = check_assertion (yyvsp[0].name.address, yyvsp[0].name.length,
875 0, NULL_PTR);
876 yyval.integer.signedp = SIGNED; ;
877 break;}
878 case 9:
879 #line 220 "cexp.y"
880 { keyword_parsing = 1; ;
881 break;}
882 case 10:
883 #line 222 "cexp.y"
884 { yyval.integer.value = check_assertion (yyvsp[-4].name.address, yyvsp[-4].name.length,
885 1, yyvsp[-1].keywords);
886 keyword_parsing = 0;
887 yyval.integer.signedp = SIGNED; ;
888 break;}
889 case 11:
890 #line 227 "cexp.y"
891 { yyval.integer = yyvsp[-1].integer; ;
892 break;}
893 case 12:
894 #line 232 "cexp.y"
895 { yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
896 if (yyval.integer.signedp)
898 yyval.integer.value = yyvsp[-2].integer.value * yyvsp[0].integer.value;
899 if (yyvsp[-2].integer.value
900 && (yyval.integer.value / yyvsp[-2].integer.value != yyvsp[0].integer.value
901 || (yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0))
902 integer_overflow ();
904 else
905 yyval.integer.value = ((unsigned HOST_WIDEST_INT) yyvsp[-2].integer.value
906 * yyvsp[0].integer.value); ;
907 break;}
908 case 13:
909 #line 245 "cexp.y"
910 { if (yyvsp[0].integer.value == 0)
912 if (!skip_evaluation)
913 error ("division by zero in #if");
914 yyvsp[0].integer.value = 1;
916 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
917 if (yyval.integer.signedp)
919 yyval.integer.value = yyvsp[-2].integer.value / yyvsp[0].integer.value;
920 if ((yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0)
921 integer_overflow ();
923 else
924 yyval.integer.value = ((unsigned HOST_WIDEST_INT) yyvsp[-2].integer.value
925 / yyvsp[0].integer.value); ;
926 break;}
927 case 14:
928 #line 262 "cexp.y"
929 { if (yyvsp[0].integer.value == 0)
931 if (!skip_evaluation)
932 error ("division by zero in #if");
933 yyvsp[0].integer.value = 1;
935 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
936 if (yyval.integer.signedp)
937 yyval.integer.value = yyvsp[-2].integer.value % yyvsp[0].integer.value;
938 else
939 yyval.integer.value = ((unsigned HOST_WIDEST_INT) yyvsp[-2].integer.value
940 % yyvsp[0].integer.value); ;
941 break;}
942 case 15:
943 #line 275 "cexp.y"
944 { yyval.integer.value = yyvsp[-2].integer.value + yyvsp[0].integer.value;
945 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
946 if (overflow_sum_sign (yyvsp[-2].integer.value, yyvsp[0].integer.value,
947 yyval.integer.value, yyval.integer.signedp))
948 integer_overflow (); ;
949 break;}
950 case 16:
951 #line 281 "cexp.y"
952 { yyval.integer.value = yyvsp[-2].integer.value - yyvsp[0].integer.value;
953 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp;
954 if (overflow_sum_sign (yyval.integer.value, yyvsp[0].integer.value,
955 yyvsp[-2].integer.value, yyval.integer.signedp))
956 integer_overflow (); ;
957 break;}
958 case 17:
959 #line 287 "cexp.y"
960 { yyval.integer.signedp = yyvsp[-2].integer.signedp;
961 if ((yyvsp[0].integer.value & yyvsp[0].integer.signedp) < 0)
962 yyval.integer.value = right_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
963 else
964 yyval.integer.value = left_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
965 break;}
966 case 18:
967 #line 293 "cexp.y"
968 { yyval.integer.signedp = yyvsp[-2].integer.signedp;
969 if ((yyvsp[0].integer.value & yyvsp[0].integer.signedp) < 0)
970 yyval.integer.value = left_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
971 else
972 yyval.integer.value = right_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); ;
973 break;}
974 case 19:
975 #line 299 "cexp.y"
976 { yyval.integer.value = (yyvsp[-2].integer.value == yyvsp[0].integer.value);
977 yyval.integer.signedp = SIGNED; ;
978 break;}
979 case 20:
980 #line 302 "cexp.y"
981 { yyval.integer.value = (yyvsp[-2].integer.value != yyvsp[0].integer.value);
982 yyval.integer.signedp = SIGNED; ;
983 break;}
984 case 21:
985 #line 305 "cexp.y"
986 { yyval.integer.signedp = SIGNED;
987 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
988 yyval.integer.value = yyvsp[-2].integer.value <= yyvsp[0].integer.value;
989 else
990 yyval.integer.value = ((unsigned HOST_WIDEST_INT) yyvsp[-2].integer.value
991 <= yyvsp[0].integer.value); ;
992 break;}
993 case 22:
994 #line 312 "cexp.y"
995 { yyval.integer.signedp = SIGNED;
996 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
997 yyval.integer.value = yyvsp[-2].integer.value >= yyvsp[0].integer.value;
998 else
999 yyval.integer.value = ((unsigned HOST_WIDEST_INT) yyvsp[-2].integer.value
1000 >= yyvsp[0].integer.value); ;
1001 break;}
1002 case 23:
1003 #line 319 "cexp.y"
1004 { yyval.integer.signedp = SIGNED;
1005 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
1006 yyval.integer.value = yyvsp[-2].integer.value < yyvsp[0].integer.value;
1007 else
1008 yyval.integer.value = ((unsigned HOST_WIDEST_INT) yyvsp[-2].integer.value
1009 < yyvsp[0].integer.value); ;
1010 break;}
1011 case 24:
1012 #line 326 "cexp.y"
1013 { yyval.integer.signedp = SIGNED;
1014 if (yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp)
1015 yyval.integer.value = yyvsp[-2].integer.value > yyvsp[0].integer.value;
1016 else
1017 yyval.integer.value = ((unsigned HOST_WIDEST_INT) yyvsp[-2].integer.value
1018 > yyvsp[0].integer.value); ;
1019 break;}
1020 case 25:
1021 #line 333 "cexp.y"
1022 { yyval.integer.value = yyvsp[-2].integer.value & yyvsp[0].integer.value;
1023 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1024 break;}
1025 case 26:
1026 #line 336 "cexp.y"
1027 { yyval.integer.value = yyvsp[-2].integer.value ^ yyvsp[0].integer.value;
1028 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1029 break;}
1030 case 27:
1031 #line 339 "cexp.y"
1032 { yyval.integer.value = yyvsp[-2].integer.value | yyvsp[0].integer.value;
1033 yyval.integer.signedp = yyvsp[-2].integer.signedp & yyvsp[0].integer.signedp; ;
1034 break;}
1035 case 28:
1036 #line 342 "cexp.y"
1037 { skip_evaluation += !yyvsp[-1].integer.value; ;
1038 break;}
1039 case 29:
1040 #line 344 "cexp.y"
1041 { skip_evaluation -= !yyvsp[-3].integer.value;
1042 yyval.integer.value = (yyvsp[-3].integer.value && yyvsp[0].integer.value);
1043 yyval.integer.signedp = SIGNED; ;
1044 break;}
1045 case 30:
1046 #line 348 "cexp.y"
1047 { skip_evaluation += !!yyvsp[-1].integer.value; ;
1048 break;}
1049 case 31:
1050 #line 350 "cexp.y"
1051 { skip_evaluation -= !!yyvsp[-3].integer.value;
1052 yyval.integer.value = (yyvsp[-3].integer.value || yyvsp[0].integer.value);
1053 yyval.integer.signedp = SIGNED; ;
1054 break;}
1055 case 32:
1056 #line 354 "cexp.y"
1057 { skip_evaluation += !yyvsp[-1].integer.value; ;
1058 break;}
1059 case 33:
1060 #line 356 "cexp.y"
1061 { skip_evaluation += !!yyvsp[-4].integer.value - !yyvsp[-4].integer.value; ;
1062 break;}
1063 case 34:
1064 #line 358 "cexp.y"
1065 { skip_evaluation -= !!yyvsp[-6].integer.value;
1066 yyval.integer.value = yyvsp[-6].integer.value ? yyvsp[-3].integer.value : yyvsp[0].integer.value;
1067 yyval.integer.signedp = yyvsp[-3].integer.signedp & yyvsp[0].integer.signedp; ;
1068 break;}
1069 case 35:
1070 #line 362 "cexp.y"
1071 { yyval.integer = yylval.integer; ;
1072 break;}
1073 case 36:
1074 #line 364 "cexp.y"
1075 { yyval.integer = yylval.integer; ;
1076 break;}
1077 case 37:
1078 #line 366 "cexp.y"
1079 { if (warn_undef && !skip_evaluation)
1080 warning ("`%.*s' is not defined",
1081 yyvsp[0].name.length, yyvsp[0].name.address);
1082 yyval.integer.value = 0;
1083 yyval.integer.signedp = SIGNED; ;
1084 break;}
1085 case 38:
1086 #line 374 "cexp.y"
1087 { yyval.keywords = 0; ;
1088 break;}
1089 case 39:
1090 #line 376 "cexp.y"
1091 { struct arglist *temp;
1092 yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1093 yyval.keywords->next = yyvsp[-2].keywords;
1094 yyval.keywords->name = (U_CHAR *) "(";
1095 yyval.keywords->length = 1;
1096 temp = yyval.keywords;
1097 while (temp != 0 && temp->next != 0)
1098 temp = temp->next;
1099 temp->next = (struct arglist *) xmalloc (sizeof (struct arglist));
1100 temp->next->next = yyvsp[0].keywords;
1101 temp->next->name = (U_CHAR *) ")";
1102 temp->next->length = 1; ;
1103 break;}
1104 case 40:
1105 #line 389 "cexp.y"
1106 { yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1107 yyval.keywords->name = yyvsp[-1].name.address;
1108 yyval.keywords->length = yyvsp[-1].name.length;
1109 yyval.keywords->next = yyvsp[0].keywords; ;
1110 break;}
1112 /* the action file gets copied in in place of this dollarsign */
1113 #line 498 "/usr/cygnus/TBD-TBD/share/bison.simple"
1115 yyvsp -= yylen;
1116 yyssp -= yylen;
1117 #ifdef YYLSP_NEEDED
1118 yylsp -= yylen;
1119 #endif
1121 #if YYDEBUG != 0
1122 if (yydebug)
1124 short *ssp1 = yyss - 1;
1125 fprintf (stderr, "state stack now");
1126 while (ssp1 != yyssp)
1127 fprintf (stderr, " %d", *++ssp1);
1128 fprintf (stderr, "\n");
1130 #endif
1132 *++yyvsp = yyval;
1134 #ifdef YYLSP_NEEDED
1135 yylsp++;
1136 if (yylen == 0)
1138 yylsp->first_line = yylloc.first_line;
1139 yylsp->first_column = yylloc.first_column;
1140 yylsp->last_line = (yylsp-1)->last_line;
1141 yylsp->last_column = (yylsp-1)->last_column;
1142 yylsp->text = 0;
1144 else
1146 yylsp->last_line = (yylsp+yylen-1)->last_line;
1147 yylsp->last_column = (yylsp+yylen-1)->last_column;
1149 #endif
1151 /* Now "shift" the result of the reduction.
1152 Determine what state that goes to,
1153 based on the state we popped back to
1154 and the rule number reduced by. */
1156 yyn = yyr1[yyn];
1158 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1159 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1160 yystate = yytable[yystate];
1161 else
1162 yystate = yydefgoto[yyn - YYNTBASE];
1164 goto yynewstate;
1166 yyerrlab: /* here on detecting error */
1168 if (! yyerrstatus)
1169 /* If not already recovering from an error, report this error. */
1171 ++yynerrs;
1173 #ifdef YYERROR_VERBOSE
1174 yyn = yypact[yystate];
1176 if (yyn > YYFLAG && yyn < YYLAST)
1178 int size = 0;
1179 char *msg;
1180 int x, count;
1182 count = 0;
1183 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1184 for (x = (yyn < 0 ? -yyn : 0);
1185 x < (sizeof(yytname) / sizeof(char *)); x++)
1186 if (yycheck[x + yyn] == x)
1187 size += strlen(yytname[x]) + 15, count++;
1188 msg = (char *) malloc(size + 15);
1189 if (msg != 0)
1191 strcpy(msg, "parse error");
1193 if (count < 5)
1195 count = 0;
1196 for (x = (yyn < 0 ? -yyn : 0);
1197 x < (sizeof(yytname) / sizeof(char *)); x++)
1198 if (yycheck[x + yyn] == x)
1200 strcat(msg, count == 0 ? ", expecting `" : " or `");
1201 strcat(msg, yytname[x]);
1202 strcat(msg, "'");
1203 count++;
1206 yyerror(msg);
1207 free(msg);
1209 else
1210 yyerror ("parse error; also virtual memory exceeded");
1212 else
1213 #endif /* YYERROR_VERBOSE */
1214 yyerror("parse error");
1217 goto yyerrlab1;
1218 yyerrlab1: /* here on error raised explicitly by an action */
1220 if (yyerrstatus == 3)
1222 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1224 /* return failure if at end of input */
1225 if (yychar == YYEOF)
1226 YYABORT;
1228 #if YYDEBUG != 0
1229 if (yydebug)
1230 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1231 #endif
1233 yychar = YYEMPTY;
1236 /* Else will try to reuse lookahead token
1237 after shifting the error token. */
1239 yyerrstatus = 3; /* Each real token shifted decrements this */
1241 goto yyerrhandle;
1243 yyerrdefault: /* current state does not do anything special for the error token. */
1245 #if 0
1246 /* This is wrong; only states that explicitly want error tokens
1247 should shift them. */
1248 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1249 if (yyn) goto yydefault;
1250 #endif
1252 yyerrpop: /* pop the current state because it cannot handle the error token */
1254 if (yyssp == yyss) YYABORT;
1255 yyvsp--;
1256 yystate = *--yyssp;
1257 #ifdef YYLSP_NEEDED
1258 yylsp--;
1259 #endif
1261 #if YYDEBUG != 0
1262 if (yydebug)
1264 short *ssp1 = yyss - 1;
1265 fprintf (stderr, "Error: state stack now");
1266 while (ssp1 != yyssp)
1267 fprintf (stderr, " %d", *++ssp1);
1268 fprintf (stderr, "\n");
1270 #endif
1272 yyerrhandle:
1274 yyn = yypact[yystate];
1275 if (yyn == YYFLAG)
1276 goto yyerrdefault;
1278 yyn += YYTERROR;
1279 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1280 goto yyerrdefault;
1282 yyn = yytable[yyn];
1283 if (yyn < 0)
1285 if (yyn == YYFLAG)
1286 goto yyerrpop;
1287 yyn = -yyn;
1288 goto yyreduce;
1290 else if (yyn == 0)
1291 goto yyerrpop;
1293 if (yyn == YYFINAL)
1294 YYACCEPT;
1296 #if YYDEBUG != 0
1297 if (yydebug)
1298 fprintf(stderr, "Shifting error token, ");
1299 #endif
1301 *++yyvsp = yylval;
1302 #ifdef YYLSP_NEEDED
1303 *++yylsp = yylloc;
1304 #endif
1306 yystate = yyn;
1307 goto yynewstate;
1309 #line 394 "cexp.y"
1312 /* During parsing of a C expression, the pointer to the next character
1313 is in this variable. */
1315 static char *lexptr;
1317 /* Take care of parsing a number (anything that starts with a digit).
1318 Set yylval and return the token type; update lexptr.
1319 LEN is the number of characters in it. */
1321 /* maybe needs to actually deal with floating point numbers */
1323 static int
1324 parse_number (olen)
1325 int olen;
1327 register char *p = lexptr;
1328 register int c;
1329 register unsigned HOST_WIDEST_INT n = 0, nd, max_over_base;
1330 register int base = 10;
1331 register int len = olen;
1332 register int overflow = 0;
1333 register int digit, largest_digit = 0;
1334 int spec_long = 0;
1336 yylval.integer.signedp = SIGNED;
1338 if (*p == '0') {
1339 base = 8;
1340 if (len >= 3 && (p[1] == 'x' || p[1] == 'X')) {
1341 p += 2;
1342 base = 16;
1343 len -= 2;
1347 max_over_base = (unsigned HOST_WIDEST_INT) -1 / base;
1349 for (; len > 0; len--) {
1350 c = *p++;
1352 if (c >= '0' && c <= '9')
1353 digit = c - '0';
1354 else if (base == 16 && c >= 'a' && c <= 'f')
1355 digit = c - 'a' + 10;
1356 else if (base == 16 && c >= 'A' && c <= 'F')
1357 digit = c - 'A' + 10;
1358 else {
1359 /* `l' means long, and `u' means unsigned. */
1360 while (1) {
1361 if (c == 'l' || c == 'L')
1363 if (!pedantic < spec_long)
1364 yyerror ("too many `l's in integer constant");
1365 spec_long++;
1367 else if (c == 'u' || c == 'U')
1369 if (! yylval.integer.signedp)
1370 yyerror ("two `u's in integer constant");
1371 yylval.integer.signedp = UNSIGNED;
1373 else {
1374 if (c == '.' || c == 'e' || c == 'E' || c == 'p' || c == 'P')
1375 yyerror ("Floating point numbers not allowed in #if expressions");
1376 else
1377 yyerror ("missing white space after number `%.*s'",
1378 (int) (p - lexptr - 1), lexptr);
1381 if (--len == 0)
1382 break;
1383 c = *p++;
1385 /* Don't look for any more digits after the suffixes. */
1386 break;
1388 if (largest_digit < digit)
1389 largest_digit = digit;
1390 nd = n * base + digit;
1391 overflow |= (max_over_base < n) | (nd < n);
1392 n = nd;
1395 if (base <= largest_digit)
1396 pedwarn ("integer constant contains digits beyond the radix");
1398 if (overflow)
1399 pedwarn ("integer constant out of range");
1401 /* If too big to be signed, consider it unsigned. */
1402 if (((HOST_WIDEST_INT) n & yylval.integer.signedp) < 0)
1404 if (base == 10)
1405 warning ("integer constant is so large that it is unsigned");
1406 yylval.integer.signedp = UNSIGNED;
1409 lexptr = p;
1410 yylval.integer.value = n;
1411 return INT;
1414 struct token {
1415 const char *operator;
1416 int token;
1419 static struct token tokentab2[] = {
1420 {"&&", AND},
1421 {"||", OR},
1422 {"<<", LSH},
1423 {">>", RSH},
1424 {"==", EQUAL},
1425 {"!=", NOTEQUAL},
1426 {"<=", LEQ},
1427 {">=", GEQ},
1428 {"++", ERROR},
1429 {"--", ERROR},
1430 {NULL, ERROR}
1433 /* Read one token, getting characters through lexptr. */
1435 static int
1436 yylex ()
1438 register int c;
1439 register int namelen;
1440 register unsigned char *tokstart;
1441 register struct token *toktab;
1442 int wide_flag;
1443 HOST_WIDEST_INT mask;
1445 retry:
1447 tokstart = (unsigned char *) lexptr;
1448 c = *tokstart;
1449 /* See if it is a special token of length 2. */
1450 if (! keyword_parsing)
1451 for (toktab = tokentab2; toktab->operator != NULL; toktab++)
1452 if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) {
1453 lexptr += 2;
1454 if (toktab->token == ERROR)
1455 yyerror ("`%s' not allowed in operand of `#if'", toktab->operator);
1456 return toktab->token;
1459 switch (c) {
1460 case '\n':
1461 return 0;
1463 case ' ':
1464 case '\t':
1465 case '\r':
1466 lexptr++;
1467 goto retry;
1469 case 'L':
1470 /* Capital L may start a wide-string or wide-character constant. */
1471 if (lexptr[1] == '\'')
1473 lexptr++;
1474 wide_flag = 1;
1475 mask = MAX_WCHAR_TYPE_MASK;
1476 goto char_constant;
1478 if (lexptr[1] == '"')
1480 lexptr++;
1481 wide_flag = 1;
1482 mask = MAX_WCHAR_TYPE_MASK;
1483 goto string_constant;
1485 break;
1487 case '\'':
1488 wide_flag = 0;
1489 mask = MAX_CHAR_TYPE_MASK;
1490 char_constant:
1491 lexptr++;
1492 if (keyword_parsing) {
1493 char *start_ptr = lexptr - 1;
1494 while (1) {
1495 c = *lexptr++;
1496 if (c == '\\')
1497 c = parse_escape (&lexptr, mask);
1498 else if (c == '\'')
1499 break;
1501 yylval.name.address = tokstart;
1502 yylval.name.length = lexptr - start_ptr;
1503 return NAME;
1506 /* This code for reading a character constant
1507 handles multicharacter constants and wide characters.
1508 It is mostly copied from c-lex.c. */
1510 register HOST_WIDEST_INT result = 0;
1511 register int num_chars = 0;
1512 int chars_seen = 0;
1513 unsigned width = MAX_CHAR_TYPE_SIZE;
1514 int max_chars;
1515 #ifdef MULTIBYTE_CHARS
1516 int longest_char = local_mb_cur_max ();
1517 char *token_buffer = (char *) alloca (longest_char);
1518 (void) local_mbtowc (NULL_PTR, NULL_PTR, 0);
1519 #endif
1521 max_chars = MAX_LONG_TYPE_SIZE / width;
1522 if (wide_flag)
1523 width = MAX_WCHAR_TYPE_SIZE;
1525 while (1)
1527 c = *lexptr++;
1529 if (c == '\'' || c == EOF)
1530 break;
1532 ++chars_seen;
1533 if (c == '\\')
1535 c = parse_escape (&lexptr, mask);
1537 else
1539 #ifdef MULTIBYTE_CHARS
1540 wchar_t wc;
1541 int i;
1542 int char_len = -1;
1543 for (i = 1; i <= longest_char; ++i)
1545 token_buffer[i - 1] = c;
1546 char_len = local_mbtowc (& wc, token_buffer, i);
1547 if (char_len != -1)
1548 break;
1549 c = *lexptr++;
1551 if (char_len > 1)
1553 /* mbtowc sometimes needs an extra char before accepting */
1554 if (char_len < i)
1555 lexptr--;
1556 if (! wide_flag)
1558 /* Merge character into result; ignore excess chars. */
1559 for (i = 1; i <= char_len; ++i)
1561 if (i > max_chars)
1562 break;
1563 if (width < HOST_BITS_PER_INT)
1564 result = (result << width)
1565 | (token_buffer[i - 1]
1566 & ((1 << width) - 1));
1567 else
1568 result = token_buffer[i - 1];
1570 num_chars += char_len;
1571 continue;
1574 else
1576 if (char_len == -1)
1577 warning ("Ignoring invalid multibyte character");
1579 if (wide_flag)
1580 c = wc;
1581 #endif /* ! MULTIBYTE_CHARS */
1584 if (wide_flag)
1586 if (chars_seen == 1) /* only keep the first one */
1587 result = c;
1588 continue;
1591 /* Merge character into result; ignore excess chars. */
1592 num_chars++;
1593 if (num_chars <= max_chars)
1595 if (width < HOST_BITS_PER_INT)
1596 result = (result << width) | (c & ((1 << width) - 1));
1597 else
1598 result = c;
1602 if (c != '\'')
1603 error ("malformatted character constant");
1604 else if (chars_seen == 0)
1605 error ("empty character constant");
1606 else if (num_chars > max_chars)
1608 num_chars = max_chars;
1609 error ("character constant too long");
1611 else if (chars_seen != 1 && ! traditional)
1612 warning ("multi-character character constant");
1614 /* If char type is signed, sign-extend the constant. */
1615 if (! wide_flag)
1617 int num_bits = num_chars * width;
1618 if (num_bits == 0)
1619 /* We already got an error; avoid invalid shift. */
1620 yylval.integer.value = 0;
1621 else if (lookup ((U_CHAR *) "__CHAR_UNSIGNED__",
1622 sizeof ("__CHAR_UNSIGNED__") - 1, -1)
1623 || ((result >> (num_bits - 1)) & 1) == 0)
1624 yylval.integer.value
1625 = result & (~ (unsigned HOST_WIDEST_INT) 0
1626 >> (HOST_BITS_PER_WIDEST_INT - num_bits));
1627 else
1628 yylval.integer.value
1629 = result | ~(~ (unsigned HOST_WIDEST_INT) 0
1630 >> (HOST_BITS_PER_WIDEST_INT - num_bits));
1632 else
1634 yylval.integer.value = result;
1638 /* This is always a signed type. */
1639 yylval.integer.signedp = SIGNED;
1641 return CHAR;
1643 /* some of these chars are invalid in constant expressions;
1644 maybe do something about them later */
1645 case '/':
1646 case '+':
1647 case '-':
1648 case '*':
1649 case '%':
1650 case '|':
1651 case '&':
1652 case '^':
1653 case '~':
1654 case '!':
1655 case '@':
1656 case '<':
1657 case '>':
1658 case '[':
1659 case ']':
1660 case '.':
1661 case '?':
1662 case ':':
1663 case '=':
1664 case '{':
1665 case '}':
1666 case ',':
1667 case '#':
1668 if (keyword_parsing)
1669 break;
1670 case '(':
1671 case ')':
1672 lexptr++;
1673 return c;
1675 case '"':
1676 mask = MAX_CHAR_TYPE_MASK;
1677 string_constant:
1678 if (keyword_parsing) {
1679 char *start_ptr = lexptr;
1680 lexptr++;
1681 while (1) {
1682 c = *lexptr++;
1683 if (c == '\\')
1684 c = parse_escape (&lexptr, mask);
1685 else if (c == '"')
1686 break;
1688 yylval.name.address = tokstart;
1689 yylval.name.length = lexptr - start_ptr;
1690 return NAME;
1692 yyerror ("string constants not allowed in #if expressions");
1693 return ERROR;
1696 if (c >= '0' && c <= '9' && !keyword_parsing) {
1697 /* It's a number */
1698 for (namelen = 1; ; namelen++) {
1699 int d = tokstart[namelen];
1700 if (! ((is_idchar[d] || d == '.')
1701 || ((d == '-' || d == '+')
1702 && (c == 'e' || c == 'E'
1703 || ((c == 'p' || c == 'P') && ! c89))
1704 && ! traditional)))
1705 break;
1706 c = d;
1708 return parse_number (namelen);
1711 /* It is a name. See how long it is. */
1713 if (keyword_parsing) {
1714 for (namelen = 0;; namelen++) {
1715 if (is_space[tokstart[namelen]])
1716 break;
1717 if (tokstart[namelen] == '(' || tokstart[namelen] == ')')
1718 break;
1719 if (tokstart[namelen] == '"' || tokstart[namelen] == '\'')
1720 break;
1722 } else {
1723 if (!is_idstart[c]) {
1724 yyerror ("Invalid token in expression");
1725 return ERROR;
1728 for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
1732 lexptr += namelen;
1733 yylval.name.address = tokstart;
1734 yylval.name.length = namelen;
1735 return NAME;
1739 /* Parse a C escape sequence. STRING_PTR points to a variable
1740 containing a pointer to the string to parse. That pointer
1741 is updated past the characters we use. The value of the
1742 escape sequence is returned.
1744 RESULT_MASK is used to mask out the result;
1745 an error is reported if bits are lost thereby.
1747 A negative value means the sequence \ newline was seen,
1748 which is supposed to be equivalent to nothing at all.
1750 If \ is followed by a null character, we return a negative
1751 value and leave the string pointer pointing at the null character.
1753 If \ is followed by 000, we return 0 and leave the string pointer
1754 after the zeros. A value of 0 does not mean end of string. */
1756 HOST_WIDEST_INT
1757 parse_escape (string_ptr, result_mask)
1758 char **string_ptr;
1759 HOST_WIDEST_INT result_mask;
1761 register int c = *(*string_ptr)++;
1762 switch (c)
1764 case 'a':
1765 return TARGET_BELL;
1766 case 'b':
1767 return TARGET_BS;
1768 case 'e':
1769 case 'E':
1770 if (pedantic)
1771 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1772 return TARGET_ESC;
1773 case 'f':
1774 return TARGET_FF;
1775 case 'n':
1776 return TARGET_NEWLINE;
1777 case 'r':
1778 return TARGET_CR;
1779 case 't':
1780 return TARGET_TAB;
1781 case 'v':
1782 return TARGET_VT;
1783 case '\n':
1784 return -2;
1785 case 0:
1786 (*string_ptr)--;
1787 return 0;
1789 case '0':
1790 case '1':
1791 case '2':
1792 case '3':
1793 case '4':
1794 case '5':
1795 case '6':
1796 case '7':
1798 register HOST_WIDEST_INT i = c - '0';
1799 register int count = 0;
1800 while (++count < 3)
1802 c = *(*string_ptr)++;
1803 if (c >= '0' && c <= '7')
1804 i = (i << 3) + c - '0';
1805 else
1807 (*string_ptr)--;
1808 break;
1811 if (i != (i & result_mask))
1813 i &= result_mask;
1814 pedwarn ("octal escape sequence out of range");
1816 return i;
1818 case 'x':
1820 register unsigned HOST_WIDEST_INT i = 0, overflow = 0;
1821 register int digits_found = 0, digit;
1822 for (;;)
1824 c = *(*string_ptr)++;
1825 if (c >= '0' && c <= '9')
1826 digit = c - '0';
1827 else if (c >= 'a' && c <= 'f')
1828 digit = c - 'a' + 10;
1829 else if (c >= 'A' && c <= 'F')
1830 digit = c - 'A' + 10;
1831 else
1833 (*string_ptr)--;
1834 break;
1836 overflow |= i ^ (i << 4 >> 4);
1837 i = (i << 4) + digit;
1838 digits_found = 1;
1840 if (!digits_found)
1841 yyerror ("\\x used with no following hex digits");
1842 if (overflow | (i != (i & result_mask)))
1844 i &= result_mask;
1845 pedwarn ("hex escape sequence out of range");
1847 return i;
1849 default:
1850 return c;
1854 static void
1855 integer_overflow ()
1857 if (!skip_evaluation && pedantic)
1858 pedwarn ("integer overflow in preprocessor expression");
1861 static HOST_WIDEST_INT
1862 left_shift (a, b)
1863 struct constant *a;
1864 unsigned HOST_WIDEST_INT b;
1866 /* It's unclear from the C standard whether shifts can overflow.
1867 The following code ignores overflow; perhaps a C standard
1868 interpretation ruling is needed. */
1869 if (b >= HOST_BITS_PER_WIDEST_INT)
1870 return 0;
1871 else
1872 return (unsigned HOST_WIDEST_INT) a->value << b;
1875 static HOST_WIDEST_INT
1876 right_shift (a, b)
1877 struct constant *a;
1878 unsigned HOST_WIDEST_INT b;
1880 if (b >= HOST_BITS_PER_WIDEST_INT)
1881 return a->signedp ? a->value >> (HOST_BITS_PER_WIDEST_INT - 1) : 0;
1882 else if (a->signedp)
1883 return a->value >> b;
1884 else
1885 return (unsigned HOST_WIDEST_INT) a->value >> b;
1888 /* This page contains the entry point to this file. */
1890 /* Parse STRING as an expression, and complain if this fails
1891 to use up all of the contents of STRING.
1892 STRING may contain '\0' bytes; it is terminated by the first '\n'
1893 outside a string constant, so that we can diagnose '\0' properly.
1894 If WARN_UNDEFINED is nonzero, warn if undefined identifiers are evaluated.
1895 We do not support C comments. They should be removed before
1896 this function is called. */
1898 HOST_WIDEST_INT
1899 parse_c_expression (string, warn_undefined)
1900 char *string;
1901 int warn_undefined;
1903 lexptr = string;
1904 warn_undef = warn_undefined;
1906 /* if there is some sort of scanning error, just return 0 and assume
1907 the parsing routine has printed an error message somewhere.
1908 there is surely a better thing to do than this. */
1909 if (setjmp (parse_return_error))
1910 return 0;
1912 if (yyparse () != 0)
1913 abort ();
1915 if (*lexptr != '\n')
1916 error ("Junk after end of expression.");
1918 return expression_value; /* set by yyparse () */
1921 static void
1922 yyerror VPARAMS ((const char * msgid, ...))
1924 #ifndef ANSI_PROTOTYPES
1925 const char * msgid;
1926 #endif
1927 va_list args;
1929 VA_START (args, msgid);
1931 #ifndef ANSI_PROTOTYPES
1932 msgid = va_arg (args, const char *);
1933 #endif
1935 verror (msgid, args);
1936 va_end (args);
1937 skip_evaluation = 0;
1938 longjmp (parse_return_error, 1);
1942 #ifdef TEST_EXP_READER
1944 #if YYDEBUG
1945 extern int yydebug;
1946 #endif
1948 int pedantic;
1949 int traditional;
1950 int c89;
1952 int main PARAMS ((int, char **));
1953 static void initialize_random_junk PARAMS ((void));
1954 static void print_unsigned_host_widest_int PARAMS ((unsigned HOST_WIDEST_INT));
1956 /* Main program for testing purposes. */
1958 main (argc, argv)
1959 int argc;
1960 char **argv;
1962 int n, c;
1963 char buf[1024];
1964 unsigned HOST_WIDEST_INT u;
1966 pedantic = 1 < argc;
1967 traditional = 2 < argc;
1968 c89 = 3 < argc;
1969 #if YYDEBUG
1970 yydebug = 4 < argc;
1971 #endif
1972 initialize_random_junk ();
1974 for (;;) {
1975 printf ("enter expression: ");
1976 n = 0;
1977 while ((buf[n] = c = getchar ()) != '\n' && c != EOF)
1978 n++;
1979 if (c == EOF)
1980 break;
1981 parse_c_expression (buf, 1);
1982 printf ("parser returned ");
1983 u = (unsigned HOST_WIDEST_INT) expression_value;
1984 if (expression_value < 0 && expression_signedp) {
1985 u = -u;
1986 printf ("-");
1988 if (u == 0)
1989 printf ("0");
1990 else
1991 print_unsigned_host_widest_int (u);
1992 if (! expression_signedp)
1993 printf("u");
1994 printf ("\n");
1997 return 0;
2000 static void
2001 print_unsigned_host_widest_int (u)
2002 unsigned HOST_WIDEST_INT u;
2004 if (u) {
2005 print_unsigned_host_widest_int (u / 10);
2006 putchar ('0' + (int) (u % 10));
2010 /* table to tell if char can be part of a C identifier. */
2011 unsigned char is_idchar[256];
2012 /* table to tell if char can be first char of a c identifier. */
2013 unsigned char is_idstart[256];
2014 /* table to tell if c is horizontal or vertical space. */
2015 unsigned char is_space[256];
2018 * initialize random junk in the hash table and maybe other places
2020 static void
2021 initialize_random_junk ()
2023 register int i;
2026 * Set up is_idchar and is_idstart tables. These should be
2027 * faster than saying (is_alpha (c) || c == '_'), etc.
2028 * Must do set up these things before calling any routines tthat
2029 * refer to them.
2031 for (i = 'a'; i <= 'z'; i++) {
2032 ++is_idchar[TOUPPER(i)];
2033 ++is_idchar[i];
2034 ++is_idstart[TOUPPER(i)];
2035 ++is_idstart[i];
2037 for (i = '0'; i <= '9'; i++)
2038 ++is_idchar[i];
2039 ++is_idchar['_'];
2040 ++is_idstart['_'];
2041 ++is_idchar['$'];
2042 ++is_idstart['$'];
2044 ++is_space[' '];
2045 ++is_space['\t'];
2046 ++is_space['\v'];
2047 ++is_space['\f'];
2048 ++is_space['\n'];
2049 ++is_space['\r'];
2052 void
2053 error VPARAMS ((char * msgid, ...))
2055 #ifndef ANSI_PROTOTYPES
2056 char * msgid;
2057 #endif
2058 va_list args;
2060 VA_START (args, msgid);
2062 #ifndef ANSI_PROTOTYPES
2063 msgid = va_arg (args, char *);
2064 #endif
2066 fprintf (stderr, "error: ");
2067 vfprintf (stderr, _(msgid), args);
2068 fprintf (stderr, "\n");
2069 va_end (args);
2072 void
2073 pedwarn VPARAMS ((char * msgid, ...))
2075 #ifndef ANSI_PROTOTYPES
2076 char * msgid;
2077 #endif
2078 va_list args;
2080 VA_START (args, msgid);
2082 #ifndef ANSI_PROTOTYPES
2083 msgid = va_arg (args, char *);
2084 #endif
2086 fprintf (stderr, "pedwarn: ");
2087 vfprintf (stderr, _(msgid), args);
2088 fprintf (stderr, "\n");
2089 va_end (args);
2092 void
2093 warning VPARAMS ((char * msgid, ...))
2095 #ifndef ANSI_PROTOTYPES
2096 char * msgid;
2097 #endif
2098 va_list args;
2100 VA_START (args, msgid);
2102 #ifndef ANSI_PROTOTYPES
2103 msgid = va_arg (args, char *);
2104 #endif
2106 fprintf (stderr, "warning: ");
2107 vfprintf (stderr, _(msgid), args);
2108 fprintf (stderr, "\n");
2109 va_end (args);
2114 check_assertion (name, sym_length, tokens_specified, tokens)
2115 U_CHAR *name;
2116 int sym_length;
2117 int tokens_specified;
2118 struct arglist *tokens;
2120 return 0;
2123 struct hashnode *
2124 lookup (name, len, hash)
2125 U_CHAR *name;
2126 int len;
2127 int hash;
2129 return (DEFAULT_SIGNED_CHAR) ? 0 : ((struct hashnode *) -1);
2133 xmalloc (size)
2134 size_t size;
2136 return (PTR) malloc (size);
2138 #endif