1 /* $NetBSD: calc2.tab.c,v 1.1.1.3 2016/01/09 21:59:46 christos Exp $ */
2
3 /* original parser id follows */
4 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
5 /* (use YYMAJOR/YYMINOR for ifdefs dependent of parser version) */
6
7 #define YYBYACC 1
8 #define YYMAJOR 1
9 #define YYMINOR 9
10 #define YYCHECK "yyyymmdd"
11
12 #define YYEMPTY (-1)
13 #define yyclearin (yychar = YYEMPTY)
14 #define yyerrok (yyerrflag = 0)
15 #define YYRECOVERING() (yyerrflag != 0)
16 #define YYENOMEM (-2)
17 #define YYEOF 0
18 #undef YYBTYACC
19 #define YYBTYACC 0
20 #define YYDEBUGSTR YYPREFIX "debug"
21
22 #ifndef yyparse
23 #define yyparse calc2_parse
24 #endif /* yyparse */
25
26 #ifndef yylex
27 #define yylex calc2_lex
28 #endif /* yylex */
29
30 #ifndef yyerror
31 #define yyerror calc2_error
32 #endif /* yyerror */
33
34 #ifndef yychar
35 #define yychar calc2_char
36 #endif /* yychar */
37
38 #ifndef yyval
39 #define yyval calc2_val
40 #endif /* yyval */
41
42 #ifndef yylval
43 #define yylval calc2_lval
44 #endif /* yylval */
45
46 #ifndef yydebug
47 #define yydebug calc2_debug
48 #endif /* yydebug */
49
50 #ifndef yynerrs
51 #define yynerrs calc2_nerrs
52 #endif /* yynerrs */
53
54 #ifndef yyerrflag
55 #define yyerrflag calc2_errflag
56 #endif /* yyerrflag */
57
58 #ifndef yylhs
59 #define yylhs calc2_lhs
60 #endif /* yylhs */
61
62 #ifndef yylen
63 #define yylen calc2_len
64 #endif /* yylen */
65
66 #ifndef yydefred
67 #define yydefred calc2_defred
68 #endif /* yydefred */
69
70 #ifndef yystos
71 #define yystos calc2_stos
72 #endif /* yystos */
73
74 #ifndef yydgoto
75 #define yydgoto calc2_dgoto
76 #endif /* yydgoto */
77
78 #ifndef yysindex
79 #define yysindex calc2_sindex
80 #endif /* yysindex */
81
82 #ifndef yyrindex
83 #define yyrindex calc2_rindex
84 #endif /* yyrindex */
85
86 #ifndef yygindex
87 #define yygindex calc2_gindex
88 #endif /* yygindex */
89
90 #ifndef yytable
91 #define yytable calc2_table
92 #endif /* yytable */
93
94 #ifndef yycheck
95 #define yycheck calc2_check
96 #endif /* yycheck */
97
98 #ifndef yyname
99 #define yyname calc2_name
100 #endif /* yyname */
101
102 #ifndef yyrule
103 #define yyrule calc2_rule
104 #endif /* yyrule */
105
106 #if YYBTYACC
107
108 #ifndef yycindex
109 #define yycindex calc2_cindex
110 #endif /* yycindex */
111
112 #ifndef yyctable
113 #define yyctable calc2_ctable
114 #endif /* yyctable */
115
116 #endif /* YYBTYACC */
117
118 #define YYPREFIX "calc2_"
119
120 #define YYPURE 0
121
122 #line 7 "calc2.y"
123 # include <stdio.h>
124 # include <ctype.h>
125
126 #ifdef YYBISON
127 #define YYLEX_PARAM base
128 #define YYLEX_DECL() yylex(int *YYLEX_PARAM)
129 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
130 int YYLEX_DECL();
131 static void YYERROR_DECL();
132 #endif
133
134 #line 133 "calc2.tab.c"
135
136 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
137 /* Default: YYSTYPE is the semantic value type. */
138 typedef int YYSTYPE;
139 # define YYSTYPE_IS_DECLARED 1
140 #endif
141
142 /* compatibility with bison */
143 #ifdef YYPARSE_PARAM
144 /* compatibility with FreeBSD */
145 # ifdef YYPARSE_PARAM_TYPE
146 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
147 # else
148 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
149 # endif
150 #else
151 # define YYPARSE_DECL() yyparse(int regs[26], int *base)
152 #endif
153
154 /* Parameters sent to lex. */
155 #ifdef YYLEX_PARAM
156 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
157 # define YYLEX yylex(YYLEX_PARAM)
158 #else
159 # define YYLEX_DECL() yylex(int *base)
160 # define YYLEX yylex(base)
161 #endif
162
163 /* Parameters sent to yyerror. */
164 #ifndef YYERROR_DECL
165 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
166 #endif
167 #ifndef YYERROR_CALL
168 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
169 #endif
170
171 extern int YYPARSE_DECL();
172
173 #define DIGIT 257
174 #define LETTER 258
175 #define UMINUS 259
176 #define YYERRCODE 256
177 typedef short YYINT;
178 static const YYINT calc2_lhs[] = { -1,
179 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
180 2, 2, 2, 2, 2, 2, 3, 3,
181 };
182 static const YYINT calc2_len[] = { 2,
183 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
184 3, 3, 3, 2, 1, 1, 1, 2,
185 };
186 static const YYINT calc2_defred[] = { 1,
187 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
188 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
189 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
190 10, 11,
191 };
192 static const YYINT calc2_stos[] = { 0,
193 261, 256, 257, 258, 45, 40, 262, 263, 264, 10,
194 61, 258, 263, 263, 10, 124, 38, 43, 45, 42,
195 47, 37, 257, 263, 41, 263, 263, 263, 263, 263,
196 263, 263,
197 };
198 static const YYINT calc2_dgoto[] = { 1,
199 7, 8, 9,
200 };
201 static const YYINT calc2_sindex[] = { 0,
202 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
203 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
204 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
205 0, 0,
206 };
207 static const YYINT calc2_rindex[] = { 0,
208 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
211 0, 0,
212 };
213 #if YYBTYACC
214 static const YYINT calc2_cindex[] = { 0,
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
216 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
218 0, 0,
219 };
220 #endif
221 static const YYINT calc2_gindex[] = { 0,
222 0, 65, 0,
223 };
224 #define YYTABLESIZE 220
225 static const YYINT calc2_table[] = { 6,
226 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
227 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
228 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
229 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
230 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
231 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
232 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
233 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
234 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
235 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
236 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
237 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
238 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
239 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
240 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
247 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
248 };
249 static const YYINT calc2_check[] = { 40,
250 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
251 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
252 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
253 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
254 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
255 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
256 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
257 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
258 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
259 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
260 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
261 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
262 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
263 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
264 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
265 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
266 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
267 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
268 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
269 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
270 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
271 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
272 };
273 #if YYBTYACC
274 static const YYINT calc2_ctable[] = { -1,
275 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
276 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
277 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
278 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
280 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
281 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
282 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
283 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
284 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
285 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
286 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
287 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
288 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
289 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
290 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
291 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
292 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
293 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
294 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
295 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
296 -1, -1, -1, -1, -1, -1, -1, -1, -1,
297 };
298 #endif
299 #define YYFINAL 1
300 #ifndef YYDEBUG
301 #define YYDEBUG 0
302 #endif
303 #define YYMAXTOKEN 259
304 #define YYUNDFTOKEN 265
305 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
306 #if YYDEBUG
307 static const char *const calc2_name[] = {
308
309 "$end",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
310 0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0,
311 0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
312 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,0,0,0,
313 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
314 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
315 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
316 0,0,"error","DIGIT","LETTER","UMINUS","$accept","list","stat","expr","number",
317 "illegal-symbol",
318 };
319 static const char *const calc2_rule[] = {
320 "$accept : list",
321 "list :",
322 "list : list stat '\\n'",
323 "list : list error '\\n'",
324 "stat : expr",
325 "stat : LETTER '=' expr",
326 "expr : '(' expr ')'",
327 "expr : expr '+' expr",
328 "expr : expr '-' expr",
329 "expr : expr '*' expr",
330 "expr : expr '/' expr",
331 "expr : expr '%' expr",
332 "expr : expr '&' expr",
333 "expr : expr '|' expr",
334 "expr : '-' expr",
335 "expr : LETTER",
336 "expr : number",
337 "number : DIGIT",
338 "number : number DIGIT",
339
340 };
341 #endif
342
343 int yydebug;
344 int yynerrs;
345
346 int yyerrflag;
347 int yychar;
348 YYSTYPE yyval;
349 YYSTYPE yylval;
350 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
351 YYLTYPE yyloc; /* position returned by actions */
352 YYLTYPE yylloc; /* position from the lexer */
353 #endif
354
355 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
356 #ifndef YYLLOC_DEFAULT
357 #define YYLLOC_DEFAULT(loc, rhs, n) \
358 do \
359 { \
360 if (n == 0) \
361 { \
362 (loc).first_line = ((rhs)[-1]).last_line; \
363 (loc).first_column = ((rhs)[-1]).last_column; \
364 (loc).last_line = ((rhs)[-1]).last_line; \
365 (loc).last_column = ((rhs)[-1]).last_column; \
366 } \
367 else \
368 { \
369 (loc).first_line = ((rhs)[ 0 ]).first_line; \
370 (loc).first_column = ((rhs)[ 0 ]).first_column; \
371 (loc).last_line = ((rhs)[n-1]).last_line; \
372 (loc).last_column = ((rhs)[n-1]).last_column; \
373 } \
374 } while (0)
375 #endif /* YYLLOC_DEFAULT */
376 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
377 #if YYBTYACC
378
379 #ifndef YYLVQUEUEGROWTH
380 #define YYLVQUEUEGROWTH 32
381 #endif
382 #endif /* YYBTYACC */
383
384 /* define the initial stack-sizes */
385 #ifdef YYSTACKSIZE
386 #undef YYMAXDEPTH
387 #define YYMAXDEPTH YYSTACKSIZE
388 #else
389 #ifdef YYMAXDEPTH
390 #define YYSTACKSIZE YYMAXDEPTH
391 #else
392 #define YYSTACKSIZE 10000
393 #define YYMAXDEPTH 10000
394 #endif
395 #endif
396
397 #ifndef YYINITSTACKSIZE
398 #define YYINITSTACKSIZE 200
399 #endif
400
401 typedef struct {
402 unsigned stacksize;
403 short *s_base;
404 short *s_mark;
405 short *s_last;
406 YYSTYPE *l_base;
407 YYSTYPE *l_mark;
408 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
409 YYLTYPE *p_base;
410 YYLTYPE *p_mark;
411 #endif
412 } YYSTACKDATA;
413 #if YYBTYACC
414
415 struct YYParseState_s
416 {
417 struct YYParseState_s *save; /* Previously saved parser state */
418 YYSTACKDATA yystack; /* saved parser stack */
419 int state; /* saved parser state */
420 int errflag; /* saved error recovery status */
421 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
422 YYINT ctry; /* saved index in yyctable[] for this conflict */
423 };
424 typedef struct YYParseState_s YYParseState;
425 #endif /* YYBTYACC */
426 /* variables for the parser stack */
427 static YYSTACKDATA yystack;
428 #if YYBTYACC
429
430 /* Current parser state */
431 static YYParseState *yyps = 0;
432
433 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
434 static YYParseState *yypath = 0;
435
436 /* Base of the lexical value queue */
437 static YYSTYPE *yylvals = 0;
438
439 /* Current position at lexical value queue */
440 static YYSTYPE *yylvp = 0;
441
442 /* End position of lexical value queue */
443 static YYSTYPE *yylve = 0;
444
445 /* The last allocated position at the lexical value queue */
446 static YYSTYPE *yylvlim = 0;
447
448 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
449 /* Base of the lexical position queue */
450 static YYLTYPE *yylpsns = 0;
451
452 /* Current position at lexical position queue */
453 static YYLTYPE *yylpp = 0;
454
455 /* End position of lexical position queue */
456 static YYLTYPE *yylpe = 0;
457
458 /* The last allocated position at the lexical position queue */
459 static YYLTYPE *yylplim = 0;
460 #endif
461
462 /* Current position at lexical token queue */
463 static short *yylexp = 0;
464
465 static short *yylexemes = 0;
466 #endif /* YYBTYACC */
467 #line 73 "calc2.y"
468 /* start of programs */
469
470 #ifdef YYBYACC
471 extern int YYLEX_DECL();
472 #endif
473
474 int
main(void)475 main (void)
476 {
477 int regs[26];
478 int base = 10;
479
480 while(!feof(stdin)) {
481 yyparse(regs, &base);
482 }
483 return 0;
484 }
485
486 #define UNUSED(x) ((void)(x))
487
488 static void
YYERROR_DECL()489 YYERROR_DECL()
490 {
491 UNUSED(regs); /* %parse-param regs is not actually used here */
492 UNUSED(base); /* %parse-param base is not actually used here */
493 fprintf(stderr, "%s\n", s);
494 }
495
496 int
YYLEX_DECL()497 YYLEX_DECL()
498 {
499 /* lexical analysis routine */
500 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
501 /* return DIGIT for a digit, yylval = 0 through 9 */
502 /* all other characters are returned immediately */
503
504 int c;
505
506 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
507
508 /* c is now nonblank */
509
510 if( islower( c )) {
511 yylval = c - 'a';
512 return ( LETTER );
513 }
514 if( isdigit( c )) {
515 yylval = (c - '0') % (*base);
516 return ( DIGIT );
517 }
518 return( c );
519 }
520 #line 519 "calc2.tab.c"
521
522 /* For use in generated program */
523 #define yydepth (int)(yystack.s_mark - yystack.s_base)
524 #if YYBTYACC
525 #define yytrial (yyps->save)
526 #endif /* YYBTYACC */
527
528 #if YYDEBUG
529 #include <stdio.h> /* needed for printf */
530 #endif
531
532 #include <stdlib.h> /* needed for malloc, etc */
533 #include <string.h> /* needed for memset */
534
535 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
yygrowstack(YYSTACKDATA * data)536 static int yygrowstack(YYSTACKDATA *data)
537 {
538 int i;
539 unsigned newsize;
540 short *newss;
541 YYSTYPE *newvs;
542 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
543 YYLTYPE *newps;
544 #endif
545
546 if ((newsize = data->stacksize) == 0)
547 newsize = YYINITSTACKSIZE;
548 else if (newsize >= YYMAXDEPTH)
549 return YYENOMEM;
550 else if ((newsize *= 2) > YYMAXDEPTH)
551 newsize = YYMAXDEPTH;
552
553 i = (int) (data->s_mark - data->s_base);
554 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
555 if (newss == 0)
556 return YYENOMEM;
557
558 data->s_base = newss;
559 data->s_mark = newss + i;
560
561 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
562 if (newvs == 0)
563 return YYENOMEM;
564
565 data->l_base = newvs;
566 data->l_mark = newvs + i;
567
568 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
569 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
570 if (newps == 0)
571 return YYENOMEM;
572
573 data->p_base = newps;
574 data->p_mark = newps + i;
575 #endif
576
577 data->stacksize = newsize;
578 data->s_last = data->s_base + newsize - 1;
579
580 #if YYDEBUG
581 if (yydebug)
582 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
583 #endif
584 return 0;
585 }
586
587 #if YYPURE || defined(YY_NO_LEAKS)
yyfreestack(YYSTACKDATA * data)588 static void yyfreestack(YYSTACKDATA *data)
589 {
590 free(data->s_base);
591 free(data->l_base);
592 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
593 free(data->p_base);
594 #endif
595 memset(data, 0, sizeof(*data));
596 }
597 #else
598 #define yyfreestack(data) /* nothing */
599 #endif /* YYPURE || defined(YY_NO_LEAKS) */
600 #if YYBTYACC
601
602 static YYParseState *
yyNewState(unsigned size)603 yyNewState(unsigned size)
604 {
605 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
606 if (p == NULL) return NULL;
607
608 p->yystack.stacksize = size;
609 if (size == 0)
610 {
611 p->yystack.s_base = NULL;
612 p->yystack.l_base = NULL;
613 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
614 p->yystack.p_base = NULL;
615 #endif
616 return p;
617 }
618 p->yystack.s_base = (short *) malloc(size * sizeof(short));
619 if (p->yystack.s_base == NULL) return NULL;
620 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
621 if (p->yystack.l_base == NULL) return NULL;
622 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
623 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
624 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
625 if (p->yystack.p_base == NULL) return NULL;
626 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
627 #endif
628
629 return p;
630 }
631
632 static void
yyFreeState(YYParseState * p)633 yyFreeState(YYParseState *p)
634 {
635 yyfreestack(&p->yystack);
636 free(p);
637 }
638 #endif /* YYBTYACC */
639
640 #define YYABORT goto yyabort
641 #define YYREJECT goto yyabort
642 #define YYACCEPT goto yyaccept
643 #define YYERROR goto yyerrlab
644 #if YYBTYACC
645 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
646 #define YYVALID_NESTED do { if (yyps->save && \
647 yyps->save->save == 0) goto yyvalid; } while(0)
648 #endif /* YYBTYACC */
649
650 int
YYPARSE_DECL()651 YYPARSE_DECL()
652 {
653 int yym, yyn, yystate, yyresult;
654 #if YYBTYACC
655 int yynewerrflag;
656 YYParseState *yyerrctx = NULL;
657 #endif /* YYBTYACC */
658 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
659 YYLTYPE yyerror_loc_range[2]; /* position of error start & end */
660 #endif
661 #if YYDEBUG
662 const char *yys;
663
664 if ((yys = getenv("YYDEBUG")) != 0)
665 {
666 yyn = *yys;
667 if (yyn >= '0' && yyn <= '9')
668 yydebug = yyn - '0';
669 }
670 if (yydebug)
671 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
672 #endif
673
674 #if YYBTYACC
675 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
676 yyps->save = 0;
677 #endif /* YYBTYACC */
678 yynerrs = 0;
679 yyerrflag = 0;
680 yychar = YYEMPTY;
681 yystate = 0;
682
683 #if YYPURE
684 memset(&yystack, 0, sizeof(yystack));
685 #endif
686
687 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
688 yystack.s_mark = yystack.s_base;
689 yystack.l_mark = yystack.l_base;
690 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
691 yystack.p_mark = yystack.p_base;
692 #endif
693 yystate = 0;
694 *yystack.s_mark = 0;
695
696 yyloop:
697 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
698 if (yychar < 0)
699 {
700 #if YYBTYACC
701 do {
702 if (yylvp < yylve)
703 {
704 /* we're currently re-reading tokens */
705 yylval = *yylvp++;
706 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
707 yylloc = *yylpp++;
708 #endif
709 yychar = *yylexp++;
710 break;
711 }
712 if (yyps->save)
713 {
714 /* in trial mode; save scanner results for future parse attempts */
715 if (yylvp == yylvlim)
716 { /* Enlarge lexical value queue */
717 size_t p = (size_t) (yylvp - yylvals);
718 size_t s = (size_t) (yylvlim - yylvals);
719
720 s += YYLVQUEUEGROWTH;
721 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem;
722 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
723 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
724 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
725 #endif
726 yylvp = yylve = yylvals + p;
727 yylvlim = yylvals + s;
728 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
729 yylpp = yylpe = yylpsns + p;
730 yylplim = yylpsns + s;
731 #endif
732 yylexp = yylexemes + p;
733 }
734 *yylexp = (short) YYLEX;
735 *yylvp++ = yylval;
736 yylve++;
737 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
738 *yylpp++ = yylloc;
739 yylpe++;
740 #endif
741 yychar = *yylexp++;
742 break;
743 }
744 /* normal operation, no conflict encountered */
745 #endif /* YYBTYACC */
746 yychar = YYLEX;
747 #if YYBTYACC
748 } while (0);
749 #endif /* YYBTYACC */
750 if (yychar < 0) yychar = YYEOF;
751 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
752 #if YYDEBUG
753 if (yydebug)
754 {
755 yys = yyname[YYTRANSLATE(yychar)];
756 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
757 YYDEBUGSTR, yydepth, yystate, yychar, yys);
758 #ifdef YYSTYPE_TOSTRING
759 #if YYBTYACC
760 if (!yytrial)
761 #endif /* YYBTYACC */
762 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
763 #endif
764 fputc('\n', stderr);
765 }
766 #endif
767 }
768 #if YYBTYACC
769
770 /* Do we have a conflict? */
771 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
772 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
773 {
774 YYINT ctry;
775
776 if (yypath)
777 {
778 YYParseState *save;
779 #if YYDEBUG
780 if (yydebug)
781 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
782 YYDEBUGSTR, yydepth, yystate);
783 #endif
784 /* Switch to the next conflict context */
785 save = yypath;
786 yypath = save->save;
787 save->save = NULL;
788 ctry = save->ctry;
789 if (save->state != yystate) YYABORT;
790 yyFreeState(save);
791
792 }
793 else
794 {
795
796 /* Unresolved conflict - start/continue trial parse */
797 YYParseState *save;
798 #if YYDEBUG
799 if (yydebug)
800 {
801 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
802 if (yyps->save)
803 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
804 else
805 fputs("Starting trial parse.\n", stderr);
806 }
807 #endif
808 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
809 if (save == NULL) goto yyenomem;
810 save->save = yyps->save;
811 save->state = yystate;
812 save->errflag = yyerrflag;
813 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
814 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
815 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
816 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
817 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
818 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
819 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
820 #endif
821 ctry = yytable[yyn];
822 if (yyctable[ctry] == -1)
823 {
824 #if YYDEBUG
825 if (yydebug && yychar >= YYEOF)
826 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
827 #endif
828 ctry++;
829 }
830 save->ctry = ctry;
831 if (yyps->save == NULL)
832 {
833 /* If this is a first conflict in the stack, start saving lexemes */
834 if (!yylexemes)
835 {
836 yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short));
837 if (yylexemes == NULL) goto yyenomem;
838 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
839 if (yylvals == NULL) goto yyenomem;
840 yylvlim = yylvals + YYLVQUEUEGROWTH;
841 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
842 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
843 if (yylpsns == NULL) goto yyenomem;
844 yylplim = yylpsns + YYLVQUEUEGROWTH;
845 #endif
846 }
847 if (yylvp == yylve)
848 {
849 yylvp = yylve = yylvals;
850 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
851 yylpp = yylpe = yylpsns;
852 #endif
853 yylexp = yylexemes;
854 if (yychar >= YYEOF)
855 {
856 *yylve++ = yylval;
857 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
858 *yylpe++ = yylloc;
859 #endif
860 *yylexp = (short) yychar;
861 yychar = YYEMPTY;
862 }
863 }
864 }
865 if (yychar >= YYEOF)
866 {
867 yylvp--;
868 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
869 yylpp--;
870 #endif
871 yylexp--;
872 yychar = YYEMPTY;
873 }
874 save->lexeme = (int) (yylvp - yylvals);
875 yyps->save = save;
876 }
877 if (yytable[yyn] == ctry)
878 {
879 #if YYDEBUG
880 if (yydebug)
881 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
882 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
883 #endif
884 if (yychar < 0)
885 {
886 yylvp++;
887 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
888 yylpp++;
889 #endif
890 yylexp++;
891 }
892 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
893 goto yyoverflow;
894 yystate = yyctable[ctry];
895 *++yystack.s_mark = (short) yystate;
896 *++yystack.l_mark = yylval;
897 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
898 *++yystack.p_mark = yylloc;
899 #endif
900 yychar = YYEMPTY;
901 if (yyerrflag > 0) --yyerrflag;
902 goto yyloop;
903 }
904 else
905 {
906 yyn = yyctable[ctry];
907 goto yyreduce;
908 }
909 } /* End of code dealing with conflicts */
910 #endif /* YYBTYACC */
911 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
912 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
913 {
914 #if YYDEBUG
915 if (yydebug)
916 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
917 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
918 #endif
919 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
920 yystate = yytable[yyn];
921 *++yystack.s_mark = yytable[yyn];
922 *++yystack.l_mark = yylval;
923 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
924 *++yystack.p_mark = yylloc;
925 #endif
926 yychar = YYEMPTY;
927 if (yyerrflag > 0) --yyerrflag;
928 goto yyloop;
929 }
930 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
931 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
932 {
933 yyn = yytable[yyn];
934 goto yyreduce;
935 }
936 if (yyerrflag != 0) goto yyinrecovery;
937 #if YYBTYACC
938
939 yynewerrflag = 1;
940 goto yyerrhandler;
941 goto yyerrlab;
942
943 yyerrlab:
944 yynewerrflag = 0;
945 yyerrhandler:
946 while (yyps->save)
947 {
948 int ctry;
949 YYParseState *save = yyps->save;
950 #if YYDEBUG
951 if (yydebug)
952 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
953 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
954 (int)(yylvp - yylvals - yyps->save->lexeme));
955 #endif
956 /* Memorize most forward-looking error state in case it's really an error. */
957 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
958 {
959 /* Free old saved error context state */
960 if (yyerrctx) yyFreeState(yyerrctx);
961 /* Create and fill out new saved error context state */
962 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
963 if (yyerrctx == NULL) goto yyenomem;
964 yyerrctx->save = yyps->save;
965 yyerrctx->state = yystate;
966 yyerrctx->errflag = yyerrflag;
967 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
968 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
969 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
970 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
971 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
972 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
973 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
974 #endif
975 yyerrctx->lexeme = (int) (yylvp - yylvals);
976 }
977 yylvp = yylvals + save->lexeme;
978 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
979 yylpp = yylpsns + save->lexeme;
980 #endif
981 yylexp = yylexemes + save->lexeme;
982 yychar = YYEMPTY;
983 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
984 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
985 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
986 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
987 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
988 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
989 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
990 #endif
991 ctry = ++save->ctry;
992 yystate = save->state;
993 /* We tried shift, try reduce now */
994 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
995 yyps->save = save->save;
996 save->save = NULL;
997 yyFreeState(save);
998
999 /* Nothing left on the stack -- error */
1000 if (!yyps->save)
1001 {
1002 #if YYDEBUG
1003 if (yydebug)
1004 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
1005 YYPREFIX, yydepth);
1006 #endif
1007 /* Restore state as it was in the most forward-advanced error */
1008 yylvp = yylvals + yyerrctx->lexeme;
1009 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1010 yylpp = yylpsns + yyerrctx->lexeme;
1011 #endif
1012 yylexp = yylexemes + yyerrctx->lexeme;
1013 yychar = yylexp[-1];
1014 yylval = yylvp[-1];
1015 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1016 yylloc = yylpp[-1];
1017 #endif
1018 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
1019 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
1020 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
1021 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1022 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1023 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
1024 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1025 #endif
1026 yystate = yyerrctx->state;
1027 yyFreeState(yyerrctx);
1028 yyerrctx = NULL;
1029 }
1030 yynewerrflag = 1;
1031 }
1032 if (yynewerrflag == 0) goto yyinrecovery;
1033 #endif /* YYBTYACC */
1034
1035 YYERROR_CALL("syntax error");
1036 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1037 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */
1038 #endif
1039
1040 #if !YYBTYACC
1041 goto yyerrlab;
1042 yyerrlab:
1043 #endif
1044 ++yynerrs;
1045
1046 yyinrecovery:
1047 if (yyerrflag < 3)
1048 {
1049 yyerrflag = 3;
1050 for (;;)
1051 {
1052 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
1053 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
1054 {
1055 #if YYDEBUG
1056 if (yydebug)
1057 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
1058 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
1059 #endif
1060 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1061 yystate = yytable[yyn];
1062 *++yystack.s_mark = yytable[yyn];
1063 *++yystack.l_mark = yylval;
1064 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1065 /* lookahead position is error end position */
1066 yyerror_loc_range[1] = yylloc;
1067 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
1068 *++yystack.p_mark = yyloc;
1069 #endif
1070 goto yyloop;
1071 }
1072 else
1073 {
1074 #if YYDEBUG
1075 if (yydebug)
1076 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
1077 YYDEBUGSTR, yydepth, *yystack.s_mark);
1078 #endif
1079 if (yystack.s_mark <= yystack.s_base) goto yyabort;
1080 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1081 /* the current TOS position is the error start position */
1082 yyerror_loc_range[0] = *yystack.p_mark;
1083 #endif
1084 #if defined(YYDESTRUCT_CALL)
1085 #if YYBTYACC
1086 if (!yytrial)
1087 #endif /* YYBTYACC */
1088 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1089 YYDESTRUCT_CALL("error: discarding state",
1090 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
1091 #else
1092 YYDESTRUCT_CALL("error: discarding state",
1093 yystos[*yystack.s_mark], yystack.l_mark);
1094 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1095 #endif /* defined(YYDESTRUCT_CALL) */
1096 --yystack.s_mark;
1097 --yystack.l_mark;
1098 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1099 --yystack.p_mark;
1100 #endif
1101 }
1102 }
1103 }
1104 else
1105 {
1106 if (yychar == YYEOF) goto yyabort;
1107 #if YYDEBUG
1108 if (yydebug)
1109 {
1110 yys = yyname[YYTRANSLATE(yychar)];
1111 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
1112 YYDEBUGSTR, yydepth, yystate, yychar, yys);
1113 }
1114 #endif
1115 #if defined(YYDESTRUCT_CALL)
1116 #if YYBTYACC
1117 if (!yytrial)
1118 #endif /* YYBTYACC */
1119 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1120 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
1121 #else
1122 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
1123 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1124 #endif /* defined(YYDESTRUCT_CALL) */
1125 yychar = YYEMPTY;
1126 goto yyloop;
1127 }
1128
1129 yyreduce:
1130 yym = yylen[yyn];
1131 #if YYDEBUG
1132 if (yydebug)
1133 {
1134 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
1135 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
1136 #ifdef YYSTYPE_TOSTRING
1137 #if YYBTYACC
1138 if (!yytrial)
1139 #endif /* YYBTYACC */
1140 if (yym > 0)
1141 {
1142 int i;
1143 fputc('<', stderr);
1144 for (i = yym; i > 0; i--)
1145 {
1146 if (i != yym) fputs(", ", stderr);
1147 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1148 yystack.l_mark[1-i]), stderr);
1149 }
1150 fputc('>', stderr);
1151 }
1152 #endif
1153 fputc('\n', stderr);
1154 }
1155 #endif
1156 if (yym > 0)
1157 yyval = yystack.l_mark[1-yym];
1158 else
1159 memset(&yyval, 0, sizeof yyval);
1160 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1161
1162 /* Perform position reduction */
1163 memset(&yyloc, 0, sizeof(yyloc));
1164 #if YYBTYACC
1165 if (!yytrial)
1166 #endif /* YYBTYACC */
1167 {
1168 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym);
1169 /* just in case YYERROR is invoked within the action, save
1170 the start of the rhs as the error start position */
1171 yyerror_loc_range[0] = yystack.p_mark[1-yym];
1172 }
1173 #endif
1174
1175 switch (yyn)
1176 {
1177 case 3:
1178 #line 35 "calc2.y"
1179 { yyerrok ; }
1180 break;
1181 case 4:
1182 #line 39 "calc2.y"
1183 { printf("%d\n",yystack.l_mark[0]);}
1184 break;
1185 case 5:
1186 #line 41 "calc2.y"
1187 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1188 break;
1189 case 6:
1190 #line 45 "calc2.y"
1191 { yyval = yystack.l_mark[-1]; }
1192 break;
1193 case 7:
1194 #line 47 "calc2.y"
1195 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1196 break;
1197 case 8:
1198 #line 49 "calc2.y"
1199 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1200 break;
1201 case 9:
1202 #line 51 "calc2.y"
1203 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1204 break;
1205 case 10:
1206 #line 53 "calc2.y"
1207 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1208 break;
1209 case 11:
1210 #line 55 "calc2.y"
1211 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1212 break;
1213 case 12:
1214 #line 57 "calc2.y"
1215 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1216 break;
1217 case 13:
1218 #line 59 "calc2.y"
1219 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1220 break;
1221 case 14:
1222 #line 61 "calc2.y"
1223 { yyval = - yystack.l_mark[0]; }
1224 break;
1225 case 15:
1226 #line 63 "calc2.y"
1227 { yyval = regs[yystack.l_mark[0]]; }
1228 break;
1229 case 17:
1230 #line 68 "calc2.y"
1231 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
1232 break;
1233 case 18:
1234 #line 70 "calc2.y"
1235 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
1236 break;
1237 #line 1236 "calc2.tab.c"
1238 default:
1239 break;
1240 }
1241 yystack.s_mark -= yym;
1242 yystate = *yystack.s_mark;
1243 yystack.l_mark -= yym;
1244 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1245 yystack.p_mark -= yym;
1246 #endif
1247 yym = yylhs[yyn];
1248 if (yystate == 0 && yym == 0)
1249 {
1250 #if YYDEBUG
1251 if (yydebug)
1252 {
1253 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1254 #ifdef YYSTYPE_TOSTRING
1255 #if YYBTYACC
1256 if (!yytrial)
1257 #endif /* YYBTYACC */
1258 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1259 #endif
1260 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1261 }
1262 #endif
1263 yystate = YYFINAL;
1264 *++yystack.s_mark = YYFINAL;
1265 *++yystack.l_mark = yyval;
1266 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1267 *++yystack.p_mark = yyloc;
1268 #endif
1269 if (yychar < 0)
1270 {
1271 #if YYBTYACC
1272 do {
1273 if (yylvp < yylve)
1274 {
1275 /* we're currently re-reading tokens */
1276 yylval = *yylvp++;
1277 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1278 yylloc = *yylpp++;
1279 #endif
1280 yychar = *yylexp++;
1281 break;
1282 }
1283 if (yyps->save)
1284 {
1285 /* in trial mode; save scanner results for future parse attempts */
1286 if (yylvp == yylvlim)
1287 { /* Enlarge lexical value queue */
1288 size_t p = (size_t) (yylvp - yylvals);
1289 size_t s = (size_t) (yylvlim - yylvals);
1290
1291 s += YYLVQUEUEGROWTH;
1292 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL)
1293 goto yyenomem;
1294 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1295 goto yyenomem;
1296 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1297 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1298 goto yyenomem;
1299 #endif
1300 yylvp = yylve = yylvals + p;
1301 yylvlim = yylvals + s;
1302 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1303 yylpp = yylpe = yylpsns + p;
1304 yylplim = yylpsns + s;
1305 #endif
1306 yylexp = yylexemes + p;
1307 }
1308 *yylexp = (short) YYLEX;
1309 *yylvp++ = yylval;
1310 yylve++;
1311 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1312 *yylpp++ = yylloc;
1313 yylpe++;
1314 #endif
1315 yychar = *yylexp++;
1316 break;
1317 }
1318 /* normal operation, no conflict encountered */
1319 #endif /* YYBTYACC */
1320 yychar = YYLEX;
1321 #if YYBTYACC
1322 } while (0);
1323 #endif /* YYBTYACC */
1324 if (yychar < 0) yychar = YYEOF;
1325 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
1326 #if YYDEBUG
1327 if (yydebug)
1328 {
1329 yys = yyname[YYTRANSLATE(yychar)];
1330 fprintf(stderr, "%s[%d]: state %d, reading %d (%s)\n",
1331 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1332 }
1333 #endif
1334 }
1335 if (yychar == YYEOF) goto yyaccept;
1336 goto yyloop;
1337 }
1338 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1339 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1340 yystate = yytable[yyn];
1341 else
1342 yystate = yydgoto[yym];
1343 #if YYDEBUG
1344 if (yydebug)
1345 {
1346 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1347 #ifdef YYSTYPE_TOSTRING
1348 #if YYBTYACC
1349 if (!yytrial)
1350 #endif /* YYBTYACC */
1351 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1352 #endif
1353 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1354 }
1355 #endif
1356 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1357 *++yystack.s_mark = (short) yystate;
1358 *++yystack.l_mark = yyval;
1359 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1360 *++yystack.p_mark = yyloc;
1361 #endif
1362 goto yyloop;
1363 #if YYBTYACC
1364
1365 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1366 yyvalid:
1367 if (yypath) YYABORT;
1368 while (yyps->save)
1369 {
1370 YYParseState *save = yyps->save;
1371 yyps->save = save->save;
1372 save->save = yypath;
1373 yypath = save;
1374 }
1375 #if YYDEBUG
1376 if (yydebug)
1377 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1378 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1379 #endif
1380 if (yyerrctx)
1381 {
1382 yyFreeState(yyerrctx);
1383 yyerrctx = NULL;
1384 }
1385 yylvp = yylvals + yypath->lexeme;
1386 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1387 yylpp = yylpsns + yypath->lexeme;
1388 #endif
1389 yylexp = yylexemes + yypath->lexeme;
1390 yychar = YYEMPTY;
1391 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1392 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
1393 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1394 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1395 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1396 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1397 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1398 #endif
1399 yystate = yypath->state;
1400 goto yyloop;
1401 #endif /* YYBTYACC */
1402
1403 yyoverflow:
1404 YYERROR_CALL("yacc stack overflow");
1405 #if YYBTYACC
1406 goto yyabort_nomem;
1407 yyenomem:
1408 YYERROR_CALL("memory exhausted");
1409 yyabort_nomem:
1410 #endif /* YYBTYACC */
1411 yyresult = 2;
1412 goto yyreturn;
1413
1414 yyabort:
1415 yyresult = 1;
1416 goto yyreturn;
1417
1418 yyaccept:
1419 #if YYBTYACC
1420 if (yyps->save) goto yyvalid;
1421 #endif /* YYBTYACC */
1422 yyresult = 0;
1423
1424 yyreturn:
1425 #if defined(YYDESTRUCT_CALL)
1426 if (yychar != YYEOF && yychar != YYEMPTY)
1427 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1428 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1429 #else
1430 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1431 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1432
1433 {
1434 YYSTYPE *pv;
1435 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1436 YYLTYPE *pp;
1437
1438 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1439 YYDESTRUCT_CALL("cleanup: discarding state",
1440 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1441 #else
1442 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1443 YYDESTRUCT_CALL("cleanup: discarding state",
1444 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1445 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1446 }
1447 #endif /* defined(YYDESTRUCT_CALL) */
1448
1449 #if YYBTYACC
1450 if (yyerrctx)
1451 {
1452 yyFreeState(yyerrctx);
1453 yyerrctx = NULL;
1454 }
1455 while (yyps)
1456 {
1457 YYParseState *save = yyps;
1458 yyps = save->save;
1459 save->save = NULL;
1460 yyFreeState(save);
1461 }
1462 while (yypath)
1463 {
1464 YYParseState *save = yypath;
1465 yypath = save->save;
1466 save->save = NULL;
1467 yyFreeState(save);
1468 }
1469 #endif /* YYBTYACC */
1470 yyfreestack(&yystack);
1471 return (yyresult);
1472 }
1473