1 | |
---|
2 | /* A Bison parser, made from ../factory/readcf.y */ |
---|
3 | |
---|
4 | #define YYBISON 1 /* Identify Bison output. */ |
---|
5 | |
---|
6 | #define NUM 258 |
---|
7 | #define NEG 259 |
---|
8 | |
---|
9 | #line 4 "../factory/readcf.y" |
---|
10 | |
---|
11 | |
---|
12 | #ifdef WINNT |
---|
13 | #include <malloc.h> |
---|
14 | #include <memory.h> |
---|
15 | #define alloca _alloca |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <config.h> |
---|
19 | |
---|
20 | #include <ctype.h> |
---|
21 | #include <iostream.h> |
---|
22 | |
---|
23 | #include "assert.h" |
---|
24 | |
---|
25 | #include "cf_defs.h" |
---|
26 | #include "gfops.h" |
---|
27 | #include "canonicalform.h" |
---|
28 | #include "parseutil.h" |
---|
29 | #include "variable.h" |
---|
30 | |
---|
31 | #ifndef BISONPP |
---|
32 | #define YYSTYPE ParseUtil |
---|
33 | #else |
---|
34 | #define YY_parse_USE_GOTO 1 |
---|
35 | #define YY_parse_STYPE ParseUtil |
---|
36 | #endif |
---|
37 | |
---|
38 | static char* readString( istream& ); |
---|
39 | |
---|
40 | #ifndef BISONPP |
---|
41 | void yyerror( char * s ); |
---|
42 | int yylex(); |
---|
43 | #endif |
---|
44 | |
---|
45 | static istream * defaultin = 0; |
---|
46 | |
---|
47 | static CanonicalForm * retvalue = 0; |
---|
48 | |
---|
49 | |
---|
50 | #ifndef YYLTYPE |
---|
51 | typedef |
---|
52 | struct yyltype |
---|
53 | { |
---|
54 | int timestamp; |
---|
55 | int first_line; |
---|
56 | int first_column; |
---|
57 | int last_line; |
---|
58 | int last_column; |
---|
59 | char *text; |
---|
60 | } |
---|
61 | yyltype; |
---|
62 | |
---|
63 | #define YYLTYPE yyltype |
---|
64 | #endif |
---|
65 | |
---|
66 | #ifndef YYSTYPE |
---|
67 | #define YYSTYPE int |
---|
68 | #endif |
---|
69 | #include <stdio.h> |
---|
70 | |
---|
71 | #ifndef __STDC__ |
---|
72 | #define const |
---|
73 | #endif |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | #define YYFINAL 25 |
---|
78 | #define YYFLAG -32768 |
---|
79 | #define YYNTBASE 13 |
---|
80 | |
---|
81 | #define YYTRANSLATE(x) ((unsigned)(x) <= 259 ? yytranslate[x] : 16) |
---|
82 | |
---|
83 | static const char yytranslate[] = { 0, |
---|
84 | 2, 2, 2, 2, 2, 2, 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, 11, |
---|
88 | 12, 6, 5, 2, 4, 2, 7, 2, 2, 2, |
---|
89 | 2, 2, 2, 2, 2, 2, 2, 2, 10, 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, 9, 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, 2, 2, 2, 2, 2, |
---|
98 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
99 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
100 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
101 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
102 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
103 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
104 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
105 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
106 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
107 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
108 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
109 | 2, 2, 2, 2, 2, 1, 2, 3, 8 |
---|
110 | }; |
---|
111 | |
---|
112 | #if YYDEBUG != 0 |
---|
113 | static const short yyprhs[] = { 0, |
---|
114 | 0, 1, 4, 6, 9, 11, 15, 19, 23, 27, |
---|
115 | 30, 33, 37 |
---|
116 | }; |
---|
117 | |
---|
118 | #endif |
---|
119 | |
---|
120 | static const short yyrhs[] = { -1, |
---|
121 | 13, 14, 0, 10, 0, 15, 10, 0, 3, 0, |
---|
122 | 15, 5, 15, 0, 15, 4, 15, 0, 15, 6, |
---|
123 | 15, 0, 15, 7, 15, 0, 4, 15, 0, 5, |
---|
124 | 15, 0, 15, 9, 3, 0, 11, 15, 12, 0 |
---|
125 | }; |
---|
126 | |
---|
127 | #if YYDEBUG != 0 |
---|
128 | static const short yyrline[] = { 0, |
---|
129 | 56, 57, 60, 61, 64, 65, 66, 67, 68, 69, |
---|
130 | 70, 71, 72 |
---|
131 | }; |
---|
132 | |
---|
133 | static const char * const yytname[] = { "$","error","$illegal.","NUM","'-'", |
---|
134 | "'+'","'*'","'/'","NEG","'^'","';'","'('","')'","input","line","exp","" |
---|
135 | }; |
---|
136 | #endif |
---|
137 | |
---|
138 | static const short yyr1[] = { 0, |
---|
139 | 13, 13, 14, 14, 15, 15, 15, 15, 15, 15, |
---|
140 | 15, 15, 15 |
---|
141 | }; |
---|
142 | |
---|
143 | static const short yyr2[] = { 0, |
---|
144 | 0, 2, 1, 2, 1, 3, 3, 3, 3, 2, |
---|
145 | 2, 3, 3 |
---|
146 | }; |
---|
147 | |
---|
148 | static const short yydefact[] = { 1, |
---|
149 | 0, 5, 0, 0, 3, 0, 2, 0, 10, 11, |
---|
150 | 0, 0, 0, 0, 0, 0, 4, 13, 7, 6, |
---|
151 | 8, 9, 12, 0, 0 |
---|
152 | }; |
---|
153 | |
---|
154 | static const short yydefgoto[] = { 1, |
---|
155 | 7, 8 |
---|
156 | }; |
---|
157 | |
---|
158 | static const short yypact[] = {-32768, |
---|
159 | 13,-32768, 3, 3,-32768, 3,-32768, 30, -7, -7, |
---|
160 | 21, 3, 3, 3, 3, 1,-32768,-32768, 35, 35, |
---|
161 | -7, -7,-32768, 5,-32768 |
---|
162 | }; |
---|
163 | |
---|
164 | static const short yypgoto[] = {-32768, |
---|
165 | -32768, -3 |
---|
166 | }; |
---|
167 | |
---|
168 | |
---|
169 | #define YYLAST 44 |
---|
170 | |
---|
171 | |
---|
172 | static const short yytable[] = { 9, |
---|
173 | 10, 16, 11, 23, 25, 2, 3, 4, 19, 20, |
---|
174 | 21, 22, 24, 6, 0, 2, 3, 4, 0, 0, |
---|
175 | 0, 0, 5, 6, 12, 13, 14, 15, 0, 16, |
---|
176 | 0, 0, 18, 12, 13, 14, 15, 0, 16, 17, |
---|
177 | 14, 15, 0, 16 |
---|
178 | }; |
---|
179 | |
---|
180 | static const short yycheck[] = { 3, |
---|
181 | 4, 9, 6, 3, 0, 3, 4, 5, 12, 13, |
---|
182 | 14, 15, 0, 11, -1, 3, 4, 5, -1, -1, |
---|
183 | -1, -1, 10, 11, 4, 5, 6, 7, -1, 9, |
---|
184 | -1, -1, 12, 4, 5, 6, 7, -1, 9, 10, |
---|
185 | 6, 7, -1, 9 |
---|
186 | }; |
---|
187 | /* -*-C-*- Note some compilers choke on comments on `#line' lines. */ |
---|
188 | #line 3 "/usr/local/lib/bison.simple" |
---|
189 | |
---|
190 | /* Skeleton output parser for bison, |
---|
191 | Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman |
---|
192 | |
---|
193 | This program is free software; you can redistribute it and/or modify |
---|
194 | it under the terms of the GNU General Public License as published by |
---|
195 | the Free Software Foundation; either version 1, or (at your option) |
---|
196 | any later version. |
---|
197 | |
---|
198 | This program is distributed in the hope that it will be useful, |
---|
199 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
200 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
201 | GNU General Public License for more details. |
---|
202 | |
---|
203 | You should have received a copy of the GNU General Public License |
---|
204 | along with this program; if not, write to the Free Software |
---|
205 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
---|
206 | |
---|
207 | |
---|
208 | #ifndef alloca |
---|
209 | #ifdef __GNUC__ |
---|
210 | #define alloca __builtin_alloca |
---|
211 | #else /* not GNU C. */ |
---|
212 | #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) |
---|
213 | #include <alloca.h> |
---|
214 | #else /* not sparc */ |
---|
215 | #if defined (MSDOS) && !defined (__TURBOC__) |
---|
216 | #include <malloc.h> |
---|
217 | #else /* not MSDOS, or __TURBOC__ */ |
---|
218 | #if defined(_AIX) |
---|
219 | #include <malloc.h> |
---|
220 | #pragma alloca |
---|
221 | #endif /* not _AIX */ |
---|
222 | #endif /* not MSDOS, or __TURBOC__ */ |
---|
223 | #endif /* not sparc. */ |
---|
224 | #endif /* not GNU C. */ |
---|
225 | #endif /* alloca not defined. */ |
---|
226 | |
---|
227 | /* This is the parser code that is written into each bison parser |
---|
228 | when the %semantic_parser declaration is not specified in the grammar. |
---|
229 | It was written by Richard Stallman by simplifying the hairy parser |
---|
230 | used when %semantic_parser is specified. */ |
---|
231 | |
---|
232 | /* Note: there must be only one dollar sign in this file. |
---|
233 | It is replaced by the list of actions, each action |
---|
234 | as one case of the switch. */ |
---|
235 | |
---|
236 | #define yyerrok (yyerrstatus = 0) |
---|
237 | #define yyclearin (yychar = YYEMPTY) |
---|
238 | #define YYEMPTY -2 |
---|
239 | #define YYEOF 0 |
---|
240 | #define YYACCEPT return(0) |
---|
241 | #define YYABORT return(1) |
---|
242 | #define YYERROR goto yyerrlab1 |
---|
243 | /* Like YYERROR except do call yyerror. |
---|
244 | This remains here temporarily to ease the |
---|
245 | transition to the new meaning of YYERROR, for GCC. |
---|
246 | Once GCC version 2 has supplanted version 1, this can go. */ |
---|
247 | #define YYFAIL goto yyerrlab |
---|
248 | #define YYRECOVERING() (!!yyerrstatus) |
---|
249 | #define YYBACKUP(token, value) \ |
---|
250 | do \ |
---|
251 | if (yychar == YYEMPTY && yylen == 1) \ |
---|
252 | { yychar = (token), yylval = (value); \ |
---|
253 | yychar1 = YYTRANSLATE (yychar); \ |
---|
254 | YYPOPSTACK; \ |
---|
255 | goto yybackup; \ |
---|
256 | } \ |
---|
257 | else \ |
---|
258 | { yyerror ("syntax error: cannot back up"); YYERROR; } \ |
---|
259 | while (0) |
---|
260 | |
---|
261 | #define YYTERROR 1 |
---|
262 | #define YYERRCODE 256 |
---|
263 | |
---|
264 | #ifndef YYPURE |
---|
265 | #define YYLEX yylex() |
---|
266 | #endif |
---|
267 | |
---|
268 | #ifdef YYPURE |
---|
269 | #ifdef YYLSP_NEEDED |
---|
270 | #define YYLEX yylex(&yylval, &yylloc) |
---|
271 | #else |
---|
272 | #define YYLEX yylex(&yylval) |
---|
273 | #endif |
---|
274 | #endif |
---|
275 | |
---|
276 | /* If nonreentrant, generate the variables here */ |
---|
277 | |
---|
278 | #ifndef YYPURE |
---|
279 | |
---|
280 | int yychar; /* the lookahead symbol */ |
---|
281 | YYSTYPE yylval; /* the semantic value of the */ |
---|
282 | /* lookahead symbol */ |
---|
283 | |
---|
284 | #ifdef YYLSP_NEEDED |
---|
285 | YYLTYPE yylloc; /* location data for the lookahead */ |
---|
286 | /* symbol */ |
---|
287 | #endif |
---|
288 | |
---|
289 | int yynerrs; /* number of parse errors so far */ |
---|
290 | #endif /* not YYPURE */ |
---|
291 | |
---|
292 | #if YYDEBUG != 0 |
---|
293 | int yydebug; /* nonzero means print parse trace */ |
---|
294 | /* Since this is uninitialized, it does not stop multiple parsers |
---|
295 | from coexisting. */ |
---|
296 | #endif |
---|
297 | |
---|
298 | /* YYINITDEPTH indicates the initial size of the parser's stacks */ |
---|
299 | |
---|
300 | #ifndef YYINITDEPTH |
---|
301 | #define YYINITDEPTH 200 |
---|
302 | #endif |
---|
303 | |
---|
304 | /* YYMAXDEPTH is the maximum size the stacks can grow to |
---|
305 | (effective only if the built-in stack extension method is used). */ |
---|
306 | |
---|
307 | #if YYMAXDEPTH == 0 |
---|
308 | #undef YYMAXDEPTH |
---|
309 | #endif |
---|
310 | |
---|
311 | #ifndef YYMAXDEPTH |
---|
312 | #define YYMAXDEPTH 10000 |
---|
313 | #endif |
---|
314 | |
---|
315 | #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ |
---|
316 | #define __yy_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT) |
---|
317 | #else /* not GNU C or C++ */ |
---|
318 | #ifndef __cplusplus |
---|
319 | |
---|
320 | /* This is the most reliable way to avoid incompatibilities |
---|
321 | in available built-in functions on various systems. */ |
---|
322 | static void |
---|
323 | __yy_bcopy (from, to, count) |
---|
324 | char *from; |
---|
325 | char *to; |
---|
326 | int count; |
---|
327 | { |
---|
328 | register char *f = from; |
---|
329 | register char *t = to; |
---|
330 | register int i = count; |
---|
331 | |
---|
332 | while (i-- > 0) |
---|
333 | *t++ = *f++; |
---|
334 | } |
---|
335 | |
---|
336 | #else /* __cplusplus */ |
---|
337 | |
---|
338 | /* This is the most reliable way to avoid incompatibilities |
---|
339 | in available built-in functions on various systems. */ |
---|
340 | static void |
---|
341 | __yy_bcopy (char *from, char *to, int count) |
---|
342 | { |
---|
343 | register char *f = from; |
---|
344 | register char *t = to; |
---|
345 | register int i = count; |
---|
346 | |
---|
347 | while (i-- > 0) |
---|
348 | *t++ = *f++; |
---|
349 | } |
---|
350 | |
---|
351 | #endif |
---|
352 | #endif |
---|
353 | |
---|
354 | #line 169 "/usr/local/lib/bison.simple" |
---|
355 | int |
---|
356 | yyparse() |
---|
357 | { |
---|
358 | register int yystate; |
---|
359 | register int yyn; |
---|
360 | register short *yyssp; |
---|
361 | register YYSTYPE *yyvsp; |
---|
362 | int yyerrstatus; /* number of tokens to shift before error messages enabled */ |
---|
363 | int yychar1; /* lookahead token as an internal (translated) token number */ |
---|
364 | |
---|
365 | short yyssa[YYINITDEPTH]; /* the state stack */ |
---|
366 | YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ |
---|
367 | |
---|
368 | short *yyss = yyssa; /* refer to the stacks thru separate pointers */ |
---|
369 | YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ |
---|
370 | |
---|
371 | #ifdef YYLSP_NEEDED |
---|
372 | YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ |
---|
373 | YYLTYPE *yyls = yylsa; |
---|
374 | YYLTYPE *yylsp; |
---|
375 | |
---|
376 | #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) |
---|
377 | #else |
---|
378 | #define YYPOPSTACK (yyvsp--, yyssp--) |
---|
379 | #endif |
---|
380 | |
---|
381 | int yystacksize = YYINITDEPTH; |
---|
382 | |
---|
383 | #ifdef YYPURE |
---|
384 | int yychar; |
---|
385 | YYSTYPE yylval; |
---|
386 | int yynerrs; |
---|
387 | #ifdef YYLSP_NEEDED |
---|
388 | YYLTYPE yylloc; |
---|
389 | #endif |
---|
390 | #endif |
---|
391 | |
---|
392 | YYSTYPE yyval; /* the variable used to return */ |
---|
393 | /* semantic values from the action */ |
---|
394 | /* routines */ |
---|
395 | |
---|
396 | int yylen; |
---|
397 | |
---|
398 | #if YYDEBUG != 0 |
---|
399 | if (yydebug) |
---|
400 | fprintf(stderr, "Starting parse\n"); |
---|
401 | #endif |
---|
402 | |
---|
403 | yystate = 0; |
---|
404 | yyerrstatus = 0; |
---|
405 | yynerrs = 0; |
---|
406 | yychar = YYEMPTY; /* Cause a token to be read. */ |
---|
407 | |
---|
408 | /* Initialize stack pointers. |
---|
409 | Waste one element of value and location stack |
---|
410 | so that they stay on the same level as the state stack. */ |
---|
411 | |
---|
412 | yyssp = yyss - 1; |
---|
413 | yyvsp = yyvs; |
---|
414 | #ifdef YYLSP_NEEDED |
---|
415 | yylsp = yyls; |
---|
416 | #endif |
---|
417 | |
---|
418 | /* Push a new state, which is found in yystate . */ |
---|
419 | /* In all cases, when you get here, the value and location stacks |
---|
420 | have just been pushed. so pushing a state here evens the stacks. */ |
---|
421 | yynewstate: |
---|
422 | |
---|
423 | *++yyssp = yystate; |
---|
424 | |
---|
425 | if (yyssp >= yyss + yystacksize - 1) |
---|
426 | { |
---|
427 | /* Give user a chance to reallocate the stack */ |
---|
428 | /* Use copies of these so that the &'s don't force the real ones into memory. */ |
---|
429 | YYSTYPE *yyvs1 = yyvs; |
---|
430 | short *yyss1 = yyss; |
---|
431 | #ifdef YYLSP_NEEDED |
---|
432 | YYLTYPE *yyls1 = yyls; |
---|
433 | #endif |
---|
434 | |
---|
435 | /* Get the current used size of the three stacks, in elements. */ |
---|
436 | int size = yyssp - yyss + 1; |
---|
437 | |
---|
438 | #ifdef yyoverflow |
---|
439 | /* Each stack pointer address is followed by the size of |
---|
440 | the data in use in that stack, in bytes. */ |
---|
441 | yyoverflow("parser stack overflow", |
---|
442 | &yyss1, size * sizeof (*yyssp), |
---|
443 | &yyvs1, size * sizeof (*yyvsp), |
---|
444 | #ifdef YYLSP_NEEDED |
---|
445 | &yyls1, size * sizeof (*yylsp), |
---|
446 | #endif |
---|
447 | &yystacksize); |
---|
448 | |
---|
449 | yyss = yyss1; yyvs = yyvs1; |
---|
450 | #ifdef YYLSP_NEEDED |
---|
451 | yyls = yyls1; |
---|
452 | #endif |
---|
453 | #else /* no yyoverflow */ |
---|
454 | /* Extend the stack our own way. */ |
---|
455 | if (yystacksize >= YYMAXDEPTH) |
---|
456 | { |
---|
457 | yyerror("parser stack overflow"); |
---|
458 | return 2; |
---|
459 | } |
---|
460 | yystacksize *= 2; |
---|
461 | if (yystacksize > YYMAXDEPTH) |
---|
462 | yystacksize = YYMAXDEPTH; |
---|
463 | yyss = (short *) alloca (yystacksize * sizeof (*yyssp)); |
---|
464 | __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp)); |
---|
465 | yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp)); |
---|
466 | __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp)); |
---|
467 | #ifdef YYLSP_NEEDED |
---|
468 | yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp)); |
---|
469 | __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp)); |
---|
470 | #endif |
---|
471 | #endif /* no yyoverflow */ |
---|
472 | |
---|
473 | yyssp = yyss + size - 1; |
---|
474 | yyvsp = yyvs + size - 1; |
---|
475 | #ifdef YYLSP_NEEDED |
---|
476 | yylsp = yyls + size - 1; |
---|
477 | #endif |
---|
478 | |
---|
479 | #if YYDEBUG != 0 |
---|
480 | if (yydebug) |
---|
481 | fprintf(stderr, "Stack size increased to %d\n", yystacksize); |
---|
482 | #endif |
---|
483 | |
---|
484 | if (yyssp >= yyss + yystacksize - 1) |
---|
485 | YYABORT; |
---|
486 | } |
---|
487 | |
---|
488 | #if YYDEBUG != 0 |
---|
489 | if (yydebug) |
---|
490 | fprintf(stderr, "Entering state %d\n", yystate); |
---|
491 | #endif |
---|
492 | |
---|
493 | yybackup: |
---|
494 | |
---|
495 | /* Do appropriate processing given the current state. */ |
---|
496 | /* Read a lookahead token if we need one and don't already have one. */ |
---|
497 | /* yyresume: */ |
---|
498 | |
---|
499 | /* First try to decide what to do without reference to lookahead token. */ |
---|
500 | |
---|
501 | yyn = yypact[yystate]; |
---|
502 | if (yyn == YYFLAG) |
---|
503 | goto yydefault; |
---|
504 | |
---|
505 | /* Not known => get a lookahead token if don't already have one. */ |
---|
506 | |
---|
507 | /* yychar is either YYEMPTY or YYEOF |
---|
508 | or a valid token in external form. */ |
---|
509 | |
---|
510 | if (yychar == YYEMPTY) |
---|
511 | { |
---|
512 | #if YYDEBUG != 0 |
---|
513 | if (yydebug) |
---|
514 | fprintf(stderr, "Reading a token: "); |
---|
515 | #endif |
---|
516 | yychar = YYLEX; |
---|
517 | } |
---|
518 | |
---|
519 | /* Convert token to internal form (in yychar1) for indexing tables with */ |
---|
520 | |
---|
521 | if (yychar <= 0) /* This means end of input. */ |
---|
522 | { |
---|
523 | yychar1 = 0; |
---|
524 | yychar = YYEOF; /* Don't call YYLEX any more */ |
---|
525 | |
---|
526 | #if YYDEBUG != 0 |
---|
527 | if (yydebug) |
---|
528 | fprintf(stderr, "Now at end of input.\n"); |
---|
529 | #endif |
---|
530 | } |
---|
531 | else |
---|
532 | { |
---|
533 | yychar1 = YYTRANSLATE(yychar); |
---|
534 | |
---|
535 | #if YYDEBUG != 0 |
---|
536 | if (yydebug) |
---|
537 | { |
---|
538 | fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); |
---|
539 | /* Give the individual parser a way to print the precise meaning |
---|
540 | of a token, for further debugging info. */ |
---|
541 | #ifdef YYPRINT |
---|
542 | YYPRINT (stderr, yychar, yylval); |
---|
543 | #endif |
---|
544 | fprintf (stderr, ")\n"); |
---|
545 | } |
---|
546 | #endif |
---|
547 | } |
---|
548 | |
---|
549 | yyn += yychar1; |
---|
550 | if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) |
---|
551 | goto yydefault; |
---|
552 | |
---|
553 | yyn = yytable[yyn]; |
---|
554 | |
---|
555 | /* yyn is what to do for this token type in this state. |
---|
556 | Negative => reduce, -yyn is rule number. |
---|
557 | Positive => shift, yyn is new state. |
---|
558 | New state is final state => don't bother to shift, |
---|
559 | just return success. |
---|
560 | 0, or most negative number => error. */ |
---|
561 | |
---|
562 | if (yyn < 0) |
---|
563 | { |
---|
564 | if (yyn == YYFLAG) |
---|
565 | goto yyerrlab; |
---|
566 | yyn = -yyn; |
---|
567 | goto yyreduce; |
---|
568 | } |
---|
569 | else if (yyn == 0) |
---|
570 | goto yyerrlab; |
---|
571 | |
---|
572 | if (yyn == YYFINAL) |
---|
573 | YYACCEPT; |
---|
574 | |
---|
575 | /* Shift the lookahead token. */ |
---|
576 | |
---|
577 | #if YYDEBUG != 0 |
---|
578 | if (yydebug) |
---|
579 | fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); |
---|
580 | #endif |
---|
581 | |
---|
582 | /* Discard the token being shifted unless it is eof. */ |
---|
583 | if (yychar != YYEOF) |
---|
584 | yychar = YYEMPTY; |
---|
585 | |
---|
586 | *++yyvsp = yylval; |
---|
587 | #ifdef YYLSP_NEEDED |
---|
588 | *++yylsp = yylloc; |
---|
589 | #endif |
---|
590 | |
---|
591 | /* count tokens shifted since error; after three, turn off error status. */ |
---|
592 | if (yyerrstatus) yyerrstatus--; |
---|
593 | |
---|
594 | yystate = yyn; |
---|
595 | goto yynewstate; |
---|
596 | |
---|
597 | /* Do the default action for the current state. */ |
---|
598 | yydefault: |
---|
599 | |
---|
600 | yyn = yydefact[yystate]; |
---|
601 | if (yyn == 0) |
---|
602 | goto yyerrlab; |
---|
603 | |
---|
604 | /* Do a reduction. yyn is the number of a rule to reduce with. */ |
---|
605 | yyreduce: |
---|
606 | yylen = yyr2[yyn]; |
---|
607 | yyval = yyvsp[1-yylen]; /* implement default value of the action */ |
---|
608 | |
---|
609 | #if YYDEBUG != 0 |
---|
610 | if (yydebug) |
---|
611 | { |
---|
612 | int i; |
---|
613 | |
---|
614 | fprintf (stderr, "Reducing via rule %d (line %d), ", |
---|
615 | yyn, yyrline[yyn]); |
---|
616 | |
---|
617 | /* Print the symboles being reduced, and their result. */ |
---|
618 | for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) |
---|
619 | fprintf (stderr, "%s ", yytname[yyrhs[i]]); |
---|
620 | fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); |
---|
621 | } |
---|
622 | #endif |
---|
623 | |
---|
624 | |
---|
625 | switch (yyn) { |
---|
626 | |
---|
627 | case 4: |
---|
628 | #line 61 "../factory/readcf.y" |
---|
629 | { *retvalue = yyvsp[-1].getval(); return 0; ; |
---|
630 | break;} |
---|
631 | case 5: |
---|
632 | #line 64 "../factory/readcf.y" |
---|
633 | { yyval = yyvsp[0]; ; |
---|
634 | break;} |
---|
635 | case 6: |
---|
636 | #line 65 "../factory/readcf.y" |
---|
637 | { yyval = yyvsp[-2].getval() + yyvsp[0].getval(); ; |
---|
638 | break;} |
---|
639 | case 7: |
---|
640 | #line 66 "../factory/readcf.y" |
---|
641 | { yyval = yyvsp[-2].getval() - yyvsp[0].getval(); ; |
---|
642 | break;} |
---|
643 | case 8: |
---|
644 | #line 67 "../factory/readcf.y" |
---|
645 | { yyval = yyvsp[-2].getval() * yyvsp[0].getval(); ; |
---|
646 | break;} |
---|
647 | case 9: |
---|
648 | #line 68 "../factory/readcf.y" |
---|
649 | { yyval = yyvsp[-2].getval() / yyvsp[0].getval(); ; |
---|
650 | break;} |
---|
651 | case 10: |
---|
652 | #line 69 "../factory/readcf.y" |
---|
653 | { yyval = -yyvsp[0].getval(); ; |
---|
654 | break;} |
---|
655 | case 11: |
---|
656 | #line 70 "../factory/readcf.y" |
---|
657 | { yyval = yyvsp[0].getval(); ; |
---|
658 | break;} |
---|
659 | case 12: |
---|
660 | #line 71 "../factory/readcf.y" |
---|
661 | { yyval = power( yyvsp[-2].getval(), yyvsp[0].getintval() ); ; |
---|
662 | break;} |
---|
663 | case 13: |
---|
664 | #line 72 "../factory/readcf.y" |
---|
665 | { yyval = yyvsp[-1].getval(); ; |
---|
666 | break;} |
---|
667 | } |
---|
668 | /* the action file gets copied in in place of this dollarsign */ |
---|
669 | #line 440 "/usr/local/lib/bison.simple" |
---|
670 | |
---|
671 | yyvsp -= yylen; |
---|
672 | yyssp -= yylen; |
---|
673 | #ifdef YYLSP_NEEDED |
---|
674 | yylsp -= yylen; |
---|
675 | #endif |
---|
676 | |
---|
677 | #if YYDEBUG != 0 |
---|
678 | if (yydebug) |
---|
679 | { |
---|
680 | short *ssp1 = yyss - 1; |
---|
681 | fprintf (stderr, "state stack now"); |
---|
682 | while (ssp1 != yyssp) |
---|
683 | fprintf (stderr, " %d", *++ssp1); |
---|
684 | fprintf (stderr, "\n"); |
---|
685 | } |
---|
686 | #endif |
---|
687 | |
---|
688 | *++yyvsp = yyval; |
---|
689 | |
---|
690 | #ifdef YYLSP_NEEDED |
---|
691 | yylsp++; |
---|
692 | if (yylen == 0) |
---|
693 | { |
---|
694 | yylsp->first_line = yylloc.first_line; |
---|
695 | yylsp->first_column = yylloc.first_column; |
---|
696 | yylsp->last_line = (yylsp-1)->last_line; |
---|
697 | yylsp->last_column = (yylsp-1)->last_column; |
---|
698 | yylsp->text = 0; |
---|
699 | } |
---|
700 | else |
---|
701 | { |
---|
702 | yylsp->last_line = (yylsp+yylen-1)->last_line; |
---|
703 | yylsp->last_column = (yylsp+yylen-1)->last_column; |
---|
704 | } |
---|
705 | #endif |
---|
706 | |
---|
707 | /* Now "shift" the result of the reduction. |
---|
708 | Determine what state that goes to, |
---|
709 | based on the state we popped back to |
---|
710 | and the rule number reduced by. */ |
---|
711 | |
---|
712 | yyn = yyr1[yyn]; |
---|
713 | |
---|
714 | yystate = yypgoto[yyn - YYNTBASE] + *yyssp; |
---|
715 | if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) |
---|
716 | yystate = yytable[yystate]; |
---|
717 | else |
---|
718 | yystate = yydefgoto[yyn - YYNTBASE]; |
---|
719 | |
---|
720 | goto yynewstate; |
---|
721 | |
---|
722 | yyerrlab: /* here on detecting error */ |
---|
723 | |
---|
724 | if (! yyerrstatus) |
---|
725 | /* If not already recovering from an error, report this error. */ |
---|
726 | { |
---|
727 | ++yynerrs; |
---|
728 | |
---|
729 | #ifdef YYERROR_VERBOSE |
---|
730 | yyn = yypact[yystate]; |
---|
731 | |
---|
732 | if (yyn > YYFLAG && yyn < YYLAST) |
---|
733 | { |
---|
734 | int size = 0; |
---|
735 | char *msg; |
---|
736 | int x, count; |
---|
737 | |
---|
738 | count = 0; |
---|
739 | for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++) |
---|
740 | if (yycheck[x + yyn] == x) |
---|
741 | size += strlen(yytname[x]) + 15, count++; |
---|
742 | msg = (char *) malloc(size + 15); |
---|
743 | if (msg != 0) |
---|
744 | { |
---|
745 | strcpy(msg, "parse error"); |
---|
746 | |
---|
747 | if (count < 5) |
---|
748 | { |
---|
749 | count = 0; |
---|
750 | for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++) |
---|
751 | if (yycheck[x + yyn] == x) |
---|
752 | { |
---|
753 | strcat(msg, count == 0 ? ", expecting `" : " or `"); |
---|
754 | strcat(msg, yytname[x]); |
---|
755 | strcat(msg, "'"); |
---|
756 | count++; |
---|
757 | } |
---|
758 | } |
---|
759 | yyerror(msg); |
---|
760 | free(msg); |
---|
761 | } |
---|
762 | else |
---|
763 | yyerror ("parse error; also virtual memory exceeded"); |
---|
764 | } |
---|
765 | else |
---|
766 | #endif /* YYERROR_VERBOSE */ |
---|
767 | yyerror("parse error"); |
---|
768 | } |
---|
769 | |
---|
770 | yyerrlab1: /* here on error raised explicitly by an action */ |
---|
771 | |
---|
772 | if (yyerrstatus == 3) |
---|
773 | { |
---|
774 | /* if just tried and failed to reuse lookahead token after an error, discard it. */ |
---|
775 | |
---|
776 | /* return failure if at end of input */ |
---|
777 | if (yychar == YYEOF) |
---|
778 | YYABORT; |
---|
779 | |
---|
780 | #if YYDEBUG != 0 |
---|
781 | if (yydebug) |
---|
782 | fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); |
---|
783 | #endif |
---|
784 | |
---|
785 | yychar = YYEMPTY; |
---|
786 | } |
---|
787 | |
---|
788 | /* Else will try to reuse lookahead token |
---|
789 | after shifting the error token. */ |
---|
790 | |
---|
791 | yyerrstatus = 3; /* Each real token shifted decrements this */ |
---|
792 | |
---|
793 | goto yyerrhandle; |
---|
794 | |
---|
795 | yyerrdefault: /* current state does not do anything special for the error token. */ |
---|
796 | |
---|
797 | #if 0 |
---|
798 | /* This is wrong; only states that explicitly want error tokens |
---|
799 | should shift them. */ |
---|
800 | yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ |
---|
801 | if (yyn) goto yydefault; |
---|
802 | #endif |
---|
803 | |
---|
804 | yyerrpop: /* pop the current state because it cannot handle the error token */ |
---|
805 | |
---|
806 | if (yyssp == yyss) YYABORT; |
---|
807 | yyvsp--; |
---|
808 | yystate = *--yyssp; |
---|
809 | #ifdef YYLSP_NEEDED |
---|
810 | yylsp--; |
---|
811 | #endif |
---|
812 | |
---|
813 | #if YYDEBUG != 0 |
---|
814 | if (yydebug) |
---|
815 | { |
---|
816 | short *ssp1 = yyss - 1; |
---|
817 | fprintf (stderr, "Error: state stack now"); |
---|
818 | while (ssp1 != yyssp) |
---|
819 | fprintf (stderr, " %d", *++ssp1); |
---|
820 | fprintf (stderr, "\n"); |
---|
821 | } |
---|
822 | #endif |
---|
823 | |
---|
824 | yyerrhandle: |
---|
825 | |
---|
826 | yyn = yypact[yystate]; |
---|
827 | if (yyn == YYFLAG) |
---|
828 | goto yyerrdefault; |
---|
829 | |
---|
830 | yyn += YYTERROR; |
---|
831 | if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) |
---|
832 | goto yyerrdefault; |
---|
833 | |
---|
834 | yyn = yytable[yyn]; |
---|
835 | if (yyn < 0) |
---|
836 | { |
---|
837 | if (yyn == YYFLAG) |
---|
838 | goto yyerrpop; |
---|
839 | yyn = -yyn; |
---|
840 | goto yyreduce; |
---|
841 | } |
---|
842 | else if (yyn == 0) |
---|
843 | goto yyerrpop; |
---|
844 | |
---|
845 | if (yyn == YYFINAL) |
---|
846 | YYACCEPT; |
---|
847 | |
---|
848 | #if YYDEBUG != 0 |
---|
849 | if (yydebug) |
---|
850 | fprintf(stderr, "Shifting error token, "); |
---|
851 | #endif |
---|
852 | |
---|
853 | *++yyvsp = yylval; |
---|
854 | #ifdef YYLSP_NEEDED |
---|
855 | *++yylsp = yylloc; |
---|
856 | #endif |
---|
857 | |
---|
858 | yystate = yyn; |
---|
859 | goto yynewstate; |
---|
860 | } |
---|
861 | #line 75 "../factory/readcf.y" |
---|
862 | |
---|
863 | |
---|
864 | #ifdef BISONPP |
---|
865 | void YY_parse_CLASS::yyerror( char * s ) |
---|
866 | #else |
---|
867 | void yyerror( char * s ) |
---|
868 | #endif |
---|
869 | { |
---|
870 | cerr << s << endl; |
---|
871 | } |
---|
872 | |
---|
873 | #ifdef BISONPP |
---|
874 | int YY_parse_CLASS::yylex() |
---|
875 | #else |
---|
876 | int yylex() |
---|
877 | #endif |
---|
878 | { |
---|
879 | int c; |
---|
880 | |
---|
881 | while ((c = defaultin->get()) == ' ' || c == '\t' || c == '\n' ) ; |
---|
882 | if ( isdigit( c ) ) { |
---|
883 | defaultin->putback( c ); |
---|
884 | yylval = ParseUtil( readString( *defaultin ) ); |
---|
885 | return NUM; |
---|
886 | } |
---|
887 | else if ( isalpha( c ) ) { |
---|
888 | // look for generators of GF(q) |
---|
889 | if ( getCharacteristic() > 0 && getGFDegree() > 1 && c == gf_name ) { |
---|
890 | #ifdef BISONPP |
---|
891 | this->yylval = getGFGenerator(); |
---|
892 | #else |
---|
893 | yylval = getGFGenerator(); |
---|
894 | #endif |
---|
895 | } |
---|
896 | else if ( c == getDefaultVarName() ) { |
---|
897 | int cc; |
---|
898 | cc = defaultin->get(); |
---|
899 | if ( cc == '_' ) { |
---|
900 | ParseUtil index( readString( *defaultin ) ); |
---|
901 | #ifdef BISONPP |
---|
902 | this->yylval = Variable( index.getintval() ); |
---|
903 | #else |
---|
904 | yylval = Variable( index.getintval() ); |
---|
905 | #endif |
---|
906 | } |
---|
907 | else { |
---|
908 | defaultin->putback( cc ); |
---|
909 | #ifdef BISONPP |
---|
910 | this->yylval = Variable( (char)c ); |
---|
911 | #else |
---|
912 | yylval = Variable( (char)c ); |
---|
913 | #endif |
---|
914 | } |
---|
915 | } |
---|
916 | else { |
---|
917 | #ifdef BISONPP |
---|
918 | this->yylval = Variable( (char)c ); |
---|
919 | #else |
---|
920 | yylval = Variable( (char)c ); |
---|
921 | #endif |
---|
922 | } |
---|
923 | return NUM; |
---|
924 | } |
---|
925 | return c; |
---|
926 | } |
---|
927 | |
---|
928 | CanonicalForm readCF( istream& str ) |
---|
929 | { |
---|
930 | CanonicalForm theRetvalue; |
---|
931 | retvalue = new CanonicalForm(); |
---|
932 | #ifdef BISONPP |
---|
933 | YY_parse_CLASS my_parser; |
---|
934 | defaultin = &str; |
---|
935 | if ( my_parser.yyparse() == 0 ) { |
---|
936 | theRetvalue = *retvalue; |
---|
937 | delete retvalue; |
---|
938 | return theRetvalue; |
---|
939 | } |
---|
940 | else { |
---|
941 | delete retvalue; |
---|
942 | return 0; |
---|
943 | } |
---|
944 | #else |
---|
945 | defaultin = &str; |
---|
946 | if ( yyparse() == 0 ) { |
---|
947 | theRetvalue = *retvalue; |
---|
948 | delete retvalue; |
---|
949 | return theRetvalue; |
---|
950 | } |
---|
951 | else { |
---|
952 | delete retvalue; |
---|
953 | return 0; |
---|
954 | } |
---|
955 | #endif |
---|
956 | } |
---|
957 | |
---|
958 | char* readString( istream& s ) |
---|
959 | { |
---|
960 | static char * buffer = 0; |
---|
961 | static int bufsize = 0; |
---|
962 | |
---|
963 | if ( buffer == 0 ) { |
---|
964 | bufsize = 10000; |
---|
965 | buffer = new char[bufsize]; |
---|
966 | } |
---|
967 | int i = 0, c, goon = 1; |
---|
968 | while ( goon ) { |
---|
969 | while ( isdigit( c = s.get() ) && i < bufsize - 2 ) { |
---|
970 | buffer[i] = c; |
---|
971 | i++; |
---|
972 | } |
---|
973 | if ( isdigit( c ) ) { |
---|
974 | bufsize += 1000; |
---|
975 | char * newbuffer = (char*)memcpy( new char[bufsize], buffer, bufsize - 1000 ); |
---|
976 | delete [] buffer; |
---|
977 | buffer = newbuffer; |
---|
978 | buffer[i] = c; |
---|
979 | i++; |
---|
980 | } |
---|
981 | else { |
---|
982 | goon = 0; |
---|
983 | buffer[i] = '\0'; |
---|
984 | s.putback( c ); |
---|
985 | } |
---|
986 | } |
---|
987 | return buffer; |
---|
988 | } |
---|