1 #ifndef lint
2 static const char yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93";
3 #endif
4 
5 #include <stdlib.h>
6 #include <string.h>
7 
8 #define YYBYACC 1
9 #define YYMAJOR 1
10 #define YYMINOR 9
11 #define YYPATCH 20091027
12 
13 #define YYEMPTY        (-1)
14 #define yyclearin      (yychar = YYEMPTY)
15 #define yyerrok        (yyerrflag = 0)
16 #define YYRECOVERING() (yyerrflag != 0)
17 
18 /* compatibility with bison */
19 #ifdef YYPARSE_PARAM
20 /* compatibility with FreeBSD */
21 #ifdef YYPARSE_PARAM_TYPE
22 #define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
23 #else
24 #define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
25 #endif
26 #else
27 #define YYPARSE_DECL() yyparse(void)
28 #endif /* YYPARSE_PARAM */
29 
30 extern int YYPARSE_DECL();
31 
32 static int yygrowstack(void);
33 #define YYPREFIX "yy"
34 /*	$NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $	*/
35 
36 /*-
37  * Copyright (c) 1993
38  *	The Regents of the University of California.  All rights reserved.
39  *
40  * This code is derived from software contributed to Berkeley by
41  * Kenneth Almquist.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  * 3. Neither the name of the University nor the names of its contributors
52  *    may be used to endorse or promote products derived from this software
53  *    without specific prior written permission.
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65  * SUCH DAMAGE.
66  */
67 
68 #if 0
69 #ifndef lint
70 static char sccsid[] = "@(#)arith.y	8.3 (Berkeley) 5/4/95";
71 #else
72 __RCSID("$NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $");
73 #endif /* not lint */
74 #endif
75 
76 #include <stdlib.h>
77 #include "expand.h"
78 #include "shell.h"
79 #include "error.h"
80 #include "output.h"
81 #include "memalloc.h"
82 #include "shinstance.h"
83 
84 shinstance *arith_psh;
85 const char *arith_buf, *arith_startbuf;
86 
87 void yyerror(const char *);
88 #ifdef TESTARITH
89 int main(int , char *[]);
90 int error(char *);
91 #else
92 # undef  malloc
93 # define malloc(cb)        sh_malloc(NULL, (cb))
94 # undef  realloc
95 # define realloc(pv,cb)    sh_realloc(NULL, (pv), (cb))
96 # undef  free
97 # define free(pv)          sh_free(NULL, (pv))
98 #endif
99 
100 #define ARITH_NUM 257
101 #define ARITH_LPAREN 258
102 #define ARITH_RPAREN 259
103 #define ARITH_OR 260
104 #define ARITH_AND 261
105 #define ARITH_BOR 262
106 #define ARITH_BXOR 263
107 #define ARITH_BAND 264
108 #define ARITH_EQ 265
109 #define ARITH_NE 266
110 #define ARITH_LT 267
111 #define ARITH_GT 268
112 #define ARITH_GE 269
113 #define ARITH_LE 270
114 #define ARITH_LSHIFT 271
115 #define ARITH_RSHIFT 272
116 #define ARITH_ADD 273
117 #define ARITH_SUB 274
118 #define ARITH_MUL 275
119 #define ARITH_DIV 276
120 #define ARITH_REM 277
121 #define ARITH_UNARYMINUS 278
122 #define ARITH_UNARYPLUS 279
123 #define ARITH_NOT 280
124 #define ARITH_BNOT 281
125 #define YYERRCODE 256
126 static const short yylhs[] = {                           -1,
127     0,    1,    1,    1,    1,    1,    1,    1,    1,    1,
128     1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
129     1,    1,    1,    1,    1,
130 };
131 static const short yylen[] = {                            2,
132     1,    3,    3,    3,    3,    3,    3,    3,    3,    3,
133     3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
134     2,    2,    2,    2,    1,
135 };
136 static const short yydefred[] = {                         0,
137    25,    0,    0,    0,    0,    0,    0,    0,    0,   24,
138    23,   21,   22,    0,    0,    0,    0,    0,    0,    0,
139     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
140     0,    2,    0,    0,    0,    0,    0,    0,    0,    0,
141     0,    0,    0,    0,    0,    0,    0,   18,   19,   20,
142 };
143 static const short yydgoto[] = {                          7,
144     8,
145 };
146 static const short yysindex[] = {                      -255,
147     0, -255, -255, -255, -255, -255,    0,  -67,  -85,    0,
148     0,    0,    0, -255, -255, -255, -255, -255, -255, -255,
149  -255, -255, -255, -255, -255, -255, -255, -255, -255, -255,
150  -255,    0,  -50,  -34,  -19,  141, -261, -233, -233, -223,
151  -223, -223, -223, -253, -253, -248, -248,    0,    0,    0,
152 };
153 static const short yyrindex[] = {                         0,
154     0,    0,    0,    0,    0,    0,    0,   30,    0,    0,
155     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
156     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
157     0,    0,  143,  140,  136,  131,  125,  109,  117,   61,
158    73,   85,   97,   33,   47,    1,   17,    0,    0,    0,
159 };
160 static const short yygindex[] = {                         0,
161   142,
162 };
163 #define YYTABLESIZE 418
164 static const short yytable[] = {                          0,
165    16,    1,    2,   19,   20,   21,   22,   23,   24,   25,
166    26,   27,   28,   29,   30,   31,   17,    3,    4,   27,
167    28,   29,   30,   31,    5,    6,   29,   30,   31,    1,
168     0,    0,   14,   21,   22,   23,   24,   25,   26,   27,
169    28,   29,   30,   31,    0,    0,   15,   25,   26,   27,
170    28,   29,   30,   31,    0,    0,    0,    0,    0,    0,
171    11,    0,    0,    0,    0,    0,    0,    0,    0,    0,
172     0,    0,    9,    0,    0,    0,    0,    0,    0,    0,
173     0,    0,    0,    0,   10,    0,    0,    0,    0,    0,
174     0,    0,    0,    0,    0,    0,   12,    0,    0,    0,
175     0,    0,    0,    0,    0,    0,    0,    0,    8,    0,
176     0,    0,    0,    0,    0,    0,   13,    0,    0,    0,
177     0,    0,    0,    0,    7,    0,    0,    0,    0,    0,
178     6,    0,    0,    0,    0,    5,    0,    0,    0,    4,
179     0,    0,    3,    9,   10,   11,   12,   13,    0,    0,
180     0,    0,    0,    0,    0,   33,   34,   35,   36,   37,
181    38,   39,   40,   41,   42,   43,   44,   45,   46,   47,
182    48,   49,   50,   32,   14,   15,   16,   17,   18,   19,
183    20,   21,   22,   23,   24,   25,   26,   27,   28,   29,
184    30,   31,   14,   15,   16,   17,   18,   19,   20,   21,
185    22,   23,   24,   25,   26,   27,   28,   29,   30,   31,
186    15,   16,   17,   18,   19,   20,   21,   22,   23,   24,
187    25,   26,   27,   28,   29,   30,   31,   16,   17,   18,
188    19,   20,   21,   22,   23,   24,   25,   26,   27,   28,
189    29,   30,   31,   17,   18,   19,   20,   21,   22,   23,
190    24,   25,   26,   27,   28,   29,   30,   31,    0,   16,
191    16,   16,   16,   16,   16,   16,   16,   16,   16,   16,
192    16,   16,   16,   16,   16,   17,   17,   17,   17,   17,
193    17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
194    17,   14,   14,   14,   14,   14,   14,   14,   14,   14,
195    14,   14,   14,   14,   14,   15,   15,   15,   15,   15,
196    15,   15,   15,   15,   15,   15,   15,   15,   15,   11,
197    11,   11,   11,   11,   11,   11,   11,   11,   11,   11,
198    11,    9,    9,    9,    9,    9,    9,    9,    9,    9,
199     9,    9,    9,   10,   10,   10,   10,   10,   10,   10,
200    10,   10,   10,   10,   10,   12,   12,   12,   12,   12,
201    12,   12,   12,   12,   12,   12,   12,    8,    8,    8,
202     8,    8,    8,    8,    8,   13,   13,   13,   13,   13,
203    13,   13,   13,    7,    7,    7,    7,    7,    7,    6,
204     6,    6,    6,    6,    5,    5,    5,    5,    4,    4,
205     4,    3,    3,    0,   18,   19,   20,   21,   22,   23,
206    24,   25,   26,   27,   28,   29,   30,   31,
207 };
208 static const short yycheck[] = {                         -1,
209     0,  257,  258,  265,  266,  267,  268,  269,  270,  271,
210   272,  273,  274,  275,  276,  277,    0,  273,  274,  273,
211   274,  275,  276,  277,  280,  281,  275,  276,  277,    0,
212    -1,   -1,    0,  267,  268,  269,  270,  271,  272,  273,
213   274,  275,  276,  277,   -1,   -1,    0,  271,  272,  273,
214   274,  275,  276,  277,   -1,   -1,   -1,   -1,   -1,   -1,
215     0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
216    -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
217    -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
218    -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,
219    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,
220    -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,
221    -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
222     0,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,    0,
223    -1,   -1,    0,    2,    3,    4,    5,    6,   -1,   -1,
224    -1,   -1,   -1,   -1,   -1,   14,   15,   16,   17,   18,
225    19,   20,   21,   22,   23,   24,   25,   26,   27,   28,
226    29,   30,   31,  259,  260,  261,  262,  263,  264,  265,
227   266,  267,  268,  269,  270,  271,  272,  273,  274,  275,
228   276,  277,  260,  261,  262,  263,  264,  265,  266,  267,
229   268,  269,  270,  271,  272,  273,  274,  275,  276,  277,
230   261,  262,  263,  264,  265,  266,  267,  268,  269,  270,
231   271,  272,  273,  274,  275,  276,  277,  262,  263,  264,
232   265,  266,  267,  268,  269,  270,  271,  272,  273,  274,
233   275,  276,  277,  263,  264,  265,  266,  267,  268,  269,
234   270,  271,  272,  273,  274,  275,  276,  277,   -1,  259,
235   260,  261,  262,  263,  264,  265,  266,  267,  268,  269,
236   270,  271,  272,  273,  274,  259,  260,  261,  262,  263,
237   264,  265,  266,  267,  268,  269,  270,  271,  272,  273,
238   274,  259,  260,  261,  262,  263,  264,  265,  266,  267,
239   268,  269,  270,  271,  272,  259,  260,  261,  262,  263,
240   264,  265,  266,  267,  268,  269,  270,  271,  272,  259,
241   260,  261,  262,  263,  264,  265,  266,  267,  268,  269,
242   270,  259,  260,  261,  262,  263,  264,  265,  266,  267,
243   268,  269,  270,  259,  260,  261,  262,  263,  264,  265,
244   266,  267,  268,  269,  270,  259,  260,  261,  262,  263,
245   264,  265,  266,  267,  268,  269,  270,  259,  260,  261,
246   262,  263,  264,  265,  266,  259,  260,  261,  262,  263,
247   264,  265,  266,  259,  260,  261,  262,  263,  264,  259,
248   260,  261,  262,  263,  259,  260,  261,  262,  259,  260,
249   261,  259,  260,   -1,  264,  265,  266,  267,  268,  269,
250   270,  271,  272,  273,  274,  275,  276,  277,
251 };
252 #define YYFINAL 7
253 #ifndef YYDEBUG
254 #define YYDEBUG 0
255 #endif
256 #define YYMAXTOKEN 281
257 #if YYDEBUG
258 static const char *yyname[] = {
259 
260 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
261 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
262 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
263 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
264 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
265 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
266 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"ARITH_NUM","ARITH_LPAREN",
267 "ARITH_RPAREN","ARITH_OR","ARITH_AND","ARITH_BOR","ARITH_BXOR","ARITH_BAND",
268 "ARITH_EQ","ARITH_NE","ARITH_LT","ARITH_GT","ARITH_GE","ARITH_LE",
269 "ARITH_LSHIFT","ARITH_RSHIFT","ARITH_ADD","ARITH_SUB","ARITH_MUL","ARITH_DIV",
270 "ARITH_REM","ARITH_UNARYMINUS","ARITH_UNARYPLUS","ARITH_NOT","ARITH_BNOT",
271 };
272 static const char *yyrule[] = {
273 "$accept : exp",
274 "exp : expr",
275 "expr : ARITH_LPAREN expr ARITH_RPAREN",
276 "expr : expr ARITH_OR expr",
277 "expr : expr ARITH_AND expr",
278 "expr : expr ARITH_BOR expr",
279 "expr : expr ARITH_BXOR expr",
280 "expr : expr ARITH_BAND expr",
281 "expr : expr ARITH_EQ expr",
282 "expr : expr ARITH_GT expr",
283 "expr : expr ARITH_GE expr",
284 "expr : expr ARITH_LT expr",
285 "expr : expr ARITH_LE expr",
286 "expr : expr ARITH_NE expr",
287 "expr : expr ARITH_LSHIFT expr",
288 "expr : expr ARITH_RSHIFT expr",
289 "expr : expr ARITH_ADD expr",
290 "expr : expr ARITH_SUB expr",
291 "expr : expr ARITH_MUL expr",
292 "expr : expr ARITH_DIV expr",
293 "expr : expr ARITH_REM expr",
294 "expr : ARITH_NOT expr",
295 "expr : ARITH_BNOT expr",
296 "expr : ARITH_SUB expr",
297 "expr : ARITH_ADD expr",
298 "expr : ARITH_NUM",
299 
300 };
301 #endif
302 #ifndef YYSTYPE
303 typedef int YYSTYPE;
304 #endif
305 #if YYDEBUG
306 #include <stdio.h>
307 #endif
308 
309 /* define the initial stack-sizes */
310 #ifdef YYSTACKSIZE
311 #undef YYMAXDEPTH
312 #define YYMAXDEPTH  YYSTACKSIZE
313 #else
314 #ifdef YYMAXDEPTH
315 #define YYSTACKSIZE YYMAXDEPTH
316 #else
317 #define YYSTACKSIZE 500
318 #define YYMAXDEPTH  500
319 #endif
320 #endif
321 
322 #define YYINITSTACKSIZE 500
323 
324 int      yydebug;
325 int      yynerrs;
326 int      yyerrflag;
327 int      yychar;
328 short   *yyssp;
329 YYSTYPE *yyvsp;
330 YYSTYPE  yyval;
331 YYSTYPE  yylval;
332 
333 /* variables for the parser stack */
334 static short   *yyss;
335 static short   *yysslim;
336 static YYSTYPE *yyvs;
337 static unsigned yystacksize;
338 int
arith(shinstance * psh,const char * s)339 arith(shinstance *psh, const char *s)
340 {
341 	long result;
342 
343 	INTOFF;
344 /* todo lock */
345    arith_psh = psh;
346 	arith_buf = arith_startbuf = s;
347 	result = yyparse();
348 	arith_lex_reset();	/* reprime lex */
349    arith_psh = NULL;
350 /* todo unlock */
351 	INTON;
352 
353 	return (result);
354 }
355 
356 
357 /*
358  *  The exp(1) builtin.
359  */
360 int
expcmd(shinstance * psh,int argc,char ** argv)361 expcmd(shinstance *psh, int argc, char **argv)
362 {
363 	const char *p;
364 	char *concat;
365 	char **ap;
366 	long i;
367 
368 	if (argc > 1) {
369 		p = argv[1];
370 		if (argc > 2) {
371 			/*
372 			 * concatenate arguments
373 			 */
374 			STARTSTACKSTR(psh, concat);
375 			ap = argv + 2;
376 			for (;;) {
377 				while (*p)
378 					STPUTC(psh, *p++, concat);
379 				if ((p = *ap++) == NULL)
380 					break;
381 				STPUTC(psh, ' ', concat);
382 			}
383 			STPUTC(psh, '\0', concat);
384 			p = grabstackstr(psh, concat);
385 		}
386 	} else
387 		p = "";
388 
389 	i = arith(psh, p);
390 
391 	out1fmt(psh, "%ld\n", i);
392 	return (! i);
393 }
394 
395 /*************************/
396 #ifdef TEST_ARITH
397 #include <stdio.h>
main(argc,argv)398 main(argc, argv)
399 	char *argv[];
400 {
401 	printf("%d\n", exp(argv[1]));
402 }
error(s)403 error(s)
404 	char *s;
405 {
406 	fprintf(stderr, "exp: %s\n", s);
407 	exit(1);
408 }
409 #endif
410 
411 void
yyerror(const char * s)412 yyerror(const char *s)
413 {
414     shinstance *psh = arith_psh;
415 #ifndef YYBISON /* yyerrok references yyerrstatus which is a local variable in yyparse().*/
416 	yyerrok;
417 #endif
418 	yyclearin;
419 	arith_lex_reset();	/* reprime lex */
420 /** @todo unlock */
421 	error(psh, "arithmetic expression: %s: \"%s\"", s, arith_startbuf);
422 	/* NOTREACHED */
423 }
424 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
yygrowstack(void)425 static int yygrowstack(void)
426 {
427     int i;
428     unsigned newsize;
429     short *newss;
430     YYSTYPE *newvs;
431 
432     if ((newsize = yystacksize) == 0)
433         newsize = YYINITSTACKSIZE;
434     else if (newsize >= YYMAXDEPTH)
435         return -1;
436     else if ((newsize *= 2) > YYMAXDEPTH)
437         newsize = YYMAXDEPTH;
438 
439     i = yyssp - yyss;
440     newss = (yyss != 0)
441           ? (short *)realloc(yyss, newsize * sizeof(*newss))
442           : (short *)malloc(newsize * sizeof(*newss));
443     if (newss == 0)
444         return -1;
445 
446     yyss  = newss;
447     yyssp = newss + i;
448     newvs = (yyvs != 0)
449           ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))
450           : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
451     if (newvs == 0)
452         return -1;
453 
454     yyvs = newvs;
455     yyvsp = newvs + i;
456     yystacksize = newsize;
457     yysslim = yyss + newsize - 1;
458     return 0;
459 }
460 
461 #define YYABORT  goto yyabort
462 #define YYREJECT goto yyabort
463 #define YYACCEPT goto yyaccept
464 #define YYERROR  goto yyerrlab
465 
466 int
YYPARSE_DECL()467 YYPARSE_DECL()
468 {
469     int yym, yyn, yystate;
470 #if YYDEBUG
471     const char *yys;
472 
473     if ((yys = getenv("YYDEBUG")) != 0)
474     {
475         yyn = *yys;
476         if (yyn >= '0' && yyn <= '9')
477             yydebug = yyn - '0';
478     }
479 #endif
480 
481     yynerrs = 0;
482     yyerrflag = 0;
483     yychar = YYEMPTY;
484     yystate = 0;
485 
486     if (yyss == NULL && yygrowstack()) goto yyoverflow;
487     yyssp = yyss;
488     yyvsp = yyvs;
489     yystate = 0;
490     *yyssp = 0;
491 
492 yyloop:
493     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
494     if (yychar < 0)
495     {
496         if ((yychar = yylex()) < 0) yychar = 0;
497 #if YYDEBUG
498         if (yydebug)
499         {
500             yys = 0;
501             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
502             if (!yys) yys = "illegal-symbol";
503             printf("%sdebug: state %d, reading %d (%s)\n",
504                     YYPREFIX, yystate, yychar, yys);
505         }
506 #endif
507     }
508     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
509             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
510     {
511 #if YYDEBUG
512         if (yydebug)
513             printf("%sdebug: state %d, shifting to state %d\n",
514                     YYPREFIX, yystate, yytable[yyn]);
515 #endif
516         if (yyssp >= yysslim && yygrowstack())
517         {
518             goto yyoverflow;
519         }
520         yystate = yytable[yyn];
521         *++yyssp = yytable[yyn];
522         *++yyvsp = yylval;
523         yychar = YYEMPTY;
524         if (yyerrflag > 0)  --yyerrflag;
525         goto yyloop;
526     }
527     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
528             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
529     {
530         yyn = yytable[yyn];
531         goto yyreduce;
532     }
533     if (yyerrflag) goto yyinrecovery;
534 
535     yyerror("syntax error");
536 
537     goto yyerrlab;
538 
539 yyerrlab:
540     ++yynerrs;
541 
542 yyinrecovery:
543     if (yyerrflag < 3)
544     {
545         yyerrflag = 3;
546         for (;;)
547         {
548             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
549                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
550             {
551 #if YYDEBUG
552                 if (yydebug)
553                     printf("%sdebug: state %d, error recovery shifting\
554  to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
555 #endif
556                 if (yyssp >= yysslim && yygrowstack())
557                 {
558                     goto yyoverflow;
559                 }
560                 yystate = yytable[yyn];
561                 *++yyssp = yytable[yyn];
562                 *++yyvsp = yylval;
563                 goto yyloop;
564             }
565             else
566             {
567 #if YYDEBUG
568                 if (yydebug)
569                     printf("%sdebug: error recovery discarding state %d\n",
570                             YYPREFIX, *yyssp);
571 #endif
572                 if (yyssp <= yyss) goto yyabort;
573                 --yyssp;
574                 --yyvsp;
575             }
576         }
577     }
578     else
579     {
580         if (yychar == 0) goto yyabort;
581 #if YYDEBUG
582         if (yydebug)
583         {
584             yys = 0;
585             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
586             if (!yys) yys = "illegal-symbol";
587             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
588                     YYPREFIX, yystate, yychar, yys);
589         }
590 #endif
591         yychar = YYEMPTY;
592         goto yyloop;
593     }
594 
595 yyreduce:
596 #if YYDEBUG
597     if (yydebug)
598         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
599                 YYPREFIX, yystate, yyn, yyrule[yyn]);
600 #endif
601     yym = yylen[yyn];
602     if (yym)
603         yyval = yyvsp[1-yym];
604     else
605         memset(&yyval, 0, sizeof yyval);
606     switch (yyn)
607     {
608 case 1:
609 	{
610 			return (yyvsp[0]);
611 		}
612 break;
613 case 2:
614 	{ yyval = yyvsp[-1]; }
615 break;
616 case 3:
617 	{ yyval = yyvsp[-2] ? yyvsp[-2] : yyvsp[0] ? yyvsp[0] : 0; }
618 break;
619 case 4:
620 	{ yyval = yyvsp[-2] ? ( yyvsp[0] ? yyvsp[0] : 0 ) : 0; }
621 break;
622 case 5:
623 	{ yyval = yyvsp[-2] | yyvsp[0]; }
624 break;
625 case 6:
626 	{ yyval = yyvsp[-2] ^ yyvsp[0]; }
627 break;
628 case 7:
629 	{ yyval = yyvsp[-2] & yyvsp[0]; }
630 break;
631 case 8:
632 	{ yyval = yyvsp[-2] == yyvsp[0]; }
633 break;
634 case 9:
635 	{ yyval = yyvsp[-2] > yyvsp[0]; }
636 break;
637 case 10:
638 	{ yyval = yyvsp[-2] >= yyvsp[0]; }
639 break;
640 case 11:
641 	{ yyval = yyvsp[-2] < yyvsp[0]; }
642 break;
643 case 12:
644 	{ yyval = yyvsp[-2] <= yyvsp[0]; }
645 break;
646 case 13:
647 	{ yyval = yyvsp[-2] != yyvsp[0]; }
648 break;
649 case 14:
650 	{ yyval = yyvsp[-2] << yyvsp[0]; }
651 break;
652 case 15:
653 	{ yyval = yyvsp[-2] >> yyvsp[0]; }
654 break;
655 case 16:
656 	{ yyval = yyvsp[-2] + yyvsp[0]; }
657 break;
658 case 17:
659 	{ yyval = yyvsp[-2] - yyvsp[0]; }
660 break;
661 case 18:
662 	{ yyval = yyvsp[-2] * yyvsp[0]; }
663 break;
664 case 19:
665 	{
666 			if (yyvsp[0] == 0)
667 				yyerror("division by zero");
668 			yyval = yyvsp[-2] / yyvsp[0];
669 			}
670 break;
671 case 20:
672 	{
673 			if (yyvsp[0] == 0)
674 				yyerror("division by zero");
675 			yyval = yyvsp[-2] % yyvsp[0];
676 			}
677 break;
678 case 21:
679 	{ yyval = !(yyvsp[0]); }
680 break;
681 case 22:
682 	{ yyval = ~(yyvsp[0]); }
683 break;
684 case 23:
685 	{ yyval = -(yyvsp[0]); }
686 break;
687 case 24:
688 	{ yyval = yyvsp[0]; }
689 break;
690     }
691     yyssp -= yym;
692     yystate = *yyssp;
693     yyvsp -= yym;
694     yym = yylhs[yyn];
695     if (yystate == 0 && yym == 0)
696     {
697 #if YYDEBUG
698         if (yydebug)
699             printf("%sdebug: after reduction, shifting from state 0 to\
700  state %d\n", YYPREFIX, YYFINAL);
701 #endif
702         yystate = YYFINAL;
703         *++yyssp = YYFINAL;
704         *++yyvsp = yyval;
705         if (yychar < 0)
706         {
707             if ((yychar = yylex()) < 0) yychar = 0;
708 #if YYDEBUG
709             if (yydebug)
710             {
711                 yys = 0;
712                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
713                 if (!yys) yys = "illegal-symbol";
714                 printf("%sdebug: state %d, reading %d (%s)\n",
715                         YYPREFIX, YYFINAL, yychar, yys);
716             }
717 #endif
718         }
719         if (yychar == 0) goto yyaccept;
720         goto yyloop;
721     }
722     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
723             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
724         yystate = yytable[yyn];
725     else
726         yystate = yydgoto[yym];
727 #if YYDEBUG
728     if (yydebug)
729         printf("%sdebug: after reduction, shifting from state %d \
730 to state %d\n", YYPREFIX, *yyssp, yystate);
731 #endif
732     if (yyssp >= yysslim && yygrowstack())
733     {
734         goto yyoverflow;
735     }
736     *++yyssp = (short) yystate;
737     *++yyvsp = yyval;
738     goto yyloop;
739 
740 yyoverflow:
741     yyerror("yacc stack overflow");
742 
743 yyabort:
744     return (1);
745 
746 yyaccept:
747     return (0);
748 }
749