1 /* $NetBSD: quote_calc.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.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();
162 #define YYERRCODE 256
163 static const short quote_calc_lhs
[] = { -1,
164 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
165 2, 2, 2, 2, 2, 2, 3, 3,
167 static const short quote_calc_len
[] = { 2,
168 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
169 3, 3, 3, 2, 1, 1, 1, 2,
171 static const short quote_calc_defred
[] = { 1,
172 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
173 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
174 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
177 static const short quote_calc_dgoto
[] = { 1,
180 static const short quote_calc_sindex
[] = { 0,
181 -38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
182 0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
183 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
186 static const short quote_calc_rindex
[] = { 0,
187 0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
188 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
189 0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
192 static const short quote_calc_gindex
[] = { 0,
195 #define YYTABLESIZE 258
196 static const short quote_calc_table
[] = { 16,
197 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
198 10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
199 23, 20, 4, 21, 5, 0, 0, 0, 0, 0,
200 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
201 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
202 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
203 29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, 16, 0, 17, 0, 18,
211 0, 19, 0, 20, 0, 21, 0, 0, 0, 0,
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 2, 0, 0,
219 3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
220 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
221 19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
222 16, 15, 16, 15, 16, 15, 16, 15,
224 static const short quote_calc_check
[] = { 10,
225 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
226 10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
227 269, 265, 10, 267, 10, -1, -1, -1, -1, -1,
228 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
229 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
230 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
231 19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
232 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
233 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
235 -1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
236 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
237 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
238 -1, -1, -1, -1, -1, 257, -1, 259, -1, 261,
239 -1, 263, -1, 265, -1, 267, -1, -1, -1, -1,
240 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
241 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
242 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
243 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
244 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
245 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
246 -1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
247 259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
248 269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
249 263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
250 261, 261, 263, 263, 265, 265, 267, 267,
256 #define YYMAXTOKEN 271
258 static const char *yyname
[] = {
260 "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,
261 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
262 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
263 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
264 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
265 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
266 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
267 0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
268 "\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
270 static const char *yyrule
[] = {
273 "list : list stat '\\n'",
274 "list : list error '\\n'",
276 "stat : LETTER '=' expr",
277 "expr : '(' expr ')'",
278 "expr : expr OP_ADD expr",
279 "expr : expr OP_SUB expr",
280 "expr : expr OP_MUL expr",
281 "expr : expr OP_DIV expr",
282 "expr : expr OP_MOD expr",
283 "expr : expr OP_AND expr",
284 "expr : expr '|' expr",
285 "expr : OP_SUB expr",
289 "number : number DIGIT",
302 /* define the initial stack-sizes */
305 #define YYMAXDEPTH YYSTACKSIZE
308 #define YYSTACKSIZE YYMAXDEPTH
310 #define YYSTACKSIZE 500
311 #define YYMAXDEPTH 500
315 #define YYINITSTACKSIZE 500
325 /* variables for the parser stack */
326 static YYSTACKDATA yystack
;
327 #line 73 "quote_calc.y"
328 /* start of programs */
333 while(!feof(stdin
)) {
340 yyerror(const char *s
)
342 fprintf(stderr
, "%s\n", s
);
347 /* lexical analysis routine */
348 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
349 /* return DIGIT for a digit, yylval = 0 through 9 */
350 /* all other characters are returned immediately */
354 while( (c
=getchar()) == ' ' ) { /* skip blanks */ }
356 /* c is now nonblank */
368 #line 367 "quote_calc.tab.c"
371 #include <stdio.h> /* needed for printf */
374 #include <stdlib.h> /* needed for malloc, etc */
375 #include <string.h> /* needed for memset */
377 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
378 static int yygrowstack(YYSTACKDATA
*data
)
385 if ((newsize
= data
->stacksize
) == 0)
386 newsize
= YYINITSTACKSIZE
;
387 else if (newsize
>= YYMAXDEPTH
)
389 else if ((newsize
*= 2) > YYMAXDEPTH
)
390 newsize
= YYMAXDEPTH
;
392 i
= (int) (data
->s_mark
- data
->s_base
);
393 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
397 data
->s_base
= newss
;
398 data
->s_mark
= newss
+ i
;
400 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
404 data
->l_base
= newvs
;
405 data
->l_mark
= newvs
+ i
;
407 data
->stacksize
= newsize
;
408 data
->s_last
= data
->s_base
+ newsize
- 1;
412 #if YYPURE || defined(YY_NO_LEAKS)
413 static void yyfreestack(YYSTACKDATA
*data
)
417 memset(data
, 0, sizeof(*data
));
420 #define yyfreestack(data) /* nothing */
423 #define YYABORT goto yyabort
424 #define YYREJECT goto yyabort
425 #define YYACCEPT goto yyaccept
426 #define YYERROR goto yyerrlab
431 int yym
, yyn
, yystate
;
435 if ((yys
= getenv("YYDEBUG")) != 0)
438 if (yyn
>= '0' && yyn
<= '9')
449 memset(&yystack
, 0, sizeof(yystack
));
452 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
453 yystack
.s_mark
= yystack
.s_base
;
454 yystack
.l_mark
= yystack
.l_base
;
459 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
462 if ((yychar
= YYLEX
) < 0) yychar
= 0;
467 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
468 if (!yys
) yys
= "illegal-symbol";
469 printf("%sdebug: state %d, reading %d (%s)\n",
470 YYPREFIX
, yystate
, yychar
, yys
);
474 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
475 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
479 printf("%sdebug: state %d, shifting to state %d\n",
480 YYPREFIX
, yystate
, yytable
[yyn
]);
482 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
486 yystate
= yytable
[yyn
];
487 *++yystack
.s_mark
= yytable
[yyn
];
488 *++yystack
.l_mark
= yylval
;
490 if (yyerrflag
> 0) --yyerrflag
;
493 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
494 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
499 if (yyerrflag
) goto yyinrecovery
;
501 yyerror("syntax error");
514 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
515 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
519 printf("%sdebug: state %d, error recovery shifting\
520 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
522 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
526 yystate
= yytable
[yyn
];
527 *++yystack
.s_mark
= yytable
[yyn
];
528 *++yystack
.l_mark
= yylval
;
535 printf("%sdebug: error recovery discarding state %d\n",
536 YYPREFIX
, *yystack
.s_mark
);
538 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
546 if (yychar
== 0) goto yyabort
;
551 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
552 if (!yys
) yys
= "illegal-symbol";
553 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
554 YYPREFIX
, yystate
, yychar
, yys
);
564 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
565 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
569 yyval
= yystack
.l_mark
[1-yym
];
571 memset(&yyval
, 0, sizeof yyval
);
575 #line 35 "quote_calc.y"
579 #line 39 "quote_calc.y"
580 { printf("%d\n",yystack
.l_mark
[0]);}
583 #line 41 "quote_calc.y"
584 { regs
[yystack
.l_mark
[-2]] = yystack
.l_mark
[0]; }
587 #line 45 "quote_calc.y"
588 { yyval
= yystack
.l_mark
[-1]; }
591 #line 47 "quote_calc.y"
592 { yyval
= yystack
.l_mark
[-2] + yystack
.l_mark
[0]; }
595 #line 49 "quote_calc.y"
596 { yyval
= yystack
.l_mark
[-2] - yystack
.l_mark
[0]; }
599 #line 51 "quote_calc.y"
600 { yyval
= yystack
.l_mark
[-2] * yystack
.l_mark
[0]; }
603 #line 53 "quote_calc.y"
604 { yyval
= yystack
.l_mark
[-2] / yystack
.l_mark
[0]; }
607 #line 55 "quote_calc.y"
608 { yyval
= yystack
.l_mark
[-2] % yystack
.l_mark
[0]; }
611 #line 57 "quote_calc.y"
612 { yyval
= yystack
.l_mark
[-2] & yystack
.l_mark
[0]; }
615 #line 59 "quote_calc.y"
616 { yyval
= yystack
.l_mark
[-2] | yystack
.l_mark
[0]; }
619 #line 61 "quote_calc.y"
620 { yyval
= - yystack
.l_mark
[0]; }
623 #line 63 "quote_calc.y"
624 { yyval
= regs
[yystack
.l_mark
[0]]; }
627 #line 68 "quote_calc.y"
628 { yyval
= yystack
.l_mark
[0]; base
= (yystack
.l_mark
[0]==0) ? 8 : 10; }
631 #line 70 "quote_calc.y"
632 { yyval
= base
* yystack
.l_mark
[-1] + yystack
.l_mark
[0]; }
634 #line 633 "quote_calc.tab.c"
636 yystack
.s_mark
-= yym
;
637 yystate
= *yystack
.s_mark
;
638 yystack
.l_mark
-= yym
;
640 if (yystate
== 0 && yym
== 0)
644 printf("%sdebug: after reduction, shifting from state 0 to\
645 state %d\n", YYPREFIX
, YYFINAL
);
648 *++yystack
.s_mark
= YYFINAL
;
649 *++yystack
.l_mark
= yyval
;
652 if ((yychar
= YYLEX
) < 0) yychar
= 0;
657 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
658 if (!yys
) yys
= "illegal-symbol";
659 printf("%sdebug: state %d, reading %d (%s)\n",
660 YYPREFIX
, YYFINAL
, yychar
, yys
);
664 if (yychar
== 0) goto yyaccept
;
667 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
668 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
669 yystate
= yytable
[yyn
];
671 yystate
= yydgoto
[yym
];
674 printf("%sdebug: after reduction, shifting from state %d \
675 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
677 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
681 *++yystack
.s_mark
= (short) yystate
;
682 *++yystack
.l_mark
= yyval
;
686 yyerror("yacc stack overflow");
689 yyfreestack(&yystack
);
693 yyfreestack(&yystack
);