1 /* $NetBSD: quote_calc-s.tab.c,v 1.1.1.1 2013/04/06 14:45:27 christos Exp $ */
4 static const char yysccsid
[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
12 #define yyclearin (yychar = YYEMPTY)
13 #define yyerrok (yyerrflag = 0)
14 #define YYRECOVERING() (yyerrflag != 0)
18 #define yyparse quote_calc_parse
22 #define yylex quote_calc_lex
26 #define yyerror quote_calc_error
30 #define yychar quote_calc_char
34 #define yyval quote_calc_val
38 #define yylval quote_calc_lval
42 #define yydebug quote_calc_debug
46 #define yynerrs quote_calc_nerrs
50 #define yyerrflag quote_calc_errflag
51 #endif /* yyerrflag */
54 #define yylhs quote_calc_lhs
58 #define yylen quote_calc_len
62 #define yydefred quote_calc_defred
66 #define yydgoto quote_calc_dgoto
70 #define yysindex quote_calc_sindex
74 #define yyrindex quote_calc_rindex
78 #define yygindex quote_calc_gindex
82 #define yytable quote_calc_table
86 #define yycheck quote_calc_check
90 #define yyname quote_calc_name
94 #define yyrule quote_calc_rule
96 #define YYPREFIX "quote_calc_"
100 #line 2 "quote_calc.y"
108 static void yyerror(const char *s
);
110 #line 109 "quote_calc-s.tab.c"
116 /* compatibility with bison */
118 /* compatibility with FreeBSD */
119 # ifdef YYPARSE_PARAM_TYPE
120 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
122 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
125 # define YYPARSE_DECL() yyparse(void)
128 /* Parameters sent to lex. */
130 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
131 # define YYLEX yylex(YYLEX_PARAM)
133 # define YYLEX_DECL() yylex(void)
134 # define YYLEX yylex()
137 /* Parameters sent to yyerror. */
139 #define YYERROR_DECL() yyerror(const char *s)
142 #define YYERROR_CALL(msg) yyerror(msg)
145 extern int YYPARSE_DECL();
156 #define YYERRCODE 256
157 static const short quote_calc_lhs
[] = { -1,
158 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
159 2, 2, 2, 2, 2, 2, 3, 3,
161 static const short quote_calc_len
[] = { 2,
162 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
163 3, 3, 3, 2, 1, 1, 1, 2,
165 static const short quote_calc_defred
[] = { 1,
166 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
167 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
168 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
171 static const short quote_calc_dgoto
[] = { 1,
174 static const short quote_calc_sindex
[] = { 0,
175 -38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
176 0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
177 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
180 static const short quote_calc_rindex
[] = { 0,
181 0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
182 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
183 0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
186 static const short quote_calc_gindex
[] = { 0,
189 #define YYTABLESIZE 258
190 static const short quote_calc_table
[] = { 16,
191 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
192 10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
193 23, 20, 4, 21, 5, 0, 0, 0, 0, 0,
194 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
195 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
196 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
197 29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
198 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
199 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
200 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
201 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
202 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
203 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 16, 0, 17, 0, 18,
205 0, 19, 0, 20, 0, 21, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
212 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
213 3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
214 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
215 19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
216 16, 15, 16, 15, 16, 15, 16, 15,
218 static const short quote_calc_check
[] = { 10,
219 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
220 10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
221 269, 265, 10, 267, 10, -1, -1, -1, -1, -1,
222 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
223 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
224 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
225 19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
226 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
227 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
228 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
229 -1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
231 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
232 -1, -1, -1, -1, -1, 257, -1, 259, -1, 261,
233 -1, 263, -1, 265, -1, 267, -1, -1, -1, -1,
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
235 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
236 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
237 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
238 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
239 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
240 -1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
241 259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
242 269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
243 263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
244 261, 261, 263, 263, 265, 265, 267, 267,
250 #define YYMAXTOKEN 271
252 static const char *yyname
[] = {
254 "end-of-file",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,
255 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
256 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
257 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
258 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
259 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
260 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
261 0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
262 "\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
264 static const char *yyrule
[] = {
267 "list : list stat '\\n'",
268 "list : list error '\\n'",
270 "stat : LETTER '=' expr",
271 "expr : '(' expr ')'",
272 "expr : expr OP_ADD expr",
273 "expr : expr OP_SUB expr",
274 "expr : expr OP_MUL expr",
275 "expr : expr OP_DIV expr",
276 "expr : expr OP_MOD expr",
277 "expr : expr OP_AND expr",
278 "expr : expr '|' expr",
279 "expr : OP_SUB expr",
283 "number : number DIGIT",
296 /* define the initial stack-sizes */
299 #define YYMAXDEPTH YYSTACKSIZE
302 #define YYSTACKSIZE YYMAXDEPTH
304 #define YYSTACKSIZE 500
305 #define YYMAXDEPTH 500
309 #define YYINITSTACKSIZE 500
319 /* variables for the parser stack */
320 static YYSTACKDATA yystack
;
321 #line 73 "quote_calc.y"
322 /* start of programs */
327 while(!feof(stdin
)) {
334 yyerror(const char *s
)
336 fprintf(stderr
, "%s\n", s
);
341 /* lexical analysis routine */
342 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
343 /* return DIGIT for a digit, yylval = 0 through 9 */
344 /* all other characters are returned immediately */
348 while( (c
=getchar()) == ' ' ) { /* skip blanks */ }
350 /* c is now nonblank */
362 #line 361 "quote_calc-s.tab.c"
365 #include <stdio.h> /* needed for printf */
368 #include <stdlib.h> /* needed for malloc, etc */
369 #include <string.h> /* needed for memset */
371 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
372 static int yygrowstack(YYSTACKDATA
*data
)
379 if ((newsize
= data
->stacksize
) == 0)
380 newsize
= YYINITSTACKSIZE
;
381 else if (newsize
>= YYMAXDEPTH
)
383 else if ((newsize
*= 2) > YYMAXDEPTH
)
384 newsize
= YYMAXDEPTH
;
386 i
= (int) (data
->s_mark
- data
->s_base
);
387 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
391 data
->s_base
= newss
;
392 data
->s_mark
= newss
+ i
;
394 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
398 data
->l_base
= newvs
;
399 data
->l_mark
= newvs
+ i
;
401 data
->stacksize
= newsize
;
402 data
->s_last
= data
->s_base
+ newsize
- 1;
406 #if YYPURE || defined(YY_NO_LEAKS)
407 static void yyfreestack(YYSTACKDATA
*data
)
411 memset(data
, 0, sizeof(*data
));
414 #define yyfreestack(data) /* nothing */
417 #define YYABORT goto yyabort
418 #define YYREJECT goto yyabort
419 #define YYACCEPT goto yyaccept
420 #define YYERROR goto yyerrlab
425 int yym
, yyn
, yystate
;
429 if ((yys
= getenv("YYDEBUG")) != 0)
432 if (yyn
>= '0' && yyn
<= '9')
443 memset(&yystack
, 0, sizeof(yystack
));
446 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
447 yystack
.s_mark
= yystack
.s_base
;
448 yystack
.l_mark
= yystack
.l_base
;
453 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
456 if ((yychar
= YYLEX
) < 0) yychar
= 0;
461 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
462 if (!yys
) yys
= "illegal-symbol";
463 printf("%sdebug: state %d, reading %d (%s)\n",
464 YYPREFIX
, yystate
, yychar
, yys
);
468 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
469 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
473 printf("%sdebug: state %d, shifting to state %d\n",
474 YYPREFIX
, yystate
, yytable
[yyn
]);
476 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
480 yystate
= yytable
[yyn
];
481 *++yystack
.s_mark
= yytable
[yyn
];
482 *++yystack
.l_mark
= yylval
;
484 if (yyerrflag
> 0) --yyerrflag
;
487 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
488 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
493 if (yyerrflag
) goto yyinrecovery
;
495 yyerror("syntax error");
508 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
509 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
513 printf("%sdebug: state %d, error recovery shifting\
514 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
516 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
520 yystate
= yytable
[yyn
];
521 *++yystack
.s_mark
= yytable
[yyn
];
522 *++yystack
.l_mark
= yylval
;
529 printf("%sdebug: error recovery discarding state %d\n",
530 YYPREFIX
, *yystack
.s_mark
);
532 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
540 if (yychar
== 0) goto yyabort
;
545 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
546 if (!yys
) yys
= "illegal-symbol";
547 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
548 YYPREFIX
, yystate
, yychar
, yys
);
558 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
559 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
563 yyval
= yystack
.l_mark
[1-yym
];
565 memset(&yyval
, 0, sizeof yyval
);
569 #line 35 "quote_calc.y"
573 #line 39 "quote_calc.y"
574 { printf("%d\n",yystack
.l_mark
[0]);}
577 #line 41 "quote_calc.y"
578 { regs
[yystack
.l_mark
[-2]] = yystack
.l_mark
[0]; }
581 #line 45 "quote_calc.y"
582 { yyval
= yystack
.l_mark
[-1]; }
585 #line 47 "quote_calc.y"
586 { yyval
= yystack
.l_mark
[-2] + yystack
.l_mark
[0]; }
589 #line 49 "quote_calc.y"
590 { yyval
= yystack
.l_mark
[-2] - yystack
.l_mark
[0]; }
593 #line 51 "quote_calc.y"
594 { yyval
= yystack
.l_mark
[-2] * yystack
.l_mark
[0]; }
597 #line 53 "quote_calc.y"
598 { yyval
= yystack
.l_mark
[-2] / yystack
.l_mark
[0]; }
601 #line 55 "quote_calc.y"
602 { yyval
= yystack
.l_mark
[-2] % yystack
.l_mark
[0]; }
605 #line 57 "quote_calc.y"
606 { yyval
= yystack
.l_mark
[-2] & yystack
.l_mark
[0]; }
609 #line 59 "quote_calc.y"
610 { yyval
= yystack
.l_mark
[-2] | yystack
.l_mark
[0]; }
613 #line 61 "quote_calc.y"
614 { yyval
= - yystack
.l_mark
[0]; }
617 #line 63 "quote_calc.y"
618 { yyval
= regs
[yystack
.l_mark
[0]]; }
621 #line 68 "quote_calc.y"
622 { yyval
= yystack
.l_mark
[0]; base
= (yystack
.l_mark
[0]==0) ? 8 : 10; }
625 #line 70 "quote_calc.y"
626 { yyval
= base
* yystack
.l_mark
[-1] + yystack
.l_mark
[0]; }
628 #line 627 "quote_calc-s.tab.c"
630 yystack
.s_mark
-= yym
;
631 yystate
= *yystack
.s_mark
;
632 yystack
.l_mark
-= yym
;
634 if (yystate
== 0 && yym
== 0)
638 printf("%sdebug: after reduction, shifting from state 0 to\
639 state %d\n", YYPREFIX
, YYFINAL
);
642 *++yystack
.s_mark
= YYFINAL
;
643 *++yystack
.l_mark
= yyval
;
646 if ((yychar
= YYLEX
) < 0) yychar
= 0;
651 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
652 if (!yys
) yys
= "illegal-symbol";
653 printf("%sdebug: state %d, reading %d (%s)\n",
654 YYPREFIX
, YYFINAL
, yychar
, yys
);
658 if (yychar
== 0) goto yyaccept
;
661 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
662 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
663 yystate
= yytable
[yyn
];
665 yystate
= yydgoto
[yym
];
668 printf("%sdebug: after reduction, shifting from state %d \
669 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
671 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
675 *++yystack
.s_mark
= (short) yystate
;
676 *++yystack
.l_mark
= yyval
;
680 yyerror("yacc stack overflow");
683 yyfreestack(&yystack
);
687 yyfreestack(&yystack
);