1 /* $NetBSD: quote_calc3-s.tab.c,v 1.1.1.1 2013/04/06 14:45:28 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_calc3_parse
22 #define yylex quote_calc3_lex
26 #define yyerror quote_calc3_error
30 #define yychar quote_calc3_char
34 #define yyval quote_calc3_val
38 #define yylval quote_calc3_lval
42 #define yydebug quote_calc3_debug
46 #define yynerrs quote_calc3_nerrs
50 #define yyerrflag quote_calc3_errflag
51 #endif /* yyerrflag */
54 #define yylhs quote_calc3_lhs
58 #define yylen quote_calc3_len
62 #define yydefred quote_calc3_defred
66 #define yydgoto quote_calc3_dgoto
70 #define yysindex quote_calc3_sindex
74 #define yyrindex quote_calc3_rindex
78 #define yygindex quote_calc3_gindex
82 #define yytable quote_calc3_table
86 #define yycheck quote_calc3_check
90 #define yyname quote_calc3_name
94 #define yyrule quote_calc3_rule
96 #define YYPREFIX "quote_calc3_"
100 #line 2 "quote_calc3.y"
108 static void yyerror(const char *s
);
110 #line 109 "quote_calc3-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_calc3_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_calc3_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_calc3_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_calc3_dgoto
[] = { 1,
174 static const short quote_calc3_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_calc3_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_calc3_gindex
[] = { 0,
189 #define YYTABLESIZE 258
190 static const short quote_calc3_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_calc3_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-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL",
262 "\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"",
263 "OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS",
265 static const char *yyrule
[] = {
268 "list : list stat '\\n'",
269 "list : list error '\\n'",
271 "stat : LETTER '=' expr",
272 "expr : '(' expr ')'",
273 "expr : expr OP_ADD expr",
274 "expr : expr OP_SUB expr",
275 "expr : expr OP_MUL expr",
276 "expr : expr OP_DIV expr",
277 "expr : expr OP_MOD expr",
278 "expr : expr OP_AND expr",
279 "expr : expr '|' expr",
280 "expr : OP_SUB expr",
284 "number : number DIGIT",
297 /* define the initial stack-sizes */
300 #define YYMAXDEPTH YYSTACKSIZE
303 #define YYSTACKSIZE YYMAXDEPTH
305 #define YYSTACKSIZE 500
306 #define YYMAXDEPTH 500
310 #define YYINITSTACKSIZE 500
320 /* variables for the parser stack */
321 static YYSTACKDATA yystack
;
322 #line 73 "quote_calc3.y"
323 /* start of programs */
328 while(!feof(stdin
)) {
335 yyerror(const char *s
)
337 fprintf(stderr
, "%s\n", s
);
342 /* lexical analysis routine */
343 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
344 /* return DIGIT for a digit, yylval = 0 through 9 */
345 /* all other characters are returned immediately */
349 while( (c
=getchar()) == ' ' ) { /* skip blanks */ }
351 /* c is now nonblank */
363 #line 362 "quote_calc3-s.tab.c"
366 #include <stdio.h> /* needed for printf */
369 #include <stdlib.h> /* needed for malloc, etc */
370 #include <string.h> /* needed for memset */
372 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
373 static int yygrowstack(YYSTACKDATA
*data
)
380 if ((newsize
= data
->stacksize
) == 0)
381 newsize
= YYINITSTACKSIZE
;
382 else if (newsize
>= YYMAXDEPTH
)
384 else if ((newsize
*= 2) > YYMAXDEPTH
)
385 newsize
= YYMAXDEPTH
;
387 i
= (int) (data
->s_mark
- data
->s_base
);
388 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
392 data
->s_base
= newss
;
393 data
->s_mark
= newss
+ i
;
395 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
399 data
->l_base
= newvs
;
400 data
->l_mark
= newvs
+ i
;
402 data
->stacksize
= newsize
;
403 data
->s_last
= data
->s_base
+ newsize
- 1;
407 #if YYPURE || defined(YY_NO_LEAKS)
408 static void yyfreestack(YYSTACKDATA
*data
)
412 memset(data
, 0, sizeof(*data
));
415 #define yyfreestack(data) /* nothing */
418 #define YYABORT goto yyabort
419 #define YYREJECT goto yyabort
420 #define YYACCEPT goto yyaccept
421 #define YYERROR goto yyerrlab
426 int yym
, yyn
, yystate
;
430 if ((yys
= getenv("YYDEBUG")) != 0)
433 if (yyn
>= '0' && yyn
<= '9')
444 memset(&yystack
, 0, sizeof(yystack
));
447 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
448 yystack
.s_mark
= yystack
.s_base
;
449 yystack
.l_mark
= yystack
.l_base
;
454 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
457 if ((yychar
= YYLEX
) < 0) yychar
= 0;
462 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
463 if (!yys
) yys
= "illegal-symbol";
464 printf("%sdebug: state %d, reading %d (%s)\n",
465 YYPREFIX
, yystate
, yychar
, yys
);
469 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
470 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
474 printf("%sdebug: state %d, shifting to state %d\n",
475 YYPREFIX
, yystate
, yytable
[yyn
]);
477 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
481 yystate
= yytable
[yyn
];
482 *++yystack
.s_mark
= yytable
[yyn
];
483 *++yystack
.l_mark
= yylval
;
485 if (yyerrflag
> 0) --yyerrflag
;
488 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
489 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
494 if (yyerrflag
) goto yyinrecovery
;
496 yyerror("syntax error");
509 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
510 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
514 printf("%sdebug: state %d, error recovery shifting\
515 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
517 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
521 yystate
= yytable
[yyn
];
522 *++yystack
.s_mark
= yytable
[yyn
];
523 *++yystack
.l_mark
= yylval
;
530 printf("%sdebug: error recovery discarding state %d\n",
531 YYPREFIX
, *yystack
.s_mark
);
533 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
541 if (yychar
== 0) goto yyabort
;
546 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
547 if (!yys
) yys
= "illegal-symbol";
548 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
549 YYPREFIX
, yystate
, yychar
, yys
);
559 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
560 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
564 yyval
= yystack
.l_mark
[1-yym
];
566 memset(&yyval
, 0, sizeof yyval
);
570 #line 35 "quote_calc3.y"
574 #line 39 "quote_calc3.y"
575 { printf("%d\n",yystack
.l_mark
[0]);}
578 #line 41 "quote_calc3.y"
579 { regs
[yystack
.l_mark
[-2]] = yystack
.l_mark
[0]; }
582 #line 45 "quote_calc3.y"
583 { yyval
= yystack
.l_mark
[-1]; }
586 #line 47 "quote_calc3.y"
587 { yyval
= yystack
.l_mark
[-2] + yystack
.l_mark
[0]; }
590 #line 49 "quote_calc3.y"
591 { yyval
= yystack
.l_mark
[-2] - yystack
.l_mark
[0]; }
594 #line 51 "quote_calc3.y"
595 { yyval
= yystack
.l_mark
[-2] * yystack
.l_mark
[0]; }
598 #line 53 "quote_calc3.y"
599 { yyval
= yystack
.l_mark
[-2] / yystack
.l_mark
[0]; }
602 #line 55 "quote_calc3.y"
603 { yyval
= yystack
.l_mark
[-2] % yystack
.l_mark
[0]; }
606 #line 57 "quote_calc3.y"
607 { yyval
= yystack
.l_mark
[-2] & yystack
.l_mark
[0]; }
610 #line 59 "quote_calc3.y"
611 { yyval
= yystack
.l_mark
[-2] | yystack
.l_mark
[0]; }
614 #line 61 "quote_calc3.y"
615 { yyval
= - yystack
.l_mark
[0]; }
618 #line 63 "quote_calc3.y"
619 { yyval
= regs
[yystack
.l_mark
[0]]; }
622 #line 68 "quote_calc3.y"
623 { yyval
= yystack
.l_mark
[0]; base
= (yystack
.l_mark
[0]==0) ? 8 : 10; }
626 #line 70 "quote_calc3.y"
627 { yyval
= base
* yystack
.l_mark
[-1] + yystack
.l_mark
[0]; }
629 #line 628 "quote_calc3-s.tab.c"
631 yystack
.s_mark
-= yym
;
632 yystate
= *yystack
.s_mark
;
633 yystack
.l_mark
-= yym
;
635 if (yystate
== 0 && yym
== 0)
639 printf("%sdebug: after reduction, shifting from state 0 to\
640 state %d\n", YYPREFIX
, YYFINAL
);
643 *++yystack
.s_mark
= YYFINAL
;
644 *++yystack
.l_mark
= yyval
;
647 if ((yychar
= YYLEX
) < 0) yychar
= 0;
652 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
653 if (!yys
) yys
= "illegal-symbol";
654 printf("%sdebug: state %d, reading %d (%s)\n",
655 YYPREFIX
, YYFINAL
, yychar
, yys
);
659 if (yychar
== 0) goto yyaccept
;
662 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
663 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
664 yystate
= yytable
[yyn
];
666 yystate
= yydgoto
[yym
];
669 printf("%sdebug: after reduction, shifting from state %d \
670 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
672 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
676 *++yystack
.s_mark
= (short) yystate
;
677 *++yystack
.l_mark
= yyval
;
681 yyerror("yacc stack overflow");
684 yyfreestack(&yystack
);
688 yyfreestack(&yystack
);