|
|
1.1 root 1:
2: /* A Bison parser, made from cexp.y */
3:
4: #define INT 258
5: #define CHAR 259
6: #define NAME 260
7: #define ERROR 261
8: #define OR 262
9: #define AND 263
10: #define EQUAL 264
11: #define NOTEQUAL 265
12: #define LEQ 266
13: #define GEQ 267
14: #define LSH 268
15: #define RSH 269
16: #define UNARY 270
17:
1.1.1.6 ! root 18: #line 26 "cexp.y"
1.1 root 19:
1.1.1.2 root 20: #include "config.h"
1.1 root 21: #include <setjmp.h>
22: /* #define YYDEBUG 1 */
23:
1.1.1.3 root 24: int yylex ();
25: void yyerror ();
1.1 root 26: int expression_value;
27:
28: static jmp_buf parse_return_error;
29:
30: /* some external tables of character types */
31: extern unsigned char is_idstart[], is_idchar[];
32:
33:
1.1.1.6 ! root 34: #line 42 "cexp.y"
1.1 root 35: typedef union {
36: long lval;
37: int voidval;
38: char *sval;
39: } YYSTYPE;
40:
41: #ifndef YYLTYPE
42: typedef
43: struct yyltype
1.1.1.6 ! root 44: {
1.1 root 45: int timestamp;
46: int first_line;
47: int first_column;
48: int last_line;
49: int last_column;
50: char *text;
51: }
1.1.1.6 ! root 52: yyltype;
1.1 root 53:
54: #define YYLTYPE yyltype
55: #endif
56:
57: #include <stdio.h>
58:
1.1.1.2 root 59: #ifndef __STDC__
60: #define const
61: #endif
62:
1.1 root 63:
64:
65: #define YYFINAL 59
66: #define YYFLAG -32768
67: #define YYNTBASE 33
68:
1.1.1.2 root 69: #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 36)
1.1 root 70:
1.1.1.2 root 71: static const char yytranslate[] = { 0,
1.1 root 72: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
73: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
74: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
75: 2, 2, 29, 2, 2, 2, 27, 14, 2, 31,
76: 32, 25, 23, 9, 24, 2, 26, 2, 2, 2,
77: 2, 2, 2, 2, 2, 2, 2, 8, 2, 17,
78: 2, 18, 7, 2, 2, 2, 2, 2, 2, 2,
79: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
80: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81: 2, 2, 2, 13, 2, 2, 2, 2, 2, 2,
82: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
83: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
84: 2, 2, 2, 12, 2, 30, 2, 2, 2, 2,
85: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
86: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
87: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
88: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
89: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
90: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
91: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
92: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
93: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
94: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
95: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
96: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
97: 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
98: 6, 10, 11, 15, 16, 19, 20, 21, 22, 28
99: };
100:
1.1.1.2 root 101: static const short yyrline[] = { 0,
1.1.1.6 ! root 102: 71, 76, 77, 82, 84, 86, 88, 93, 95, 102,
! 103: 109, 111, 113, 115, 117, 119, 121, 123, 125, 127,
! 104: 129, 131, 133, 135, 137, 139, 141, 143, 145
1.1 root 105: };
106:
1.1.1.2 root 107: static const char * const yytname[] = { 0,
1.1 root 108: "error","$illegal.","INT","CHAR","NAME","ERROR","'?'","':'","','","OR",
109: "AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'","'>'","LEQ","GEQ",
110: "LSH","RSH","'+'","'-'","'*'","'/'","'%'","UNARY","'!'","'~'",
111: "'('","')'","start"
112: };
113:
1.1.1.2 root 114: static const short yyr1[] = { 0,
1.1 root 115: 33, 34, 34, 35, 35, 35, 35, 35, 35, 35,
116: 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
117: 35, 35, 35, 35, 35, 35, 35, 35, 35
118: };
119:
1.1.1.2 root 120: static const short yyr2[] = { 0,
1.1 root 121: 1, 1, 3, 2, 2, 2, 3, 3, 3, 3,
122: 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123: 3, 3, 3, 3, 3, 5, 1, 1, 1
124: };
125:
1.1.1.2 root 126: static const short yydefact[] = { 0,
1.1 root 127: 27, 28, 29, 0, 0, 0, 0, 1, 2, 4,
128: 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
129: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130: 0, 0, 0, 7, 3, 0, 25, 24, 23, 22,
131: 21, 15, 16, 19, 20, 17, 18, 13, 14, 11,
132: 12, 8, 9, 10, 0, 26, 0, 0, 0
133: };
134:
1.1.1.2 root 135: static const short yydefgoto[] = { 57,
1.1 root 136: 8, 9
137: };
138:
1.1.1.2 root 139: static const short yypact[] = { 28,
1.1 root 140: -32768,-32768,-32768, 28, 28, 28, 28, -3, 74,-32768,
141: -32768,-32768, -2, 28, 28, 28, 28, 28, 28, 28,
142: 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
143: 28, 28, 28,-32768, 74, 53, 23, 90, 105, 119,
144: 132, 143, 143, 150, 150, 150, 150, 155, 155, -22,
145: -22,-32768,-32768,-32768, 28, 74, 8, 9,-32768
146: };
147:
1.1.1.2 root 148: static const short yypgoto[] = {-32768,
1.1 root 149: 46, -4
150: };
151:
152:
153: #define YYLAST 182
154:
155:
1.1.1.2 root 156: static const short yytable[] = { 10,
1.1 root 157: 11, 12, 31, 32, 33, 14, 14, 58, 59, 35,
158: 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
159: 46, 47, 48, 49, 50, 51, 52, 53, 54, 34,
160: 1, 2, 3, 17, 18, 19, 20, 21, 22, 23,
161: 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
162: 56, 4, 13, 0, 0, 0, 5, 6, 7, 15,
163: 55, 0, 16, 17, 18, 19, 20, 21, 22, 23,
164: 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
165: 15, 0, 0, 16, 17, 18, 19, 20, 21, 22,
166: 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
167: 33, 18, 19, 20, 21, 22, 23, 24, 25, 26,
168: 27, 28, 29, 30, 31, 32, 33, 19, 20, 21,
169: 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
170: 32, 33, 20, 21, 22, 23, 24, 25, 26, 27,
171: 28, 29, 30, 31, 32, 33, 21, 22, 23, 24,
172: 25, 26, 27, 28, 29, 30, 31, 32, 33, 23,
173: 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
174: 27, 28, 29, 30, 31, 32, 33, 29, 30, 31,
175: 32, 33
176: };
177:
1.1.1.2 root 178: static const short yycheck[] = { 4,
1.1 root 179: 5, 6, 25, 26, 27, 9, 9, 0, 0, 14,
180: 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
181: 25, 26, 27, 28, 29, 30, 31, 32, 33, 32,
182: 3, 4, 5, 11, 12, 13, 14, 15, 16, 17,
183: 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
184: 55, 24, 7, -1, -1, -1, 29, 30, 31, 7,
185: 8, -1, 10, 11, 12, 13, 14, 15, 16, 17,
186: 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
187: 7, -1, -1, 10, 11, 12, 13, 14, 15, 16,
188: 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
189: 27, 12, 13, 14, 15, 16, 17, 18, 19, 20,
190: 21, 22, 23, 24, 25, 26, 27, 13, 14, 15,
191: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
192: 26, 27, 14, 15, 16, 17, 18, 19, 20, 21,
193: 22, 23, 24, 25, 26, 27, 15, 16, 17, 18,
194: 19, 20, 21, 22, 23, 24, 25, 26, 27, 17,
195: 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
196: 21, 22, 23, 24, 25, 26, 27, 23, 24, 25,
197: 26, 27
198: };
199: #define YYPURE 1
200:
1.1.1.6 ! root 201: /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
! 202: #line 3 "bison.simple"
1.1 root 203:
204: /* Skeleton output parser for bison,
205: copyright (C) 1984 Bob Corbett and Richard Stallman
206:
1.1.1.2 root 207: NO WARRANTY
208:
209: BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
210: NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
211: WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
212: RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
213: WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
214: BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
215: FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
216: AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
217: DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
218: CORRECTION.
219:
220: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
221: STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
222: WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
223: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
224: OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
225: USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
226: DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
227: A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
228: PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
229: DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
230:
231: GENERAL PUBLIC LICENSE TO COPY
232:
233: 1. You may copy and distribute verbatim copies of this source file
234: as you receive it, in any medium, provided that you conspicuously and
235: appropriately publish on each copy a valid copyright notice "Copyright
236: (C) 1985 Free Software Foundation, Inc."; and include following the
237: copyright notice a verbatim copy of the above disclaimer of warranty
238: and of this License. You may charge a distribution fee for the
239: physical act of transferring a copy.
240:
241: 2. You may modify your copy or copies of this source file or
242: any portion of it, and copy and distribute such modifications under
243: the terms of Paragraph 1 above, provided that you also do the following:
244:
245: a) cause the modified files to carry prominent notices stating
246: that you changed the files and the date of any change; and
247:
248: b) cause the whole of any work that you distribute or publish,
249: that in whole or in part contains or is a derivative of this
250: program or any part thereof, to be licensed at no charge to all
251: third parties on terms identical to those contained in this
252: License Agreement (except that you may choose to grant more extensive
253: warranty protection to some or all third parties, at your option).
254:
255: c) You may charge a distribution fee for the physical act of
256: transferring a copy, and you may at your option offer warranty
257: protection in exchange for a fee.
258:
259: Mere aggregation of another unrelated program with this program (or its
260: derivative) on a volume of a storage or distribution medium does not bring
261: the other program under the scope of these terms.
262:
263: 3. You may copy and distribute this program (or a portion or derivative
264: of it, under Paragraph 2) in object code or executable form under the terms
265: of Paragraphs 1 and 2 above provided that you also do one of the following:
266:
267: a) accompany it with the complete corresponding machine-readable
268: source code, which must be distributed under the terms of
269: Paragraphs 1 and 2 above; or,
270:
271: b) accompany it with a written offer, valid for at least three
272: years, to give any third party free (except for a nominal
273: shipping charge) a complete machine-readable copy of the
274: corresponding source code, to be distributed under the terms of
275: Paragraphs 1 and 2 above; or,
276:
277: c) accompany it with the information you received as to where the
278: corresponding source code may be obtained. (This alternative is
279: allowed only for noncommercial distribution and only if you
280: received the program in object code or executable form alone.)
281:
282: For an executable file, complete source code means all the source code for
283: all modules it contains; but, as a special exception, it need not include
284: source code for modules which are standard libraries that accompany the
285: operating system on which the executable file runs.
286:
287: 4. You may not copy, sublicense, distribute or transfer this program
288: except as expressly provided under this License Agreement. Any attempt
289: otherwise to copy, sublicense, distribute or transfer this program is void and
290: your rights to use the program under this License agreement shall be
291: automatically terminated. However, parties who have received computer
292: software programs from you with this License Agreement will not have
293: their licenses terminated so long as such parties remain in full compliance.
294:
295: 5. If you wish to incorporate parts of this program into other free
296: programs whose distribution conditions are different, write to the Free
297: Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
298: worked out a simple rule that can be stated here, but we will often permit
299: this. We will be guided by the two goals of preserving the free status of
300: all derivatives of our free software and of promoting the sharing and reuse of
301: software.
302:
303:
304: In other words, you are welcome to use, share and improve this program.
305: You are forbidden to forbid anyone else to use, share and improve
306: what you give them. Help stamp out software-hoarding! */
1.1 root 307:
1.1.1.6 ! root 308: #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
! 309: #include <alloca.h>
! 310: #endif
! 311:
1.1 root 312: /* This is the parser code that is written into each bison parser
313: when the %semantic_parser declaration is not specified in the grammar.
314: It was written by Richard Stallman by simplifying the hairy parser
315: used when %semantic_parser is specified. */
316:
317: /* Note: there must be only one dollar sign in this file.
318: It is replaced by the list of actions, each action
319: as one case of the switch. */
320:
321: #define yyerrok (yyerrstatus = 0)
322: #define yyclearin (yychar = YYEMPTY)
323: #define YYEMPTY -2
324: #define YYEOF 0
325: #define YYFAIL goto yyerrlab;
1.1.1.6 ! root 326: #define YYACCEPT return(0)
! 327: #define YYABORT return(1)
! 328: #define YYERROR goto yyerrlab
1.1 root 329:
330: #define YYTERROR 1
331:
332: #ifndef YYIMPURE
333: #define YYLEX yylex()
334: #endif
335:
336: #ifndef YYPURE
337: #define YYLEX yylex(&yylval, &yylloc)
338: #endif
339:
340: /* If nonreentrant, generate the variables here */
341:
342: #ifndef YYIMPURE
343:
344: int yychar; /* the lookahead symbol */
345: YYSTYPE yylval; /* the semantic value of the */
346: /* lookahead symbol */
347:
348: YYLTYPE yylloc; /* location data for the lookahead */
349: /* symbol */
350:
1.1.1.6 ! root 351: int yynerrs; /* number of parse errors so far */
1.1 root 352: #endif /* YYIMPURE */
353:
1.1.1.6 ! root 354: #if YYDEBUG != 0
! 355: int yydebug; /* nonzero means print parse trace */
! 356: /* Since this is uninitialized, it does not stop multiple parsers
! 357: from coexisting. */
! 358: #endif
1.1 root 359:
360: /* YYMAXDEPTH indicates the initial size of the parser's stacks */
361:
362: #ifndef YYMAXDEPTH
363: #define YYMAXDEPTH 200
364: #endif
365:
366: /* YYMAXLIMIT is the maximum size the stacks can grow to
367: (effective only if the built-in stack extension method is used). */
368:
369: #ifndef YYMAXLIMIT
370: #define YYMAXLIMIT 10000
371: #endif
372:
373:
1.1.1.6 ! root 374: #line 175 "bison.simple"
1.1 root 375: int
376: yyparse()
377: {
378: register int yystate;
379: register int yyn;
380: register short *yyssp;
381: register YYSTYPE *yyvsp;
382: YYLTYPE *yylsp;
383: int yyerrstatus; /* number of tokens to shift before error messages enabled */
384: int yychar1; /* lookahead token as an internal (translated) token number */
385:
386: short yyssa[YYMAXDEPTH]; /* the state stack */
387: YYSTYPE yyvsa[YYMAXDEPTH]; /* the semantic value stack */
388: YYLTYPE yylsa[YYMAXDEPTH]; /* the location stack */
389:
390: short *yyss = yyssa; /* refer to the stacks thru separate pointers */
391: YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
392: YYLTYPE *yyls = yylsa;
393:
394: int yymaxdepth = YYMAXDEPTH;
395:
396: #ifndef YYPURE
397: int yychar;
398: YYSTYPE yylval;
399: YYLTYPE yylloc;
1.1.1.6 ! root 400: int yynerrs;
1.1.1.2 root 401: #endif
1.1 root 402:
403: YYSTYPE yyval; /* the variable used to return */
404: /* semantic values from the action */
405: /* routines */
406:
407: int yylen;
408:
1.1.1.6 ! root 409: #if YYDEBUG != 0
1.1 root 410: if (yydebug)
411: fprintf(stderr, "Starting parse\n");
1.1.1.2 root 412: #endif
1.1 root 413:
414: yystate = 0;
415: yyerrstatus = 0;
1.1.1.6 ! root 416: yynerrs = 0;
1.1 root 417: yychar = YYEMPTY; /* Cause a token to be read. */
418:
419: /* Initialize stack pointers.
420: Waste one element of value and location stack
421: so that they stay on the same level as the state stack. */
422:
423: yyssp = yyss - 1;
424: yyvsp = yyvs;
425: yylsp = yyls;
426:
427: /* Push a new state, which is found in yystate . */
428: /* In all cases, when you get here, the value and location stacks
429: have just been pushed. so pushing a state here evens the stacks. */
430: yynewstate:
431:
432: *++yyssp = yystate;
433:
434: if (yyssp >= yyss + yymaxdepth - 1)
435: {
436: /* Give user a chance to reallocate the stack */
437: /* Use copies of these so that the &'s don't force the real ones into memory. */
438: YYSTYPE *yyvs1 = yyvs;
439: YYLTYPE *yyls1 = yyls;
440: short *yyss1 = yyss;
441:
442: /* Get the current used size of the three stacks, in elements. */
443: int size = yyssp - yyss + 1;
444:
445: #ifdef yyoverflow
446: /* Each stack pointer address is followed by the size of
447: the data in use in that stack, in bytes. */
448: yyoverflow("parser stack overflow",
449: &yyss1, size * sizeof (*yyssp),
450: &yyvs1, size * sizeof (*yyvsp),
451: &yyls1, size * sizeof (*yylsp),
452: &yymaxdepth);
453:
454: yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
455: #else /* no yyoverflow */
456: /* Extend the stack our own way. */
457: if (yymaxdepth >= YYMAXLIMIT)
458: yyerror("parser stack overflow");
459: yymaxdepth *= 2;
460: if (yymaxdepth > YYMAXLIMIT)
461: yymaxdepth = YYMAXLIMIT;
462: yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
463: bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
464: yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
465: bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
1.1.1.3 root 466: #ifdef YYLSP_NEEDED
1.1.1.2 root 467: yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
468: bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
469: #endif
1.1 root 470: #endif /* no yyoverflow */
471:
472: yyssp = yyss + size - 1;
473: yyvsp = yyvs + size - 1;
1.1.1.3 root 474: #ifdef YYLSP_NEEDED
1.1.1.2 root 475: yylsp = yyls + size - 1;
476: #endif
1.1 root 477:
1.1.1.6 ! root 478: #if YYDEBUG != 0
1.1 root 479: if (yydebug)
480: fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
1.1.1.2 root 481: #endif
1.1 root 482:
483: if (yyssp >= yyss + yymaxdepth - 1)
1.1.1.6 ! root 484: YYABORT;
1.1 root 485: }
486:
1.1.1.6 ! root 487: #if YYDEBUG != 0
1.1 root 488: if (yydebug)
489: fprintf(stderr, "Entering state %d\n", yystate);
1.1.1.2 root 490: #endif
1.1 root 491:
492: /* Do appropriate processing given the current state. */
493: /* Read a lookahead token if we need one and don't already have one. */
494: yyresume:
495:
496: /* First try to decide what to do without reference to lookahead token. */
497:
498: yyn = yypact[yystate];
499: if (yyn == YYFLAG)
500: goto yydefault;
501:
502: /* Not known => get a lookahead token if don't already have one. */
503:
504: /* yychar is either YYEMPTY or YYEOF
505: or a valid token in external form. */
506:
507: if (yychar == YYEMPTY)
508: {
1.1.1.6 ! root 509: #if YYDEBUG != 0
1.1.1.2 root 510: if (yydebug)
511: fprintf(stderr, "Reading a token: ");
512: #endif
1.1 root 513: yychar = YYLEX;
514: }
515:
516: /* Convert token to internal form (in yychar1) for indexing tables with */
517:
518: if (yychar <= 0) /* This means end of input. */
519: {
520: yychar1 = 0;
521: yychar = YYEOF; /* Don't call YYLEX any more */
522:
1.1.1.6 ! root 523: #if YYDEBUG != 0
1.1 root 524: if (yydebug)
525: fprintf(stderr, "Now at end of input.\n");
1.1.1.2 root 526: #endif
1.1 root 527: }
528: else
529: {
530: yychar1 = YYTRANSLATE(yychar);
531:
1.1.1.6 ! root 532: #if YYDEBUG != 0
1.1 root 533: if (yydebug)
1.1.1.2 root 534: fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
535: #endif
1.1 root 536: }
537:
538: yyn += yychar1;
539: if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
540: goto yydefault;
541:
542: yyn = yytable[yyn];
543:
544: /* yyn is what to do for this token type in this state.
545: Negative => reduce, -yyn is rule number.
546: Positive => shift, yyn is new state.
547: New state is final state => don't bother to shift,
548: just return success.
549: 0, or most negative number => error. */
550:
551: if (yyn < 0)
552: {
553: if (yyn == YYFLAG)
554: goto yyerrlab;
555: yyn = -yyn;
556: goto yyreduce;
557: }
558: else if (yyn == 0)
559: goto yyerrlab;
560:
561: if (yyn == YYFINAL)
562: YYACCEPT;
563:
564: /* Shift the lookahead token. */
565:
1.1.1.6 ! root 566: #if YYDEBUG != 0
1.1 root 567: if (yydebug)
568: fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
1.1.1.2 root 569: #endif
1.1 root 570:
571: /* Discard the token being shifted unless it is eof. */
572: if (yychar != YYEOF)
573: yychar = YYEMPTY;
574:
575: *++yyvsp = yylval;
1.1.1.3 root 576: #ifdef YYLSP_NEEDED
1.1 root 577: *++yylsp = yylloc;
1.1.1.2 root 578: #endif
1.1 root 579:
580: /* count tokens shifted since error; after three, turn off error status. */
581: if (yyerrstatus) yyerrstatus--;
582:
583: yystate = yyn;
584: goto yynewstate;
585:
586: /* Do the default action for the current state. */
587: yydefault:
588:
589: yyn = yydefact[yystate];
590: if (yyn == 0)
591: goto yyerrlab;
592:
593: /* Do a reduction. yyn is the number of a rule to reduce with. */
594: yyreduce:
595: yylen = yyr2[yyn];
596: yyval = yyvsp[1-yylen]; /* implement default value of the action */
597:
1.1.1.6 ! root 598: #if YYDEBUG != 0
1.1 root 599: if (yydebug)
600: {
601: if (yylen == 1)
602: fprintf (stderr, "Reducing 1 value via line %d, ",
603: yyrline[yyn]);
604: else
605: fprintf (stderr, "Reducing %d values via line %d, ",
606: yylen, yyrline[yyn]);
607: }
1.1.1.2 root 608: #endif
1.1 root 609:
610:
611: switch (yyn) {
612:
613: case 1:
1.1.1.6 ! root 614: #line 72 "cexp.y"
1.1 root 615: { expression_value = yyvsp[0].lval; ;
616: break;}
617: case 3:
1.1.1.6 ! root 618: #line 78 "cexp.y"
1.1 root 619: { yyval.lval = yyvsp[0].lval; ;
620: break;}
621: case 4:
1.1.1.6 ! root 622: #line 83 "cexp.y"
1.1 root 623: { yyval.lval = - yyvsp[0].lval; ;
624: break;}
625: case 5:
1.1.1.6 ! root 626: #line 85 "cexp.y"
1.1 root 627: { yyval.lval = ! yyvsp[0].lval; ;
628: break;}
629: case 6:
1.1.1.6 ! root 630: #line 87 "cexp.y"
1.1 root 631: { yyval.lval = ~ yyvsp[0].lval; ;
632: break;}
633: case 7:
1.1.1.6 ! root 634: #line 89 "cexp.y"
1.1 root 635: { yyval.lval = yyvsp[-1].lval; ;
636: break;}
637: case 8:
1.1.1.6 ! root 638: #line 94 "cexp.y"
1.1 root 639: { yyval.lval = yyvsp[-2].lval * yyvsp[0].lval; ;
640: break;}
641: case 9:
1.1.1.6 ! root 642: #line 96 "cexp.y"
! 643: { if (yyvsp[0].lval == 0)
! 644: {
! 645: error ("division by zero in #if");
! 646: yyvsp[0].lval = 1;
! 647: }
! 648: yyval.lval = yyvsp[-2].lval / yyvsp[0].lval; ;
1.1 root 649: break;}
650: case 10:
1.1.1.6 ! root 651: #line 103 "cexp.y"
! 652: { if (yyvsp[0].lval == 0)
! 653: {
! 654: error ("division by zero in #if");
! 655: yyvsp[0].lval = 1;
! 656: }
! 657: yyval.lval = yyvsp[-2].lval % yyvsp[0].lval; ;
1.1 root 658: break;}
659: case 11:
1.1.1.6 ! root 660: #line 110 "cexp.y"
1.1 root 661: { yyval.lval = yyvsp[-2].lval + yyvsp[0].lval; ;
662: break;}
663: case 12:
1.1.1.6 ! root 664: #line 112 "cexp.y"
1.1 root 665: { yyval.lval = yyvsp[-2].lval - yyvsp[0].lval; ;
666: break;}
667: case 13:
1.1.1.6 ! root 668: #line 114 "cexp.y"
1.1 root 669: { yyval.lval = yyvsp[-2].lval << yyvsp[0].lval; ;
670: break;}
671: case 14:
1.1.1.6 ! root 672: #line 116 "cexp.y"
1.1 root 673: { yyval.lval = yyvsp[-2].lval >> yyvsp[0].lval; ;
674: break;}
675: case 15:
1.1.1.6 ! root 676: #line 118 "cexp.y"
1.1 root 677: { yyval.lval = (yyvsp[-2].lval == yyvsp[0].lval); ;
678: break;}
679: case 16:
1.1.1.6 ! root 680: #line 120 "cexp.y"
1.1 root 681: { yyval.lval = (yyvsp[-2].lval != yyvsp[0].lval); ;
682: break;}
683: case 17:
1.1.1.6 ! root 684: #line 122 "cexp.y"
1.1 root 685: { yyval.lval = (yyvsp[-2].lval <= yyvsp[0].lval); ;
686: break;}
687: case 18:
1.1.1.6 ! root 688: #line 124 "cexp.y"
1.1 root 689: { yyval.lval = (yyvsp[-2].lval >= yyvsp[0].lval); ;
690: break;}
691: case 19:
1.1.1.6 ! root 692: #line 126 "cexp.y"
1.1 root 693: { yyval.lval = (yyvsp[-2].lval < yyvsp[0].lval); ;
694: break;}
695: case 20:
1.1.1.6 ! root 696: #line 128 "cexp.y"
1.1 root 697: { yyval.lval = (yyvsp[-2].lval > yyvsp[0].lval); ;
698: break;}
699: case 21:
1.1.1.6 ! root 700: #line 130 "cexp.y"
1.1 root 701: { yyval.lval = (yyvsp[-2].lval & yyvsp[0].lval); ;
702: break;}
703: case 22:
1.1.1.6 ! root 704: #line 132 "cexp.y"
1.1 root 705: { yyval.lval = (yyvsp[-2].lval ^ yyvsp[0].lval); ;
706: break;}
707: case 23:
1.1.1.6 ! root 708: #line 134 "cexp.y"
1.1 root 709: { yyval.lval = (yyvsp[-2].lval | yyvsp[0].lval); ;
710: break;}
711: case 24:
1.1.1.6 ! root 712: #line 136 "cexp.y"
1.1 root 713: { yyval.lval = (yyvsp[-2].lval && yyvsp[0].lval); ;
714: break;}
715: case 25:
1.1.1.6 ! root 716: #line 138 "cexp.y"
1.1 root 717: { yyval.lval = (yyvsp[-2].lval || yyvsp[0].lval); ;
718: break;}
719: case 26:
1.1.1.6 ! root 720: #line 140 "cexp.y"
1.1 root 721: { yyval.lval = yyvsp[-4].lval ? yyvsp[-2].lval : yyvsp[0].lval; ;
722: break;}
723: case 27:
1.1.1.6 ! root 724: #line 142 "cexp.y"
1.1 root 725: { yyval.lval = yylval.lval; ;
726: break;}
727: case 28:
1.1.1.6 ! root 728: #line 144 "cexp.y"
1.1 root 729: { yyval.lval = yylval.lval; ;
730: break;}
731: case 29:
1.1.1.6 ! root 732: #line 146 "cexp.y"
1.1 root 733: { yyval.lval = 0; ;
734: break;}
735: }
736: /* the action file gets copied in in place of this dollarsign */
1.1.1.6 ! root 737: #line 412 "bison.simple"
1.1 root 738:
739: yyvsp -= yylen;
740: yyssp -= yylen;
1.1.1.3 root 741: #ifdef YYLSP_NEEDED
1.1.1.2 root 742: yylsp -= yylen;
743: #endif
1.1 root 744:
1.1.1.6 ! root 745: #if YYDEBUG != 0
1.1 root 746: if (yydebug)
747: {
748: short *ssp1 = yyss - 1;
1.1.1.6 ! root 749: fprintf (stderr, "state stack now");
1.1 root 750: while (ssp1 != yyssp)
751: fprintf (stderr, " %d", *++ssp1);
752: fprintf (stderr, "\n");
753: }
1.1.1.2 root 754: #endif
1.1 root 755:
756: *++yyvsp = yyval;
757:
1.1.1.3 root 758: #ifdef YYLSP_NEEDED
1.1 root 759: yylsp++;
760: if (yylen == 0)
761: {
762: yylsp->first_line = yylloc.first_line;
763: yylsp->first_column = yylloc.first_column;
764: yylsp->last_line = (yylsp-1)->last_line;
765: yylsp->last_column = (yylsp-1)->last_column;
766: yylsp->text = 0;
767: }
768: else
769: {
770: yylsp->last_line = (yylsp+yylen-1)->last_line;
771: yylsp->last_column = (yylsp+yylen-1)->last_column;
772: }
1.1.1.2 root 773: #endif
1.1 root 774:
775: /* Now "shift" the result of the reduction.
776: Determine what state that goes to,
777: based on the state we popped back to
778: and the rule number reduced by. */
779:
780: yyn = yyr1[yyn];
781:
782: yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
783: if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
784: yystate = yytable[yystate];
785: else
786: yystate = yydefgoto[yyn - YYNTBASE];
787:
788: goto yynewstate;
789:
790: yyerrlab: /* here on detecting error */
791:
792: if (! yyerrstatus)
793: /* If not already recovering from an error, report this error. */
794: {
1.1.1.6 ! root 795: ++yynerrs;
1.1 root 796: yyerror("parse error");
797: }
798:
799: if (yyerrstatus == 3)
800: {
801: /* if just tried and failed to reuse lookahead token after an error, discard it. */
802:
803: /* return failure if at end of input */
804: if (yychar == YYEOF)
1.1.1.6 ! root 805: YYABORT;
1.1 root 806:
1.1.1.6 ! root 807: #if YYDEBUG != 0
1.1 root 808: if (yydebug)
809: fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1.1.1.2 root 810: #endif
1.1 root 811:
812: yychar = YYEMPTY;
813: }
814:
815: /* Else will try to reuse lookahead token
816: after shifting the error token. */
817:
818: yyerrstatus = 3; /* Each real token shifted decrements this */
819:
820: goto yyerrhandle;
821:
822: yyerrdefault: /* current state does not do anything special for the error token. */
823:
824: #if 0
825: /* This is wrong; only states that explicitly want error tokens
826: should shift them. */
827: yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
828: if (yyn) goto yydefault;
829: #endif
830:
831: yyerrpop: /* pop the current state because it cannot handle the error token */
832:
1.1.1.6 ! root 833: if (yyssp == yyss) YYABORT;
1.1 root 834: yyvsp--;
835: yystate = *--yyssp;
1.1.1.3 root 836: #ifdef YYLSP_NEEDED
1.1.1.2 root 837: yylsp--;
838: #endif
1.1 root 839:
1.1.1.6 ! root 840: #if YYDEBUG != 0
1.1 root 841: if (yydebug)
842: {
843: short *ssp1 = yyss - 1;
1.1.1.6 ! root 844: fprintf (stderr, "Error: state stack now");
1.1 root 845: while (ssp1 != yyssp)
846: fprintf (stderr, " %d", *++ssp1);
847: fprintf (stderr, "\n");
848: }
1.1.1.2 root 849: #endif
1.1 root 850:
851: yyerrhandle:
852:
853: yyn = yypact[yystate];
854: if (yyn == YYFLAG)
855: goto yyerrdefault;
856:
857: yyn += YYTERROR;
858: if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
859: goto yyerrdefault;
860:
861: yyn = yytable[yyn];
862: if (yyn < 0)
863: {
864: if (yyn == YYFLAG)
865: goto yyerrpop;
866: yyn = -yyn;
867: goto yyreduce;
868: }
869: else if (yyn == 0)
870: goto yyerrpop;
871:
872: if (yyn == YYFINAL)
873: YYACCEPT;
874:
1.1.1.6 ! root 875: #if YYDEBUG != 0
1.1 root 876: if (yydebug)
877: fprintf(stderr, "Shifting error token, ");
1.1.1.2 root 878: #endif
1.1 root 879:
880: *++yyvsp = yylval;
1.1.1.3 root 881: #ifdef YYLSP_NEEDED
1.1 root 882: *++yylsp = yylloc;
1.1.1.2 root 883: #endif
1.1 root 884:
885: yystate = yyn;
886: goto yynewstate;
887: }
1.1.1.6 ! root 888: #line 148 "cexp.y"
1.1 root 889:
890:
891: /* During parsing of a C expression, the pointer to the next character
892: is in this variable. */
893:
894: static char *lexptr;
895:
896: /* Take care of parsing a number (anything that starts with a digit).
897: Set yylval and return the token type; update lexptr.
898: LEN is the number of characters in it. */
899:
900: /* maybe needs to actually deal with floating point numbers */
901:
1.1.1.3 root 902: int
1.1 root 903: parse_number (olen)
904: int olen;
905: {
906: register char *p = lexptr;
907: register long n = 0;
908: register int c;
909: register int base = 10;
910: register len = olen;
911:
912: extern double atof ();
913:
914: for (c = 0; c < len; c++)
915: if (p[c] == '.') {
916: /* It's a float since it contains a point. */
917: yyerror ("floating point numbers not allowed in #if expressions");
918: return ERROR;
919:
920: /* ****************
921: yylval.dval = atof (p);
922: lexptr += len;
923: return FLOAT;
924: **************** */
925: }
926:
927: if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) {
928: p += 2;
929: base = 16;
930: len -= 2;
931: }
932: else if (*p == '0')
933: base = 8;
934:
935: while (len-- > 0) {
936: c = *p++;
937: n *= base;
938: if (c >= '0' && c <= '9')
939: n += c - '0';
940: else {
941: if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
942: if (base == 16 && c >= 'a' && c <= 'f')
943: n += c - 'a' + 10;
944: else if (len == 0 && c == 'l')
945: ;
946: else {
947: yyerror ("Invalid number in #if expression");
948: return ERROR;
949: }
950: }
951: }
952:
953: lexptr = p;
954: yylval.lval = n;
955: return INT;
956: }
957:
958: struct token {
959: char *operator;
960: int token;
961: };
962:
963: #define NULL 0
964:
965: static struct token tokentab2[] = {
966: {"&&", AND},
967: {"||", OR},
968: {"<<", LSH},
969: {">>", RSH},
970: {"==", EQUAL},
971: {"!=", NOTEQUAL},
972: {"<=", LEQ},
973: {">=", GEQ},
974: {NULL, ERROR}
975: };
976:
977: /* Read one token, getting characters through lexptr. */
978:
1.1.1.3 root 979: int
1.1 root 980: yylex ()
981: {
982: register int c;
983: register int namelen;
984: register char *tokstart;
985: register struct token *toktab;
986:
987: retry:
988:
989: tokstart = lexptr;
990: c = *tokstart;
991: /* See if it is a special token of length 2. */
992: for (toktab = tokentab2; toktab->operator != NULL; toktab++)
993: if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) {
994: lexptr += 2;
995: return toktab->token;
996: }
997:
998: switch (c) {
999: case 0:
1000: return 0;
1001:
1002: case ' ':
1003: case '\t':
1004: case '\n':
1005: lexptr++;
1006: goto retry;
1007:
1008: case '\'':
1009: lexptr++;
1010: c = *lexptr++;
1011: if (c == '\\')
1012: c = parse_escape (&lexptr);
1013: yylval.lval = c;
1014: c = *lexptr++;
1015: if (c != '\'') {
1016: yyerror ("Invalid character constant in #if");
1017: return ERROR;
1018: }
1019:
1020: return CHAR;
1021:
1022: /* some of these chars are invalid in constant expressions;
1023: maybe do something about them later */
1024: case '/':
1025: case '+':
1026: case '-':
1027: case '*':
1028: case '%':
1029: case '|':
1030: case '&':
1031: case '^':
1032: case '~':
1033: case '!':
1034: case '@':
1035: case '<':
1036: case '>':
1037: case '(':
1038: case ')':
1039: case '[':
1040: case ']':
1041: case '.':
1042: case '?':
1043: case ':':
1044: case '=':
1045: case '{':
1046: case '}':
1047: case ',':
1048: lexptr++;
1049: return c;
1050:
1051: case '"':
1052: yyerror ("double quoted strings not allowed in #if expressions");
1053: return ERROR;
1054: }
1055: if (c >= '0' && c <= '9') {
1056: /* It's a number */
1057: for (namelen = 0;
1058: c = tokstart[namelen], is_idchar[c] || c == '.';
1059: namelen++)
1060: ;
1061: return parse_number (namelen);
1062: }
1063:
1064: if (!is_idstart[c]) {
1065: yyerror ("Invalid token in expression");
1066: return ERROR;
1067: }
1068:
1069: /* It is a name. See how long it is. */
1070:
1071: for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
1072: ;
1073:
1074: lexptr += namelen;
1075: return NAME;
1076: }
1077:
1078:
1079: /* Parse a C escape sequence. STRING_PTR points to a variable
1080: containing a pointer to the string to parse. That pointer
1081: is updated past the characters we use. The value of the
1082: escape sequence is returned.
1083:
1084: A negative value means the sequence \ newline was seen,
1085: which is supposed to be equivalent to nothing at all.
1086:
1087: If \ is followed by a null character, we return a negative
1088: value and leave the string pointer pointing at the null character.
1089:
1090: If \ is followed by 000, we return 0 and leave the string pointer
1091: after the zeros. A value of 0 does not mean end of string. */
1092:
1.1.1.3 root 1093: int
1.1 root 1094: parse_escape (string_ptr)
1095: char **string_ptr;
1096: {
1097: register int c = *(*string_ptr)++;
1098: switch (c)
1099: {
1100: case 'a':
1101: return '\a';
1102: case 'b':
1103: return '\b';
1104: case 'e':
1105: return 033;
1106: case 'f':
1107: return '\f';
1108: case 'n':
1109: return '\n';
1110: case 'r':
1111: return '\r';
1112: case 't':
1113: return '\t';
1114: case 'v':
1115: return '\v';
1116: case '\n':
1117: return -2;
1118: case 0:
1119: (*string_ptr)--;
1120: return 0;
1121: case '^':
1122: c = *(*string_ptr)++;
1123: if (c == '\\')
1124: c = parse_escape (string_ptr);
1125: if (c == '?')
1126: return 0177;
1127: return (c & 0200) | (c & 037);
1128:
1129: case '0':
1130: case '1':
1131: case '2':
1132: case '3':
1133: case '4':
1134: case '5':
1135: case '6':
1136: case '7':
1137: {
1138: register int i = c - '0';
1139: register int count = 0;
1140: while (++count < 3)
1141: {
1142: if ((c = *(*string_ptr)++) >= '0' && c <= '7')
1143: {
1144: i *= 8;
1145: i += c - '0';
1146: }
1147: else
1148: {
1149: (*string_ptr)--;
1150: break;
1151: }
1152: }
1153: return i;
1154: }
1155: default:
1156: return c;
1157: }
1158: }
1159:
1.1.1.3 root 1160: void
1.1 root 1161: yyerror (s)
1162: char *s;
1163: {
1164: error (s);
1165: longjmp (parse_return_error, 1);
1166: }
1167:
1168: /* This page contains the entry point to this file. */
1169:
1170: /* Parse STRING as an expression, and complain if this fails
1171: to use up all of the contents of STRING. */
1172: /* We do not support C comments. They should be removed before
1173: this function is called. */
1174:
1175: int
1176: parse_c_expression (string)
1177: char *string;
1178: {
1179: lexptr = string;
1180:
1181: if (lexptr == 0 || *lexptr == 0) {
1182: error ("empty #if expression");
1183: return 0; /* don't include the #if group */
1184: }
1185:
1186: /* if there is some sort of scanning error, just return 0 and assume
1187: the parsing routine has printed an error message somewhere.
1188: there is surely a better thing to do than this. */
1189: if (setjmp(parse_return_error))
1190: return 0;
1191:
1192: if (yyparse ())
1193: return 0; /* actually this is never reached
1194: the way things stand. */
1195: if (*lexptr)
1196: error ("Junk after end of expression.");
1197:
1198: return expression_value; /* set by yyparse() */
1199: }
1200:
1201: #ifdef TEST_EXP_READER
1202: /* main program, for testing purposes. */
1203: main()
1204: {
1205: int n;
1206: char buf[1024];
1207: extern int yydebug;
1208: /*
1209: yydebug = 1;
1210: */
1211: initialize_random_junk ();
1212:
1213: for (;;) {
1214: printf("enter expression: ");
1215: n = 0;
1216: while ((buf[n] = getchar()) != '\n')
1217: n++;
1218: buf[n] = '\0';
1219: printf("parser returned %d\n", parse_c_expression(buf));
1220: }
1221: }
1222:
1223: /* table to tell if char can be part of a C identifier. */
1224: char is_idchar[256];
1225: /* table to tell if char can be first char of a c identifier. */
1226: char is_idstart[256];
1227: /* table to tell if c is horizontal space. isspace() thinks that
1228: newline is space; this is not a good idea for this program. */
1229: char is_hor_space[256];
1230:
1231: /*
1232: * initialize random junk in the hash table and maybe other places
1233: */
1234: initialize_random_junk()
1235: {
1236: register int i;
1237:
1238: /*
1239: * Set up is_idchar and is_idstart tables. These should be
1240: * faster than saying (is_alpha(c) || c == '_'), etc.
1241: * Must do set up these things before calling any routines tthat
1242: * refer to them.
1243: */
1244: for (i = 'a'; i <= 'z'; i++) {
1245: ++is_idchar[i - 'a' + 'A'];
1246: ++is_idchar[i];
1247: ++is_idstart[i - 'a' + 'A'];
1248: ++is_idstart[i];
1249: }
1250: for (i = '0'; i <= '9'; i++)
1251: ++is_idchar[i];
1252: ++is_idchar['_'];
1253: ++is_idstart['_'];
1254: #ifdef DOLLARS_IN_IDENTIFIERS
1255: ++is_idchar['$'];
1256: ++is_idstart['$'];
1257: #endif
1258:
1259: /* horizontal space table */
1260: ++is_hor_space[' '];
1261: ++is_hor_space['\t'];
1262: }
1263:
1264: error (msg)
1265: {
1266: printf("error: %s\n", msg);
1267: }
1268: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.