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