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