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