This source file includes following definitions.
- yymemcpy
- yystrlen
- yystpcpy
- yyparse
- parse_number
- yylex
- parse_escape
- yyerror
- integer_overflow
- left_shift
- right_shift
- parse_c_expression
- main
- initialize_random_junk
- error
- warning
- lookup
1
2
3
4 #define YYBISON 1
5
6 # define INT 257
7 # define CHAR 258
8 # define NAME 259
9 # define ERROR 260
10 # define OR 261
11 # define AND 262
12 # define EQUAL 263
13 # define NOTEQUAL 264
14 # define LEQ 265
15 # define GEQ 266
16 # define LSH 267
17 # define RSH 268
18 # define UNARY 269
19
20 #line 26 "y-src/cccp.y"
21
22 #include "config.h"
23 #include <setjmp.h>
24
25
26 #ifdef MULTIBYTE_CHARS
27 #include <stdlib.h>
28 #include <locale.h>
29 #endif
30
31 #include <stdio.h>
32
33 typedef unsigned char U_CHAR;
34
35
36 struct arglist {
37 struct arglist *next;
38 U_CHAR *name;
39 int length;
40 int argno;
41 };
42
43
44
45 #ifndef NULL
46 #define NULL 0
47 #endif
48
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
56
57 #ifndef NULL_PTR
58 #define NULL_PTR ((GENERIC_PTR)0)
59 #endif
60
61 int yylex ();
62 void yyerror ();
63 int expression_value;
64
65 static jmp_buf parse_return_error;
66
67
68 static int keyword_parsing = 0;
69
70
71 extern unsigned char is_idstart[], is_idchar[], is_hor_space[];
72
73 extern char *xmalloc ();
74
75
76 extern int pedantic;
77
78
79 extern int traditional;
80
81 #ifndef CHAR_TYPE_SIZE
82 #define CHAR_TYPE_SIZE BITS_PER_UNIT
83 #endif
84
85 #ifndef INT_TYPE_SIZE
86 #define INT_TYPE_SIZE BITS_PER_WORD
87 #endif
88
89 #ifndef LONG_TYPE_SIZE
90 #define LONG_TYPE_SIZE BITS_PER_WORD
91 #endif
92
93 #ifndef WCHAR_TYPE_SIZE
94 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
95 #endif
96
97
98
99 #define possible_sum_sign(a, b, sum) ((((a) ^ (b)) | ~ ((a) ^ (sum))) < 0)
100
101 static void integer_overflow ();
102 static long left_shift ();
103 static long right_shift ();
104
105 #line 111 "y-src/cccp.y"
106 #ifndef YYSTYPE
107 typedef union {
108 struct constant {long value; int unsignedp;} integer;
109 struct name {U_CHAR *address; int length;} name;
110 struct arglist *keywords;
111 int voidval;
112 char *sval;
113 } yystype;
114 # define YYSTYPE yystype
115 #endif
116 #ifndef YYDEBUG
117 # define YYDEBUG 0
118 #endif
119
120
121
122 #define YYFINAL 73
123 #define YYFLAG -32768
124 #define YYNTBASE 34
125
126
127 #define YYTRANSLATE(x) ((unsigned)(x) <= 269 ? yytranslate[x] : 39)
128
129
130 static const char yytranslate[] =
131 {
132 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
133 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
134 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
135 2, 2, 2, 29, 2, 31, 2, 27, 14, 2,
136 32, 33, 25, 23, 9, 24, 2, 26, 2, 2,
137 2, 2, 2, 2, 2, 2, 2, 2, 8, 2,
138 17, 2, 18, 7, 2, 2, 2, 2, 2, 2,
139 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
140 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
141 2, 2, 2, 2, 13, 2, 2, 2, 2, 2,
142 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
143 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
144 2, 2, 2, 2, 12, 2, 30, 2, 2, 2,
145 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
146 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
147 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
148 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
149 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
150 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
151 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
152 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
153 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
154 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
155 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
156 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
157 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
158 6, 10, 11, 15, 16, 19, 20, 21, 22, 28
159 };
160
161 #if YYDEBUG
162 static const short yyprhs[] =
163 {
164 0, 0, 2, 4, 8, 11, 14, 17, 20, 23,
165 24, 31, 35, 39, 43, 47, 51, 55, 59, 63,
166 67, 71, 75, 79, 83, 87, 91, 95, 99, 103,
167 107, 113, 115, 117, 119, 120, 125
168 };
169 static const short yyrhs[] =
170 {
171 35, 0, 36, 0, 35, 9, 36, 0, 24, 36,
172 0, 29, 36, 0, 23, 36, 0, 30, 36, 0,
173 31, 5, 0, 0, 31, 5, 37, 32, 38, 33,
174 0, 32, 35, 33, 0, 36, 25, 36, 0, 36,
175 26, 36, 0, 36, 27, 36, 0, 36, 23, 36,
176 0, 36, 24, 36, 0, 36, 21, 36, 0, 36,
177 22, 36, 0, 36, 15, 36, 0, 36, 16, 36,
178 0, 36, 19, 36, 0, 36, 20, 36, 0, 36,
179 17, 36, 0, 36, 18, 36, 0, 36, 14, 36,
180 0, 36, 13, 36, 0, 36, 12, 36, 0, 36,
181 11, 36, 0, 36, 10, 36, 0, 36, 7, 36,
182 8, 36, 0, 3, 0, 4, 0, 5, 0, 0,
183 32, 38, 33, 38, 0, 5, 38, 0
184 };
185
186 #endif
187
188 #if YYDEBUG
189
190 static const short yyrline[] =
191 {
192 0, 143, 148, 149, 156, 161, 164, 166, 169, 173,
193 173, 180, 185, 197, 212, 223, 230, 237, 243, 249,
194 252, 255, 261, 267, 273, 279, 282, 285, 288, 291,
195 294, 297, 299, 301, 306, 308, 321
196 };
197 #endif
198
199
200 #if (YYDEBUG) || defined YYERROR_VERBOSE
201
202
203 static const char *const yytname[] =
204 {
205 "$", "error", "$undefined.", "INT", "CHAR", "NAME", "ERROR", "'?'", "':'",
206 "','", "OR", "AND", "'|'", "'^'", "'&'", "EQUAL", "NOTEQUAL", "'<'",
207 "'>'", "LEQ", "GEQ", "LSH", "RSH", "'+'", "'-'", "'*'", "'/'", "'%'",
208 "UNARY", "'!'", "'~'", "'#'", "'('", "')'", "start", "exp1", "exp",
209 "@1", "keywords", NULL
210 };
211 #endif
212
213
214 static const short yyr1[] =
215 {
216 0, 34, 35, 35, 36, 36, 36, 36, 36, 37,
217 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
218 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
219 36, 36, 36, 36, 38, 38, 38
220 };
221
222
223 static const short yyr2[] =
224 {
225 0, 1, 1, 3, 2, 2, 2, 2, 2, 0,
226 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
227 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
228 5, 1, 1, 1, 0, 4, 2
229 };
230
231
232
233
234 static const short yydefact[] =
235 {
236 0, 31, 32, 33, 0, 0, 0, 0, 0, 0,
237 1, 2, 6, 4, 5, 7, 8, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 11,
240 3, 0, 29, 28, 27, 26, 25, 19, 20, 23,
241 24, 21, 22, 17, 18, 15, 16, 12, 13, 14,
242 34, 0, 34, 34, 0, 30, 36, 0, 10, 34,
243 35, 0, 0, 0
244 };
245
246 static const short yydefgoto[] =
247 {
248 71, 10, 11, 38, 64
249 };
250
251 static const short yypact[] =
252 {
253 31,-32768,-32768,-32768, 31, 31, 31, 31, 4, 31,
254 3, 80,-32768,-32768,-32768,-32768, 6, 32, 31, 31,
255 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
256 31, 31, 31, 31, 31, 31, 31, 31, 7,-32768,
257 80, 59, 97, 113, 128, 142, 155, 25, 25, 162,
258 162, 162, 162, 167, 167, -19, -19,-32768,-32768,-32768,
259 5, 31, 5, 5, -20, 80,-32768, 20,-32768, 5,
260 -32768, 40, 56,-32768
261 };
262
263 static const short yypgoto[] =
264 {
265 -32768, 49, -4,-32768, -58
266 };
267
268
269 #define YYLAST 194
270
271
272 static const short yytable[] =
273 {
274 12, 13, 14, 15, 66, 67, 35, 36, 37, 16,
275 62, 70, 18, 68, 40, 41, 42, 43, 44, 45,
276 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
277 56, 57, 58, 59, 1, 2, 3, 63, -9, 60,
278 72, 18, 27, 28, 29, 30, 31, 32, 33, 34,
279 35, 36, 37, 69, 4, 5, 73, 65, 17, 0,
280 6, 7, 8, 9, 0, 39, 19, 61, 0, 20,
281 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
282 31, 32, 33, 34, 35, 36, 37, 19, 0, 0,
283 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
284 30, 31, 32, 33, 34, 35, 36, 37, 21, 22,
285 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
286 33, 34, 35, 36, 37, 22, 23, 24, 25, 26,
287 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
288 37, 23, 24, 25, 26, 27, 28, 29, 30, 31,
289 32, 33, 34, 35, 36, 37, 24, 25, 26, 27,
290 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
291 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
292 35, 36, 37, 31, 32, 33, 34, 35, 36, 37,
293 33, 34, 35, 36, 37
294 };
295
296 static const short yycheck[] =
297 {
298 4, 5, 6, 7, 62, 63, 25, 26, 27, 5,
299 5, 69, 9, 33, 18, 19, 20, 21, 22, 23,
300 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
301 34, 35, 36, 37, 3, 4, 5, 32, 32, 32,
302 0, 9, 17, 18, 19, 20, 21, 22, 23, 24,
303 25, 26, 27, 33, 23, 24, 0, 61, 9, -1,
304 29, 30, 31, 32, -1, 33, 7, 8, -1, 10,
305 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
306 21, 22, 23, 24, 25, 26, 27, 7, -1, -1,
307 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
308 20, 21, 22, 23, 24, 25, 26, 27, 11, 12,
309 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
310 23, 24, 25, 26, 27, 12, 13, 14, 15, 16,
311 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
312 27, 13, 14, 15, 16, 17, 18, 19, 20, 21,
313 22, 23, 24, 25, 26, 27, 14, 15, 16, 17,
314 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
315 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
316 25, 26, 27, 21, 22, 23, 24, 25, 26, 27,
317 23, 24, 25, 26, 27
318 };
319
320 #line 3 "/usr/share/bison/bison.simple"
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358 #ifdef __cplusplus
359 # define YYSTD(x) std::x
360 #else
361 # define YYSTD(x) x
362 #endif
363
364 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
365
366
367
368 # if YYSTACK_USE_ALLOCA
369 # define YYSTACK_ALLOC alloca
370 # define YYSIZE_T YYSTD (size_t)
371 # else
372 # ifndef YYSTACK_USE_ALLOCA
373 # if defined (alloca) || defined (_ALLOCA_H)
374 # define YYSTACK_ALLOC alloca
375 # define YYSIZE_T YYSTD (size_t)
376 # else
377 # ifdef __GNUC__
378 # define YYSTACK_ALLOC __builtin_alloca
379 # endif
380 # endif
381 # endif
382 # endif
383
384 # ifdef YYSTACK_ALLOC
385
386 # define YYSTACK_FREE(Ptr) do { ; } while (0)
387 # else
388 # ifdef __cplusplus
389 # include <cstdlib>
390 # define YYSIZE_T std::size_t
391 # else
392 # ifdef __STDC__
393 # include <stdlib.h>
394 # define YYSIZE_T size_t
395 # endif
396 # endif
397 # define YYSTACK_ALLOC YYSTD (malloc)
398 # define YYSTACK_FREE YYSTD (free)
399 # endif
400
401
402 union yyalloc
403 {
404 short yyss;
405 YYSTYPE yyvs;
406 # if YYLSP_NEEDED
407 YYLTYPE yyls;
408 # endif
409 };
410
411
412 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
413
414
415
416 # if YYLSP_NEEDED
417 # define YYSTACK_BYTES(N) \
418 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
419 + 2 * YYSTACK_GAP_MAX)
420 # else
421 # define YYSTACK_BYTES(N) \
422 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
423 + YYSTACK_GAP_MAX)
424 # endif
425
426
427
428
429
430
431 # define YYSTACK_RELOCATE(Type, Stack) \
432 do \
433 { \
434 YYSIZE_T yynewbytes; \
435 yymemcpy ((char *) yyptr, (char *) (Stack), \
436 yysize * (YYSIZE_T) sizeof (Type)); \
437 Stack = &yyptr->Stack; \
438 yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX; \
439 yyptr += yynewbytes / sizeof (*yyptr); \
440 } \
441 while (0)
442
443 #endif
444
445
446 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
447 # define YYSIZE_T __SIZE_TYPE__
448 #endif
449 #if ! defined (YYSIZE_T) && defined (size_t)
450 # define YYSIZE_T size_t
451 #endif
452 #if ! defined (YYSIZE_T)
453 # ifdef __cplusplus
454 # include <cstddef>
455 # define YYSIZE_T std::size_t
456 # else
457 # ifdef __STDC__
458 # include <stddef.h>
459 # define YYSIZE_T size_t
460 # endif
461 # endif
462 #endif
463 #if ! defined (YYSIZE_T)
464 # define YYSIZE_T unsigned int
465 #endif
466
467 #define yyerrok (yyerrstatus = 0)
468 #define yyclearin (yychar = YYEMPTY)
469 #define YYEMPTY -2
470 #define YYEOF 0
471 #define YYACCEPT goto yyacceptlab
472 #define YYABORT goto yyabortlab
473 #define YYERROR goto yyerrlab1
474
475
476
477 #define YYFAIL goto yyerrlab
478 #define YYRECOVERING() (!!yyerrstatus)
479 #define YYBACKUP(Token, Value) \
480 do \
481 if (yychar == YYEMPTY && yylen == 1) \
482 { \
483 yychar = (Token); \
484 yylval = (Value); \
485 yychar1 = YYTRANSLATE (yychar); \
486 YYPOPSTACK; \
487 goto yybackup; \
488 } \
489 else \
490 { \
491 yyerror ("syntax error: cannot back up"); \
492 YYERROR; \
493 } \
494 while (0)
495
496 #define YYTERROR 1
497 #define YYERRCODE 256
498
499
500
501
502
503
504
505
506
507 #ifndef YYLLOC_DEFAULT
508 # define YYLLOC_DEFAULT(Current, Rhs, N) \
509 Current.last_line = Rhs[N].last_line; \
510 Current.last_column = Rhs[N].last_column;
511 #endif
512
513
514
515
516 #if YYPURE
517 # if YYLSP_NEEDED
518 # ifdef YYLEX_PARAM
519 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
520 # else
521 # define YYLEX yylex (&yylval, &yylloc)
522 # endif
523 # else
524 # ifdef YYLEX_PARAM
525 # define YYLEX yylex (&yylval, YYLEX_PARAM)
526 # else
527 # define YYLEX yylex (&yylval)
528 # endif
529 # endif
530 #else
531 # define YYLEX yylex ()
532 #endif
533
534
535
536 #if YYDEBUG
537
538 # ifndef YYFPRINTF
539 # ifdef __cplusplus
540 # include <cstdio>
541 # else
542 # include <stdio.h>
543 # endif
544 # define YYFPRINTF YYSTD (fprintf)
545 # endif
546
547 # define YYDPRINTF(Args) \
548 do { \
549 if (yydebug) \
550 YYFPRINTF Args; \
551 } while (0)
552
553
554
555
556 int yydebug;
557 #else
558 # define YYDPRINTF(Args)
559 #endif
560
561
562 #ifndef YYINITDEPTH
563 # define YYINITDEPTH 200
564 #endif
565
566
567
568
569
570
571
572
573 #if YYMAXDEPTH == 0
574 # undef YYMAXDEPTH
575 #endif
576
577 #ifndef YYMAXDEPTH
578 # define YYMAXDEPTH 10000
579 #endif
580
581 #if ! defined (yyoverflow) && ! defined (yymemcpy)
582 # if __GNUC__ > 1
583 # define yymemcpy __builtin_memcpy
584 # else
585
586
587
588 static void
589 # if defined (__STDC__) || defined (__cplusplus)
590 yymemcpy (char *yyto, const char *yyfrom, YYSIZE_T yycount)
591 # else
592 yymemcpy (yyto, yyfrom, yycount)
593 char *yyto;
594 const char *yyfrom;
595 YYSIZE_T yycount;
596 # endif
597 {
598 register const char *yyf = yyfrom;
599 register char *yyt = yyto;
600 register YYSIZE_T yyi = yycount;
601
602 while (yyi-- != 0)
603 *yyt++ = *yyf++;
604 }
605 # endif
606 #endif
607
608 #ifdef YYERROR_VERBOSE
609
610 # ifndef yystrlen
611 # if defined (__GLIBC__) && defined (_STRING_H)
612 # define yystrlen strlen
613 # else
614
615 static YYSIZE_T
616 # if defined (__STDC__) || defined (__cplusplus)
617 yystrlen (const char *yystr)
618 # else
619 yystrlen (yystr)
620 const char *yystr;
621 # endif
622 {
623 register const char *yys = yystr;
624
625 while (*yys++ != '\0')
626 continue;
627
628 return yys - yystr - 1;
629 }
630 # endif
631 # endif
632
633 # ifndef yystpcpy
634 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
635 # define yystpcpy stpcpy
636 # else
637
638
639 static char *
640 # if defined (__STDC__) || defined (__cplusplus)
641 yystpcpy (char *yydest, const char *yysrc)
642 # else
643 yystpcpy (yydest, yysrc)
644 char *yydest;
645 const char *yysrc;
646 # endif
647 {
648 register char *yyd = yydest;
649 register const char *yys = yysrc;
650
651 while ((*yyd++ = *yys++) != '\0')
652 continue;
653
654 return yyd - 1;
655 }
656 # endif
657 # endif
658 #endif
659
660 #line 341 "/usr/share/bison/bison.simple"
661
662
663
664
665
666
667
668
669 #ifdef YYPARSE_PARAM
670 # ifdef __cplusplus
671 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
672 # define YYPARSE_PARAM_DECL
673 # else
674 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
675 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
676 # endif
677 #else
678 # define YYPARSE_PARAM_ARG
679 # define YYPARSE_PARAM_DECL
680 #endif
681
682
683 #ifdef __GNUC__
684 # ifdef YYPARSE_PARAM
685 int yyparse (void *);
686 # else
687 int yyparse (void);
688 # endif
689 #endif
690
691
692
693
694 #define YY_DECL_NON_LSP_VARIABLES \
695 \
696 int yychar; \
697 \
698 \
699 YYSTYPE yylval; \
700 \
701 \
702 int yynerrs;
703
704 #if YYLSP_NEEDED
705 # define YY_DECL_VARIABLES \
706 YY_DECL_NON_LSP_VARIABLES \
707 \
708 \
709 YYLTYPE yylloc;
710 #else
711 # define YY_DECL_VARIABLES \
712 YY_DECL_NON_LSP_VARIABLES
713 #endif
714
715
716
717
718 #if !YYPURE
719 YY_DECL_VARIABLES
720 #endif
721
722 int
723 yyparse (YYPARSE_PARAM_ARG)
724 YYPARSE_PARAM_DECL
725 {
726
727 #if YYPURE
728 YY_DECL_VARIABLES
729 #endif
730
731 register int yystate;
732 register int yyn;
733 int yyresult;
734
735 int yyerrstatus;
736
737 int yychar1 = 0;
738
739
740
741
742
743
744
745
746
747
748 short yyssa[YYINITDEPTH];
749 short *yyss = yyssa;
750 register short *yyssp;
751
752
753 YYSTYPE yyvsa[YYINITDEPTH];
754 YYSTYPE *yyvs = yyvsa;
755 register YYSTYPE *yyvsp;
756
757 #if YYLSP_NEEDED
758
759 YYLTYPE yylsa[YYINITDEPTH];
760 YYLTYPE *yyls = yylsa;
761 YYLTYPE *yylsp;
762 #endif
763
764 #if YYLSP_NEEDED
765 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
766 #else
767 # define YYPOPSTACK (yyvsp--, yyssp--)
768 #endif
769
770 YYSIZE_T yystacksize = YYINITDEPTH;
771
772
773
774
775 YYSTYPE yyval;
776 #if YYLSP_NEEDED
777 YYLTYPE yyloc;
778 #endif
779
780
781
782 int yylen;
783
784 YYDPRINTF ((stderr, "Starting parse\n"));
785
786 yystate = 0;
787 yyerrstatus = 0;
788 yynerrs = 0;
789 yychar = YYEMPTY;
790
791
792
793
794
795
796 yyssp = yyss;
797 yyvsp = yyvs;
798 #if YYLSP_NEEDED
799 yylsp = yyls;
800 #endif
801 goto yysetstate;
802
803
804
805
806 yynewstate:
807
808
809
810 yyssp++;
811
812 yysetstate:
813 *yyssp = yystate;
814
815 if (yyssp >= yyss + yystacksize - 1)
816 {
817
818 YYSIZE_T yysize = yyssp - yyss + 1;
819
820 #ifdef yyoverflow
821 {
822
823
824
825 YYSTYPE *yyvs1 = yyvs;
826 short *yyss1 = yyss;
827
828
829
830 # if YYLSP_NEEDED
831 YYLTYPE *yyls1 = yyls;
832
833
834 yyoverflow ("parser stack overflow",
835 &yyss1, yysize * sizeof (*yyssp),
836 &yyvs1, yysize * sizeof (*yyvsp),
837 &yyls1, yysize * sizeof (*yylsp),
838 &yystacksize);
839 yyls = yyls1;
840 # else
841 yyoverflow ("parser stack overflow",
842 &yyss1, yysize * sizeof (*yyssp),
843 &yyvs1, yysize * sizeof (*yyvsp),
844 &yystacksize);
845 # endif
846 yyss = yyss1;
847 yyvs = yyvs1;
848 }
849 #else
850
851 if (yystacksize >= YYMAXDEPTH)
852 goto yyoverflowlab;
853 yystacksize *= 2;
854 if (yystacksize > YYMAXDEPTH)
855 yystacksize = YYMAXDEPTH;
856
857 {
858 short *yyss1 = yyss;
859 union yyalloc *yyptr =
860 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
861 if (! yyptr)
862 goto yyoverflowlab;
863 YYSTACK_RELOCATE (short, yyss);
864 YYSTACK_RELOCATE (YYSTYPE, yyvs);
865 # if YYLSP_NEEDED
866 YYSTACK_RELOCATE (YYLTYPE, yyls);
867 # endif
868 # undef YYSTACK_RELOCATE
869 if (yyss1 != yyssa)
870 YYSTACK_FREE (yyss1);
871 }
872 #endif
873
874 yyssp = yyss + yysize - 1;
875 yyvsp = yyvs + yysize - 1;
876 #if YYLSP_NEEDED
877 yylsp = yyls + yysize - 1;
878 #endif
879
880 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
881 (unsigned long int) yystacksize));
882
883 if (yyssp >= yyss + yystacksize - 1)
884 YYABORT;
885 }
886
887 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
888
889 goto yybackup;
890
891
892
893
894
895 yybackup:
896
897
898
899
900
901
902
903 yyn = yypact[yystate];
904 if (yyn == YYFLAG)
905 goto yydefault;
906
907
908
909
910
911
912 if (yychar == YYEMPTY)
913 {
914 YYDPRINTF ((stderr, "Reading a token: "));
915 yychar = YYLEX;
916 }
917
918
919
920 if (yychar <= 0)
921 {
922 yychar1 = 0;
923 yychar = YYEOF;
924
925 YYDPRINTF ((stderr, "Now at end of input.\n"));
926 }
927 else
928 {
929 yychar1 = YYTRANSLATE (yychar);
930
931 #if YYDEBUG
932
933
934 if (yydebug)
935 {
936 YYFPRINTF (stderr, "Next token is %d (%s",
937 yychar, yytname[yychar1]);
938
939
940 # ifdef YYPRINT
941 YYPRINT (stderr, yychar, yylval);
942 # endif
943 YYFPRINTF (stderr, ")\n");
944 }
945 #endif
946 }
947
948 yyn += yychar1;
949 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
950 goto yydefault;
951
952 yyn = yytable[yyn];
953
954
955
956
957
958
959
960
961 if (yyn < 0)
962 {
963 if (yyn == YYFLAG)
964 goto yyerrlab;
965 yyn = -yyn;
966 goto yyreduce;
967 }
968 else if (yyn == 0)
969 goto yyerrlab;
970
971 if (yyn == YYFINAL)
972 YYACCEPT;
973
974
975 YYDPRINTF ((stderr, "Shifting token %d (%s), ",
976 yychar, yytname[yychar1]));
977
978
979 if (yychar != YYEOF)
980 yychar = YYEMPTY;
981
982 *++yyvsp = yylval;
983 #if YYLSP_NEEDED
984 *++yylsp = yylloc;
985 #endif
986
987
988
989 if (yyerrstatus)
990 yyerrstatus--;
991
992 yystate = yyn;
993 goto yynewstate;
994
995
996
997
998
999 yydefault:
1000 yyn = yydefact[yystate];
1001 if (yyn == 0)
1002 goto yyerrlab;
1003 goto yyreduce;
1004
1005
1006
1007
1008
1009 yyreduce:
1010
1011 yylen = yyr2[yyn];
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021 yyval = yyvsp[1-yylen];
1022
1023 #if YYLSP_NEEDED
1024
1025
1026 yyloc = yylsp[1-yylen];
1027 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1028 #endif
1029
1030 #if YYDEBUG
1031
1032
1033 if (yydebug)
1034 {
1035 int yyi;
1036
1037 YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
1038 yyn, yyrline[yyn]);
1039
1040
1041 for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
1042 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
1043 YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1044 }
1045 #endif
1046
1047 switch (yyn) {
1048
1049 case 1:
1050 #line 144 "y-src/cccp.y"
1051 { expression_value = yyvsp[0].integer.value; }
1052 break;
1053 case 3:
1054 #line 150 "y-src/cccp.y"
1055 { if (pedantic)
1056 pedwarn ("comma operator in operand of `#if'");
1057 yyval.integer = yyvsp[0].integer; }
1058 break;
1059 case 4:
1060 #line 157 "y-src/cccp.y"
1061 { yyval.integer.value = - yyvsp[0].integer.value;
1062 if ((yyval.integer.value & yyvsp[0].integer.value) < 0 && ! yyvsp[0].integer.unsignedp)
1063 integer_overflow ();
1064 yyval.integer.unsignedp = yyvsp[0].integer.unsignedp; }
1065 break;
1066 case 5:
1067 #line 162 "y-src/cccp.y"
1068 { yyval.integer.value = ! yyvsp[0].integer.value;
1069 yyval.integer.unsignedp = 0; }
1070 break;
1071 case 6:
1072 #line 165 "y-src/cccp.y"
1073 { yyval.integer = yyvsp[0].integer; }
1074 break;
1075 case 7:
1076 #line 167 "y-src/cccp.y"
1077 { yyval.integer.value = ~ yyvsp[0].integer.value;
1078 yyval.integer.unsignedp = yyvsp[0].integer.unsignedp; }
1079 break;
1080 case 8:
1081 #line 170 "y-src/cccp.y"
1082 { yyval.integer.value = check_assertion (yyvsp[0].name.address, yyvsp[0].name.length,
1083 0, NULL_PTR);
1084 yyval.integer.unsignedp = 0; }
1085 break;
1086 case 9:
1087 #line 174 "y-src/cccp.y"
1088 { keyword_parsing = 1; }
1089 break;
1090 case 10:
1091 #line 176 "y-src/cccp.y"
1092 { yyval.integer.value = check_assertion (yyvsp[-4].name.address, yyvsp[-4].name.length,
1093 1, yyvsp[-1].keywords);
1094 keyword_parsing = 0;
1095 yyval.integer.unsignedp = 0; }
1096 break;
1097 case 11:
1098 #line 181 "y-src/cccp.y"
1099 { yyval.integer = yyvsp[-1].integer; }
1100 break;
1101 case 12:
1102 #line 186 "y-src/cccp.y"
1103 { yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
1104 if (yyval.integer.unsignedp)
1105 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value * yyvsp[0].integer.value;
1106 else
1107 {
1108 yyval.integer.value = yyvsp[-2].integer.value * yyvsp[0].integer.value;
1109 if (yyvsp[-2].integer.value
1110 && (yyval.integer.value / yyvsp[-2].integer.value != yyvsp[0].integer.value
1111 || (yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0))
1112 integer_overflow ();
1113 } }
1114 break;
1115 case 13:
1116 #line 198 "y-src/cccp.y"
1117 { if (yyvsp[0].integer.value == 0)
1118 {
1119 error ("division by zero in #if");
1120 yyvsp[0].integer.value = 1;
1121 }
1122 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
1123 if (yyval.integer.unsignedp)
1124 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value / yyvsp[0].integer.value;
1125 else
1126 {
1127 yyval.integer.value = yyvsp[-2].integer.value / yyvsp[0].integer.value;
1128 if ((yyval.integer.value & yyvsp[-2].integer.value & yyvsp[0].integer.value) < 0)
1129 integer_overflow ();
1130 } }
1131 break;
1132 case 14:
1133 #line 213 "y-src/cccp.y"
1134 { if (yyvsp[0].integer.value == 0)
1135 {
1136 error ("division by zero in #if");
1137 yyvsp[0].integer.value = 1;
1138 }
1139 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
1140 if (yyval.integer.unsignedp)
1141 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value % yyvsp[0].integer.value;
1142 else
1143 yyval.integer.value = yyvsp[-2].integer.value % yyvsp[0].integer.value; }
1144 break;
1145 case 15:
1146 #line 224 "y-src/cccp.y"
1147 { yyval.integer.value = yyvsp[-2].integer.value + yyvsp[0].integer.value;
1148 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
1149 if (! yyval.integer.unsignedp
1150 && ! possible_sum_sign (yyvsp[-2].integer.value, yyvsp[0].integer.value,
1151 yyval.integer.value))
1152 integer_overflow (); }
1153 break;
1154 case 16:
1155 #line 231 "y-src/cccp.y"
1156 { yyval.integer.value = yyvsp[-2].integer.value - yyvsp[0].integer.value;
1157 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp;
1158 if (! yyval.integer.unsignedp
1159 && ! possible_sum_sign (yyval.integer.value, yyvsp[0].integer.value,
1160 yyvsp[-2].integer.value))
1161 integer_overflow (); }
1162 break;
1163 case 17:
1164 #line 238 "y-src/cccp.y"
1165 { yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp;
1166 if (yyvsp[0].integer.value < 0 && ! yyvsp[0].integer.unsignedp)
1167 yyval.integer.value = right_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
1168 else
1169 yyval.integer.value = left_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); }
1170 break;
1171 case 18:
1172 #line 244 "y-src/cccp.y"
1173 { yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp;
1174 if (yyvsp[0].integer.value < 0 && ! yyvsp[0].integer.unsignedp)
1175 yyval.integer.value = left_shift (&yyvsp[-2].integer, -yyvsp[0].integer.value);
1176 else
1177 yyval.integer.value = right_shift (&yyvsp[-2].integer, yyvsp[0].integer.value); }
1178 break;
1179 case 19:
1180 #line 250 "y-src/cccp.y"
1181 { yyval.integer.value = (yyvsp[-2].integer.value == yyvsp[0].integer.value);
1182 yyval.integer.unsignedp = 0; }
1183 break;
1184 case 20:
1185 #line 253 "y-src/cccp.y"
1186 { yyval.integer.value = (yyvsp[-2].integer.value != yyvsp[0].integer.value);
1187 yyval.integer.unsignedp = 0; }
1188 break;
1189 case 21:
1190 #line 256 "y-src/cccp.y"
1191 { yyval.integer.unsignedp = 0;
1192 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
1193 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value <= yyvsp[0].integer.value;
1194 else
1195 yyval.integer.value = yyvsp[-2].integer.value <= yyvsp[0].integer.value; }
1196 break;
1197 case 22:
1198 #line 262 "y-src/cccp.y"
1199 { yyval.integer.unsignedp = 0;
1200 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
1201 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value >= yyvsp[0].integer.value;
1202 else
1203 yyval.integer.value = yyvsp[-2].integer.value >= yyvsp[0].integer.value; }
1204 break;
1205 case 23:
1206 #line 268 "y-src/cccp.y"
1207 { yyval.integer.unsignedp = 0;
1208 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
1209 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value < yyvsp[0].integer.value;
1210 else
1211 yyval.integer.value = yyvsp[-2].integer.value < yyvsp[0].integer.value; }
1212 break;
1213 case 24:
1214 #line 274 "y-src/cccp.y"
1215 { yyval.integer.unsignedp = 0;
1216 if (yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp)
1217 yyval.integer.value = (unsigned long) yyvsp[-2].integer.value > yyvsp[0].integer.value;
1218 else
1219 yyval.integer.value = yyvsp[-2].integer.value > yyvsp[0].integer.value; }
1220 break;
1221 case 25:
1222 #line 280 "y-src/cccp.y"
1223 { yyval.integer.value = yyvsp[-2].integer.value & yyvsp[0].integer.value;
1224 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; }
1225 break;
1226 case 26:
1227 #line 283 "y-src/cccp.y"
1228 { yyval.integer.value = yyvsp[-2].integer.value ^ yyvsp[0].integer.value;
1229 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; }
1230 break;
1231 case 27:
1232 #line 286 "y-src/cccp.y"
1233 { yyval.integer.value = yyvsp[-2].integer.value | yyvsp[0].integer.value;
1234 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; }
1235 break;
1236 case 28:
1237 #line 289 "y-src/cccp.y"
1238 { yyval.integer.value = (yyvsp[-2].integer.value && yyvsp[0].integer.value);
1239 yyval.integer.unsignedp = 0; }
1240 break;
1241 case 29:
1242 #line 292 "y-src/cccp.y"
1243 { yyval.integer.value = (yyvsp[-2].integer.value || yyvsp[0].integer.value);
1244 yyval.integer.unsignedp = 0; }
1245 break;
1246 case 30:
1247 #line 295 "y-src/cccp.y"
1248 { yyval.integer.value = yyvsp[-4].integer.value ? yyvsp[-2].integer.value : yyvsp[0].integer.value;
1249 yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; }
1250 break;
1251 case 31:
1252 #line 298 "y-src/cccp.y"
1253 { yyval.integer = yylval.integer; }
1254 break;
1255 case 32:
1256 #line 300 "y-src/cccp.y"
1257 { yyval.integer = yylval.integer; }
1258 break;
1259 case 33:
1260 #line 302 "y-src/cccp.y"
1261 { yyval.integer.value = 0;
1262 yyval.integer.unsignedp = 0; }
1263 break;
1264 case 34:
1265 #line 307 "y-src/cccp.y"
1266 { yyval.keywords = 0; }
1267 break;
1268 case 35:
1269 #line 309 "y-src/cccp.y"
1270 { struct arglist *temp;
1271 yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1272 yyval.keywords->next = yyvsp[-2].keywords;
1273 yyval.keywords->name = (U_CHAR *) "(";
1274 yyval.keywords->length = 1;
1275 temp = yyval.keywords;
1276 while (temp != 0 && temp->next != 0)
1277 temp = temp->next;
1278 temp->next = (struct arglist *) xmalloc (sizeof (struct arglist));
1279 temp->next->next = yyvsp[0].keywords;
1280 temp->next->name = (U_CHAR *) ")";
1281 temp->next->length = 1; }
1282 break;
1283 case 36:
1284 #line 322 "y-src/cccp.y"
1285 { yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));
1286 yyval.keywords->name = yyvsp[-1].name.address;
1287 yyval.keywords->length = yyvsp[-1].name.length;
1288 yyval.keywords->next = yyvsp[0].keywords; }
1289 break;
1290 }
1291
1292 #line 727 "/usr/share/bison/bison.simple"
1293
1294
1295 yyvsp -= yylen;
1296 yyssp -= yylen;
1297 #if YYLSP_NEEDED
1298 yylsp -= yylen;
1299 #endif
1300
1301 #if YYDEBUG
1302 if (yydebug)
1303 {
1304 short *yyssp1 = yyss - 1;
1305 YYFPRINTF (stderr, "state stack now");
1306 while (yyssp1 != yyssp)
1307 YYFPRINTF (stderr, " %d", *++yyssp1);
1308 YYFPRINTF (stderr, "\n");
1309 }
1310 #endif
1311
1312 *++yyvsp = yyval;
1313 #if YYLSP_NEEDED
1314 *++yylsp = yyloc;
1315 #endif
1316
1317
1318
1319
1320
1321 yyn = yyr1[yyn];
1322
1323 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1324 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1325 yystate = yytable[yystate];
1326 else
1327 yystate = yydefgoto[yyn - YYNTBASE];
1328
1329 goto yynewstate;
1330
1331
1332
1333
1334
1335 yyerrlab:
1336
1337 if (!yyerrstatus)
1338 {
1339 ++yynerrs;
1340
1341 #ifdef YYERROR_VERBOSE
1342 yyn = yypact[yystate];
1343
1344 if (yyn > YYFLAG && yyn < YYLAST)
1345 {
1346 YYSIZE_T yysize = 0;
1347 char *yymsg;
1348 int yyx, yycount;
1349
1350 yycount = 0;
1351
1352
1353 for (yyx = yyn < 0 ? -yyn : 0;
1354 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1355 if (yycheck[yyx + yyn] == yyx)
1356 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1357 yysize += yystrlen ("parse error, unexpected ") + 1;
1358 yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
1359 yymsg = (char *) YYSTACK_ALLOC (yysize);
1360 if (yymsg != 0)
1361 {
1362 char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
1363 yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
1364
1365 if (yycount < 5)
1366 {
1367 yycount = 0;
1368 for (yyx = yyn < 0 ? -yyn : 0;
1369 yyx < (int) (sizeof (yytname) / sizeof (char *));
1370 yyx++)
1371 if (yycheck[yyx + yyn] == yyx)
1372 {
1373 const char *yyq = ! yycount ? ", expecting " : " or ";
1374 yyp = yystpcpy (yyp, yyq);
1375 yyp = yystpcpy (yyp, yytname[yyx]);
1376 yycount++;
1377 }
1378 }
1379 yyerror (yymsg);
1380 YYSTACK_FREE (yymsg);
1381 }
1382 else
1383 yyerror ("parse error; also virtual memory exhausted");
1384 }
1385 else
1386 #endif
1387 yyerror ("parse error");
1388 }
1389 goto yyerrlab1;
1390
1391
1392
1393
1394
1395 yyerrlab1:
1396 if (yyerrstatus == 3)
1397 {
1398
1399
1400
1401
1402 if (yychar == YYEOF)
1403 YYABORT;
1404 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
1405 yychar, yytname[yychar1]));
1406 yychar = YYEMPTY;
1407 }
1408
1409
1410
1411
1412 yyerrstatus = 3;
1413
1414 goto yyerrhandle;
1415
1416
1417
1418
1419
1420
1421 yyerrdefault:
1422 #if 0
1423
1424
1425
1426
1427 yyn = yydefact[yystate];
1428 if (yyn)
1429 goto yydefault;
1430 #endif
1431
1432
1433
1434
1435
1436
1437 yyerrpop:
1438 if (yyssp == yyss)
1439 YYABORT;
1440 yyvsp--;
1441 yystate = *--yyssp;
1442 #if YYLSP_NEEDED
1443 yylsp--;
1444 #endif
1445
1446 #if YYDEBUG
1447 if (yydebug)
1448 {
1449 short *yyssp1 = yyss - 1;
1450 YYFPRINTF (stderr, "Error: state stack now");
1451 while (yyssp1 != yyssp)
1452 YYFPRINTF (stderr, " %d", *++yyssp1);
1453 YYFPRINTF (stderr, "\n");
1454 }
1455 #endif
1456
1457
1458
1459
1460 yyerrhandle:
1461 yyn = yypact[yystate];
1462 if (yyn == YYFLAG)
1463 goto yyerrdefault;
1464
1465 yyn += YYTERROR;
1466 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1467 goto yyerrdefault;
1468
1469 yyn = yytable[yyn];
1470 if (yyn < 0)
1471 {
1472 if (yyn == YYFLAG)
1473 goto yyerrpop;
1474 yyn = -yyn;
1475 goto yyreduce;
1476 }
1477 else if (yyn == 0)
1478 goto yyerrpop;
1479
1480 if (yyn == YYFINAL)
1481 YYACCEPT;
1482
1483 YYDPRINTF ((stderr, "Shifting error token, "));
1484
1485 *++yyvsp = yylval;
1486 #if YYLSP_NEEDED
1487 *++yylsp = yylloc;
1488 #endif
1489
1490 yystate = yyn;
1491 goto yynewstate;
1492
1493
1494
1495
1496
1497 yyacceptlab:
1498 yyresult = 0;
1499 goto yyreturn;
1500
1501
1502
1503
1504 yyabortlab:
1505 yyresult = 1;
1506 goto yyreturn;
1507
1508
1509
1510
1511 yyoverflowlab:
1512 yyerror ("parser stack overflow");
1513 yyresult = 2;
1514
1515
1516 yyreturn:
1517 #ifndef yyoverflow
1518 if (yyss != yyssa)
1519 YYSTACK_FREE (yyss);
1520 #endif
1521 return yyresult;
1522 }
1523 #line 327 "y-src/cccp.y"
1524
1525
1526
1527
1528
1529 static char *lexptr;
1530
1531
1532
1533
1534
1535
1536
1537 int
1538 parse_number (olen)
1539 int olen;
1540 {
1541 register char *p = lexptr;
1542 register int c;
1543 register unsigned long n = 0, nd, ULONG_MAX_over_base;
1544 register int base = 10;
1545 register int len = olen;
1546 register int overflow = 0;
1547 register int digit, largest_digit = 0;
1548 int spec_long = 0;
1549
1550 for (c = 0; c < len; c++)
1551 if (p[c] == '.') {
1552
1553 yyerror ("floating point numbers not allowed in #if expressions");
1554 return ERROR;
1555 }
1556
1557 yylval.integer.unsignedp = 0;
1558
1559 if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) {
1560 p += 2;
1561 base = 16;
1562 len -= 2;
1563 }
1564 else if (*p == '0')
1565 base = 8;
1566
1567 ULONG_MAX_over_base = (unsigned long) -1 / base;
1568
1569 for (; len > 0; len--) {
1570 c = *p++;
1571
1572 if (c >= '0' && c <= '9')
1573 digit = c - '0';
1574 else if (base == 16 && c >= 'a' && c <= 'f')
1575 digit = c - 'a' + 10;
1576 else if (base == 16 && c >= 'A' && c <= 'F')
1577 digit = c - 'A' + 10;
1578 else {
1579
1580 while (1) {
1581 if (c == 'l' || c == 'L')
1582 {
1583 if (spec_long)
1584 yyerror ("two `l's in integer constant");
1585 spec_long = 1;
1586 }
1587 else if (c == 'u' || c == 'U')
1588 {
1589 if (yylval.integer.unsignedp)
1590 yyerror ("two `u's in integer constant");
1591 yylval.integer.unsignedp = 1;
1592 }
1593 else
1594 break;
1595
1596 if (--len == 0)
1597 break;
1598 c = *p++;
1599 }
1600
1601 break;
1602 }
1603 if (largest_digit < digit)
1604 largest_digit = digit;
1605 nd = n * base + digit;
1606 overflow |= ULONG_MAX_over_base < n | nd < n;
1607 n = nd;
1608 }
1609
1610 if (len != 0) {
1611 yyerror ("Invalid number in #if expression");
1612 return ERROR;
1613 }
1614
1615 if (base <= largest_digit)
1616 warning ("integer constant contains digits beyond the radix");
1617
1618 if (overflow)
1619 warning ("integer constant out of range");
1620
1621
1622 if ((long) n < 0 && ! yylval.integer.unsignedp)
1623 {
1624 if (base == 10)
1625 warning ("integer constant is so large that it is unsigned");
1626 yylval.integer.unsignedp = 1;
1627 }
1628
1629 lexptr = p;
1630 yylval.integer.value = n;
1631 return INT;
1632 }
1633
1634 struct token {
1635 char *operator;
1636 int token;
1637 };
1638
1639 static struct token tokentab2[] = {
1640 {"&&", AND},
1641 {"||", OR},
1642 {"<<", LSH},
1643 {">>", RSH},
1644 {"==", EQUAL},
1645 {"!=", NOTEQUAL},
1646 {"<=", LEQ},
1647 {">=", GEQ},
1648 {"++", ERROR},
1649 {"--", ERROR},
1650 {NULL, ERROR}
1651 };
1652
1653
1654
1655 int
1656 yylex ()
1657 {
1658 register int c;
1659 register int namelen;
1660 register unsigned char *tokstart;
1661 register struct token *toktab;
1662 int wide_flag;
1663
1664 retry:
1665
1666 tokstart = (unsigned char *) lexptr;
1667 c = *tokstart;
1668
1669 if (! keyword_parsing)
1670 for (toktab = tokentab2; toktab->operator != NULL; toktab++)
1671 if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) {
1672 lexptr += 2;
1673 if (toktab->token == ERROR)
1674 {
1675 char *buf = (char *) alloca (40);
1676 sprintf (buf, "`%s' not allowed in operand of `#if'", toktab->operator);
1677 yyerror (buf);
1678 }
1679 return toktab->token;
1680 }
1681
1682 switch (c) {
1683 case 0:
1684 return 0;
1685
1686 case ' ':
1687 case '\t':
1688 case '\r':
1689 case '\n':
1690 lexptr++;
1691 goto retry;
1692
1693 case 'L':
1694
1695 if (lexptr[1] == '\'')
1696 {
1697 lexptr++;
1698 wide_flag = 1;
1699 goto char_constant;
1700 }
1701 if (lexptr[1] == '"')
1702 {
1703 lexptr++;
1704 wide_flag = 1;
1705 goto string_constant;
1706 }
1707 break;
1708
1709 case '\'':
1710 wide_flag = 0;
1711 char_constant:
1712 lexptr++;
1713 if (keyword_parsing) {
1714 char *start_ptr = lexptr - 1;
1715 while (1) {
1716 c = *lexptr++;
1717 if (c == '\\')
1718 c = parse_escape (&lexptr);
1719 else if (c == '\'')
1720 break;
1721 }
1722 yylval.name.address = tokstart;
1723 yylval.name.length = lexptr - start_ptr;
1724 return NAME;
1725 }
1726
1727
1728
1729
1730 {
1731 register int result = 0;
1732 register num_chars = 0;
1733 unsigned width = CHAR_TYPE_SIZE;
1734 int max_chars;
1735 char *token_buffer;
1736
1737 if (wide_flag)
1738 {
1739 width = WCHAR_TYPE_SIZE;
1740 #ifdef MULTIBYTE_CHARS
1741 max_chars = MB_CUR_MAX;
1742 #else
1743 max_chars = 1;
1744 #endif
1745 }
1746 else
1747 max_chars = LONG_TYPE_SIZE / width;
1748
1749 token_buffer = (char *) alloca (max_chars + 1);
1750
1751 while (1)
1752 {
1753 c = *lexptr++;
1754
1755 if (c == '\'' || c == EOF)
1756 break;
1757
1758 if (c == '\\')
1759 {
1760 c = parse_escape (&lexptr);
1761 if (width < HOST_BITS_PER_INT
1762 && (unsigned) c >= (1 << width))
1763 pedwarn ("escape sequence out of range for character");
1764 }
1765
1766 num_chars++;
1767
1768
1769 if (num_chars < max_chars + 1)
1770 {
1771 if (width < HOST_BITS_PER_INT)
1772 result = (result << width) | (c & ((1 << width) - 1));
1773 else
1774 result = c;
1775 token_buffer[num_chars - 1] = c;
1776 }
1777 }
1778
1779 token_buffer[num_chars] = 0;
1780
1781 if (c != '\'')
1782 error ("malformatted character constant");
1783 else if (num_chars == 0)
1784 error ("empty character constant");
1785 else if (num_chars > max_chars)
1786 {
1787 num_chars = max_chars;
1788 error ("character constant too long");
1789 }
1790 else if (num_chars != 1 && ! traditional)
1791 warning ("multi-character character constant");
1792
1793
1794 if (! wide_flag)
1795 {
1796 int num_bits = num_chars * width;
1797
1798 if (lookup ("__CHAR_UNSIGNED__", sizeof ("__CHAR_UNSIGNED__")-1, -1)
1799 || ((result >> (num_bits - 1)) & 1) == 0)
1800 yylval.integer.value
1801 = result & ((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits));
1802 else
1803 yylval.integer.value
1804 = result | ~((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits));
1805 }
1806 else
1807 {
1808 #ifdef MULTIBYTE_CHARS
1809
1810 result = 0;
1811
1812
1813 if (num_chars > 1
1814 || (num_chars == 1 && token_buffer[0] != '\0'))
1815 {
1816 wchar_t wc;
1817 (void) mbtowc (NULL_PTR, NULL_PTR, 0);
1818 if (mbtowc (& wc, token_buffer, num_chars) == num_chars)
1819 result = wc;
1820 else
1821 warning ("Ignoring invalid multibyte character");
1822 }
1823 #endif
1824 yylval.integer.value = result;
1825 }
1826 }
1827
1828
1829 yylval.integer.unsignedp = 0;
1830
1831 return CHAR;
1832
1833
1834
1835 case '/':
1836 case '+':
1837 case '-':
1838 case '*':
1839 case '%':
1840 case '|':
1841 case '&':
1842 case '^':
1843 case '~':
1844 case '!':
1845 case '@':
1846 case '<':
1847 case '>':
1848 case '[':
1849 case ']':
1850 case '.':
1851 case '?':
1852 case ':':
1853 case '=':
1854 case '{':
1855 case '}':
1856 case ',':
1857 case '#':
1858 if (keyword_parsing)
1859 break;
1860 case '(':
1861 case ')':
1862 lexptr++;
1863 return c;
1864
1865 case '"':
1866 string_constant:
1867 if (keyword_parsing) {
1868 char *start_ptr = lexptr;
1869 lexptr++;
1870 while (1) {
1871 c = *lexptr++;
1872 if (c == '\\')
1873 c = parse_escape (&lexptr);
1874 else if (c == '"')
1875 break;
1876 }
1877 yylval.name.address = tokstart;
1878 yylval.name.length = lexptr - start_ptr;
1879 return NAME;
1880 }
1881 yyerror ("string constants not allowed in #if expressions");
1882 return ERROR;
1883 }
1884
1885 if (c >= '0' && c <= '9' && !keyword_parsing) {
1886
1887 for (namelen = 0;
1888 c = tokstart[namelen], is_idchar[c] || c == '.';
1889 namelen++)
1890 ;
1891 return parse_number (namelen);
1892 }
1893
1894
1895
1896 if (keyword_parsing) {
1897 for (namelen = 0;; namelen++) {
1898 if (is_hor_space[tokstart[namelen]])
1899 break;
1900 if (tokstart[namelen] == '(' || tokstart[namelen] == ')')
1901 break;
1902 if (tokstart[namelen] == '"' || tokstart[namelen] == '\'')
1903 break;
1904 }
1905 } else {
1906 if (!is_idstart[c]) {
1907 yyerror ("Invalid token in expression");
1908 return ERROR;
1909 }
1910
1911 for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
1912 ;
1913 }
1914
1915 lexptr += namelen;
1916 yylval.name.address = tokstart;
1917 yylval.name.length = namelen;
1918 return NAME;
1919 }
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936 int
1937 parse_escape (string_ptr)
1938 char **string_ptr;
1939 {
1940 register int c = *(*string_ptr)++;
1941 switch (c)
1942 {
1943 case 'a':
1944 return TARGET_BELL;
1945 case 'b':
1946 return TARGET_BS;
1947 case 'e':
1948 case 'E':
1949 if (pedantic)
1950 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
1951 return 033;
1952 case 'f':
1953 return TARGET_FF;
1954 case 'n':
1955 return TARGET_NEWLINE;
1956 case 'r':
1957 return TARGET_CR;
1958 case 't':
1959 return TARGET_TAB;
1960 case 'v':
1961 return TARGET_VT;
1962 case '\n':
1963 return -2;
1964 case 0:
1965 (*string_ptr)--;
1966 return 0;
1967
1968 case '0':
1969 case '1':
1970 case '2':
1971 case '3':
1972 case '4':
1973 case '5':
1974 case '6':
1975 case '7':
1976 {
1977 register int i = c - '0';
1978 register int count = 0;
1979 while (++count < 3)
1980 {
1981 c = *(*string_ptr)++;
1982 if (c >= '0' && c <= '7')
1983 i = (i << 3) + c - '0';
1984 else
1985 {
1986 (*string_ptr)--;
1987 break;
1988 }
1989 }
1990 if ((i & ~((1 << CHAR_TYPE_SIZE) - 1)) != 0)
1991 {
1992 i &= (1 << CHAR_TYPE_SIZE) - 1;
1993 warning ("octal character constant does not fit in a byte");
1994 }
1995 return i;
1996 }
1997 case 'x':
1998 {
1999 register unsigned i = 0, overflow = 0, digits_found = 0, digit;
2000 for (;;)
2001 {
2002 c = *(*string_ptr)++;
2003 if (c >= '0' && c <= '9')
2004 digit = c - '0';
2005 else if (c >= 'a' && c <= 'f')
2006 digit = c - 'a' + 10;
2007 else if (c >= 'A' && c <= 'F')
2008 digit = c - 'A' + 10;
2009 else
2010 {
2011 (*string_ptr)--;
2012 break;
2013 }
2014 overflow |= i ^ (i << 4 >> 4);
2015 i = (i << 4) + digit;
2016 digits_found = 1;
2017 }
2018 if (!digits_found)
2019 yyerror ("\\x used with no following hex digits");
2020 if (overflow | (i & ~((1 << BITS_PER_UNIT) - 1)))
2021 {
2022 i &= (1 << BITS_PER_UNIT) - 1;
2023 warning ("hex character constant does not fit in a byte");
2024 }
2025 return i;
2026 }
2027 default:
2028 return c;
2029 }
2030 }
2031
2032 void
2033 yyerror (s)
2034 char *s;
2035 {
2036 error (s);
2037 longjmp (parse_return_error, 1);
2038 }
2039
2040 static void
2041 integer_overflow ()
2042 {
2043 if (pedantic)
2044 pedwarn ("integer overflow in preprocessor expression");
2045 }
2046
2047 static long
2048 left_shift (a, b)
2049 struct constant *a;
2050 unsigned long b;
2051 {
2052 if (b >= HOST_BITS_PER_LONG)
2053 {
2054 if (! a->unsignedp && a->value != 0)
2055 integer_overflow ();
2056 return 0;
2057 }
2058 else if (a->unsignedp)
2059 return (unsigned long) a->value << b;
2060 else
2061 {
2062 long l = a->value << b;
2063 if (l >> b != a->value)
2064 integer_overflow ();
2065 return l;
2066 }
2067 }
2068
2069 static long
2070 right_shift (a, b)
2071 struct constant *a;
2072 unsigned long b;
2073 {
2074 if (b >= HOST_BITS_PER_LONG)
2075 return a->unsignedp ? 0 : a->value >> (HOST_BITS_PER_LONG - 1);
2076 else if (a->unsignedp)
2077 return (unsigned long) a->value >> b;
2078 else
2079 return a->value >> b;
2080 }
2081
2082
2083
2084
2085
2086
2087
2088
2089 int
2090 parse_c_expression (string)
2091 char *string;
2092 {
2093 lexptr = string;
2094
2095 if (lexptr == 0 || *lexptr == 0) {
2096 error ("empty #if expression");
2097 return 0;
2098 }
2099
2100
2101
2102
2103 if (setjmp (parse_return_error))
2104 return 0;
2105
2106 if (yyparse ())
2107 return 0;
2108
2109 if (*lexptr)
2110 error ("Junk after end of expression.");
2111
2112 return expression_value;
2113 }
2114
2115 #ifdef TEST_EXP_READER
2116 extern int yydebug;
2117
2118
2119 int
2120 main ()
2121 {
2122 int n, c;
2123 char buf[1024];
2124
2125
2126
2127
2128 initialize_random_junk ();
2129
2130 for (;;) {
2131 printf ("enter expression: ");
2132 n = 0;
2133 while ((buf[n] = getchar ()) != '\n' && buf[n] != EOF)
2134 n++;
2135 if (buf[n] == EOF)
2136 break;
2137 buf[n] = '\0';
2138 printf ("parser returned %d\n", parse_c_expression (buf));
2139 }
2140
2141 return 0;
2142 }
2143
2144
2145 unsigned char is_idchar[256];
2146
2147 unsigned char is_idstart[256];
2148
2149
2150 char is_hor_space[256];
2151
2152
2153
2154
2155 initialize_random_junk ()
2156 {
2157 register int i;
2158
2159
2160
2161
2162
2163
2164
2165 for (i = 'a'; i <= 'z'; i++) {
2166 ++is_idchar[i - 'a' + 'A'];
2167 ++is_idchar[i];
2168 ++is_idstart[i - 'a' + 'A'];
2169 ++is_idstart[i];
2170 }
2171 for (i = '0'; i <= '9'; i++)
2172 ++is_idchar[i];
2173 ++is_idchar['_'];
2174 ++is_idstart['_'];
2175 #if DOLLARS_IN_IDENTIFIERS
2176 ++is_idchar['$'];
2177 ++is_idstart['$'];
2178 #endif
2179
2180
2181 ++is_hor_space[' '];
2182 ++is_hor_space['\t'];
2183 }
2184
2185 error (msg)
2186 {
2187 printf ("error: %s\n", msg);
2188 }
2189
2190 warning (msg)
2191 {
2192 printf ("warning: %s\n", msg);
2193 }
2194
2195 struct hashnode *
2196 lookup (name, len, hash)
2197 char *name;
2198 int len;
2199 int hash;
2200 {
2201 return (DEFAULT_SIGNED_CHAR) ? 0 : ((struct hashnode *) -1);
2202 }
2203 #endif