1 /* $NetBSD: calc1.tab.c,v 1.1.1.4 2013/04/06 14:45:29 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 calc1_parse
22 #define yylex calc1_lex
26 #define yyerror calc1_error
30 #define yychar calc1_char
34 #define yyval calc1_val
38 #define yylval calc1_lval
42 #define yydebug calc1_debug
46 #define yynerrs calc1_nerrs
50 #define yyerrflag calc1_errflag
51 #endif /* yyerrflag */
54 #define yylhs calc1_lhs
58 #define yylen calc1_len
62 #define yydefred calc1_defred
66 #define yydgoto calc1_dgoto
70 #define yysindex calc1_sindex
74 #define yyrindex calc1_rindex
78 #define yygindex calc1_gindex
82 #define yytable calc1_table
86 #define yycheck calc1_check
90 #define yyname calc1_name
94 #define yyrule calc1_rule
96 #define YYPREFIX "calc1_"
102 /* http://dinosaur.compilertools.net/yacc/index.html */
109 typedef struct interval
115 INTERVAL
vmul(double, double, INTERVAL
);
116 INTERVAL
vdiv(double, double, INTERVAL
);
118 extern int yylex(void);
119 static void yyerror(const char *s
);
121 int dcheck(INTERVAL
);
128 #undef YYSTYPE_IS_DECLARED
129 #define YYSTYPE_IS_DECLARED 1
131 #ifndef YYSTYPE_IS_DECLARED
132 #define YYSTYPE_IS_DECLARED 1
139 #endif /* !YYSTYPE_IS_DECLARED */
140 #line 139 "calc1.tab.c"
142 /* compatibility with bison */
144 /* compatibility with FreeBSD */
145 # ifdef YYPARSE_PARAM_TYPE
146 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
148 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
151 # define YYPARSE_DECL() yyparse(void)
154 /* Parameters sent to lex. */
156 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
157 # define YYLEX yylex(YYLEX_PARAM)
159 # define YYLEX_DECL() yylex(void)
160 # define YYLEX yylex()
163 /* Parameters sent to yyerror. */
165 #define YYERROR_DECL() yyerror(const char *s)
168 #define YYERROR_CALL(msg) yyerror(msg)
171 extern int YYPARSE_DECL();
177 #define YYERRCODE 256
178 static const short calc1_lhs
[] = { -1,
179 3, 3, 0, 0, 0, 0, 0, 1, 1, 1,
180 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
181 2, 2, 2, 2, 2, 2, 2, 2,
183 static const short calc1_len
[] = { 2,
184 0, 2, 2, 2, 4, 4, 2, 1, 1, 3,
185 3, 3, 3, 2, 3, 1, 5, 1, 3, 3,
186 3, 3, 3, 3, 3, 3, 2, 3,
188 static const short calc1_defred
[] = { 0,
189 0, 0, 0, 8, 0, 0, 0, 0, 0, 7,
190 0, 0, 9, 18, 14, 27, 0, 0, 0, 0,
191 0, 0, 3, 0, 0, 0, 0, 4, 0, 0,
192 0, 0, 0, 15, 0, 28, 0, 0, 0, 0,
193 12, 24, 13, 26, 0, 0, 23, 25, 14, 0,
194 0, 0, 0, 0, 5, 6, 0, 0, 0, 12,
197 static const short calc1_dgoto
[] = { 7,
200 static const short calc1_sindex
[] = { -40,
201 -8, -48, -47, 0, -37, -37, 0, 2, 17, 0,
202 -34, -37, 0, 0, 0, 0, -25, 90, -37, -37,
203 -37, -37, 0, -37, -37, -37, -37, 0, -34, -34,
204 25, 125, 31, 0, -34, 0, -11, 37, -11, 37,
205 0, 0, 0, 0, 37, 37, 0, 0, 0, 111,
206 -34, -34, -34, -34, 0, 0, 118, 69, 69, 0,
209 static const short calc1_rindex
[] = { 0,
210 0, 38, 44, 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, 0, 0, 0,
213 0, -9, 0, 0, 0, 0, 51, -3, 56, 61,
214 0, 0, 0, 0, 67, 72, 0, 0, 0, 0,
215 0, 0, 0, 0, 0, 0, 0, 78, 83, 0,
218 static const short calc1_gindex
[] = { 0,
221 #define YYTABLESIZE 225
222 static const short calc1_table
[] = { 6,
223 16, 10, 6, 8, 5, 30, 20, 5, 15, 17,
224 29, 23, 11, 12, 31, 34, 21, 19, 35, 20,
225 0, 22, 37, 39, 41, 43, 28, 0, 0, 0,
226 21, 16, 49, 50, 55, 22, 0, 20, 57, 20,
227 56, 20, 0, 21, 19, 0, 20, 9, 22, 0,
228 0, 0, 0, 18, 58, 59, 60, 61, 26, 24,
229 10, 25, 0, 27, 0, 11, 53, 51, 0, 52,
230 22, 54, 26, 24, 0, 25, 19, 27, 26, 9,
231 9, 21, 9, 27, 9, 18, 18, 10, 18, 0,
232 18, 10, 11, 10, 10, 10, 11, 0, 11, 11,
233 11, 22, 0, 22, 0, 22, 0, 19, 0, 19,
234 53, 19, 21, 0, 21, 54, 21, 0, 10, 0,
235 10, 0, 10, 11, 0, 11, 0, 11, 16, 18,
236 36, 26, 24, 0, 25, 33, 27, 0, 0, 0,
237 0, 0, 38, 40, 42, 44, 0, 45, 46, 47,
238 48, 34, 53, 51, 0, 52, 0, 54, 62, 53,
239 51, 0, 52, 0, 54, 0, 21, 19, 0, 20,
240 0, 22, 0, 0, 0, 0, 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, 1, 2, 3, 4, 13,
247 static const short calc1_check
[] = { 40,
248 10, 10, 40, 0, 45, 40, 10, 45, 5, 6,
249 45, 10, 61, 61, 11, 41, 42, 43, 44, 45,
250 -1, 47, 19, 20, 21, 22, 10, -1, -1, -1,
251 42, 41, 29, 30, 10, 47, -1, 41, 35, 43,
252 10, 45, -1, 42, 43, -1, 45, 10, 47, -1,
253 -1, -1, -1, 10, 51, 52, 53, 54, 42, 43,
254 10, 45, -1, 47, -1, 10, 42, 43, -1, 45,
255 10, 47, 42, 43, -1, 45, 10, 47, 42, 42,
256 43, 10, 45, 47, 47, 42, 43, 10, 45, -1,
257 47, 41, 10, 43, 44, 45, 41, -1, 43, 44,
258 45, 41, -1, 43, -1, 45, -1, 41, -1, 43,
259 42, 45, 41, -1, 43, 47, 45, -1, 41, -1,
260 43, -1, 45, 41, -1, 43, -1, 45, 5, 6,
261 41, 42, 43, -1, 45, 12, 47, -1, -1, -1,
262 -1, -1, 19, 20, 21, 22, -1, 24, 25, 26,
263 27, 41, 42, 43, -1, 45, -1, 47, 41, 42,
264 43, -1, 45, -1, 47, -1, 42, 43, -1, 45,
265 -1, 47, -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, 256, 257, 258, 259, 257,
270 258, 259, 257, -1, 259,
276 #define YYMAXTOKEN 260
278 static const char *yyname
[] = {
280 "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,
281 0,0,0,0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,
282 0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
283 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
284 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
285 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
286 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
287 0,0,"DREG","VREG","CONST","UMINUS",
289 static const char *yyrule
[] = {
292 "lines : lines line",
295 "line : DREG '=' dexp '\\n'",
296 "line : VREG '=' vexp '\\n'",
297 "line : error '\\n'",
300 "dexp : dexp '+' dexp",
301 "dexp : dexp '-' dexp",
302 "dexp : dexp '*' dexp",
303 "dexp : dexp '/' dexp",
305 "dexp : '(' dexp ')'",
307 "vexp : '(' dexp ',' dexp ')'",
309 "vexp : vexp '+' vexp",
310 "vexp : dexp '+' vexp",
311 "vexp : vexp '-' vexp",
312 "vexp : dexp '-' vexp",
313 "vexp : vexp '*' vexp",
314 "vexp : dexp '*' vexp",
315 "vexp : vexp '/' vexp",
316 "vexp : dexp '/' vexp",
318 "vexp : '(' vexp ')'",
331 /* define the initial stack-sizes */
334 #define YYMAXDEPTH YYSTACKSIZE
337 #define YYSTACKSIZE YYMAXDEPTH
339 #define YYSTACKSIZE 500
340 #define YYMAXDEPTH 500
344 #define YYINITSTACKSIZE 500
354 /* variables for the parser stack */
355 static YYSTACKDATA yystack
;
357 /* beginning of subroutines section */
359 #define BSZ 50 /* buffer size for floating point numbers */
361 /* lexical analysis */
364 yyerror(const char *s
)
366 fprintf(stderr
, "%s\n", s
);
374 while ((c
= getchar()) == ' ')
375 { /* skip over blanks */
380 yylval
.ival
= c
- 'A';
385 yylval
.ival
= c
- 'a';
389 if (isdigit(c
) || c
== '.')
391 /* gobble up digits, points, exponents */
392 char buf
[BSZ
+ 1], *cp
= buf
;
393 int dot
= 0, expr
= 0;
395 for (; (cp
- buf
) < BSZ
; ++cp
, c
= getchar())
404 return ('.'); /* will cause syntax error */
411 return ('e'); /* will cause syntax error */
420 if ((cp
- buf
) >= BSZ
)
421 printf("constant too long: truncated\n");
423 ungetc(c
, stdin
); /* push back last char read */
424 yylval
.dval
= atof(buf
);
431 hilo(double a
, double b
, double c
, double d
)
433 /* returns the smallest interval containing a, b, c, and d */
434 /* used by *, / routines */
466 vmul(double a
, double b
, INTERVAL v
)
468 return (hilo(a
* v
.hi
, a
* v
.lo
, b
* v
.hi
, b
* v
.lo
));
474 if (v
.hi
>= 0. && v
.lo
<= 0.)
476 printf("divisor interval contains 0.\n");
483 vdiv(double a
, double b
, INTERVAL v
)
485 return (hilo(a
/ v
.hi
, a
/ v
.lo
, b
/ v
.hi
, b
/ v
.lo
));
487 #line 486 "calc1.tab.c"
490 #include <stdio.h> /* needed for printf */
493 #include <stdlib.h> /* needed for malloc, etc */
494 #include <string.h> /* needed for memset */
496 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
497 static int yygrowstack(YYSTACKDATA
*data
)
504 if ((newsize
= data
->stacksize
) == 0)
505 newsize
= YYINITSTACKSIZE
;
506 else if (newsize
>= YYMAXDEPTH
)
508 else if ((newsize
*= 2) > YYMAXDEPTH
)
509 newsize
= YYMAXDEPTH
;
511 i
= (int) (data
->s_mark
- data
->s_base
);
512 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
516 data
->s_base
= newss
;
517 data
->s_mark
= newss
+ i
;
519 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
523 data
->l_base
= newvs
;
524 data
->l_mark
= newvs
+ i
;
526 data
->stacksize
= newsize
;
527 data
->s_last
= data
->s_base
+ newsize
- 1;
531 #if YYPURE || defined(YY_NO_LEAKS)
532 static void yyfreestack(YYSTACKDATA
*data
)
536 memset(data
, 0, sizeof(*data
));
539 #define yyfreestack(data) /* nothing */
542 #define YYABORT goto yyabort
543 #define YYREJECT goto yyabort
544 #define YYACCEPT goto yyaccept
545 #define YYERROR goto yyerrlab
550 int yym
, yyn
, yystate
;
554 if ((yys
= getenv("YYDEBUG")) != 0)
557 if (yyn
>= '0' && yyn
<= '9')
568 memset(&yystack
, 0, sizeof(yystack
));
571 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
572 yystack
.s_mark
= yystack
.s_base
;
573 yystack
.l_mark
= yystack
.l_base
;
578 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
581 if ((yychar
= YYLEX
) < 0) yychar
= 0;
586 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
587 if (!yys
) yys
= "illegal-symbol";
588 printf("%sdebug: state %d, reading %d (%s)\n",
589 YYPREFIX
, yystate
, yychar
, yys
);
593 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
594 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
598 printf("%sdebug: state %d, shifting to state %d\n",
599 YYPREFIX
, yystate
, yytable
[yyn
]);
601 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
605 yystate
= yytable
[yyn
];
606 *++yystack
.s_mark
= yytable
[yyn
];
607 *++yystack
.l_mark
= yylval
;
609 if (yyerrflag
> 0) --yyerrflag
;
612 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
613 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
618 if (yyerrflag
) goto yyinrecovery
;
620 yyerror("syntax error");
633 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
634 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
638 printf("%sdebug: state %d, error recovery shifting\
639 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
641 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
645 yystate
= yytable
[yyn
];
646 *++yystack
.s_mark
= yytable
[yyn
];
647 *++yystack
.l_mark
= yylval
;
654 printf("%sdebug: error recovery discarding state %d\n",
655 YYPREFIX
, *yystack
.s_mark
);
657 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
665 if (yychar
== 0) goto yyabort
;
670 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
671 if (!yys
) yys
= "illegal-symbol";
672 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
673 YYPREFIX
, yystate
, yychar
, yys
);
683 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
684 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
688 yyval
= yystack
.l_mark
[1-yym
];
690 memset(&yyval
, 0, sizeof yyval
);
696 (void) printf("%15.8f\n", yystack
.l_mark
[-1].dval
);
702 (void) printf("(%15.8f, %15.8f)\n", yystack
.l_mark
[-1].vval
.lo
, yystack
.l_mark
[-1].vval
.hi
);
708 dreg
[yystack
.l_mark
[-3].ival
] = yystack
.l_mark
[-1].dval
;
714 vreg
[yystack
.l_mark
[-3].ival
] = yystack
.l_mark
[-1].vval
;
726 yyval
.dval
= dreg
[yystack
.l_mark
[0].ival
];
732 yyval
.dval
= yystack
.l_mark
[-2].dval
+ yystack
.l_mark
[0].dval
;
738 yyval
.dval
= yystack
.l_mark
[-2].dval
- yystack
.l_mark
[0].dval
;
744 yyval
.dval
= yystack
.l_mark
[-2].dval
* yystack
.l_mark
[0].dval
;
750 yyval
.dval
= yystack
.l_mark
[-2].dval
/ yystack
.l_mark
[0].dval
;
756 yyval
.dval
= -yystack
.l_mark
[0].dval
;
762 yyval
.dval
= yystack
.l_mark
[-1].dval
;
768 yyval
.vval
.hi
= yyval
.vval
.lo
= yystack
.l_mark
[0].dval
;
774 yyval
.vval
.lo
= yystack
.l_mark
[-3].dval
;
775 yyval
.vval
.hi
= yystack
.l_mark
[-1].dval
;
776 if ( yyval
.vval
.lo
> yyval
.vval
.hi
)
778 (void) printf("interval out of order\n");
786 yyval
.vval
= vreg
[yystack
.l_mark
[0].ival
];
792 yyval
.vval
.hi
= yystack
.l_mark
[-2].vval
.hi
+ yystack
.l_mark
[0].vval
.hi
;
793 yyval
.vval
.lo
= yystack
.l_mark
[-2].vval
.lo
+ yystack
.l_mark
[0].vval
.lo
;
799 yyval
.vval
.hi
= yystack
.l_mark
[-2].dval
+ yystack
.l_mark
[0].vval
.hi
;
800 yyval
.vval
.lo
= yystack
.l_mark
[-2].dval
+ yystack
.l_mark
[0].vval
.lo
;
806 yyval
.vval
.hi
= yystack
.l_mark
[-2].vval
.hi
- yystack
.l_mark
[0].vval
.lo
;
807 yyval
.vval
.lo
= yystack
.l_mark
[-2].vval
.lo
- yystack
.l_mark
[0].vval
.hi
;
813 yyval
.vval
.hi
= yystack
.l_mark
[-2].dval
- yystack
.l_mark
[0].vval
.lo
;
814 yyval
.vval
.lo
= yystack
.l_mark
[-2].dval
- yystack
.l_mark
[0].vval
.hi
;
820 yyval
.vval
= vmul( yystack
.l_mark
[-2].vval
.lo
, yystack
.l_mark
[-2].vval
.hi
, yystack
.l_mark
[0].vval
);
826 yyval
.vval
= vmul (yystack
.l_mark
[-2].dval
, yystack
.l_mark
[-2].dval
, yystack
.l_mark
[0].vval
);
832 if (dcheck(yystack
.l_mark
[0].vval
)) YYERROR
;
833 yyval
.vval
= vdiv ( yystack
.l_mark
[-2].vval
.lo
, yystack
.l_mark
[-2].vval
.hi
, yystack
.l_mark
[0].vval
);
839 if (dcheck ( yystack
.l_mark
[0].vval
)) YYERROR
;
840 yyval
.vval
= vdiv (yystack
.l_mark
[-2].dval
, yystack
.l_mark
[-2].dval
, yystack
.l_mark
[0].vval
);
846 yyval
.vval
.hi
= -yystack
.l_mark
[0].vval
.lo
;
847 yyval
.vval
.lo
= -yystack
.l_mark
[0].vval
.hi
;
853 yyval
.vval
= yystack
.l_mark
[-1].vval
;
856 #line 855 "calc1.tab.c"
858 yystack
.s_mark
-= yym
;
859 yystate
= *yystack
.s_mark
;
860 yystack
.l_mark
-= yym
;
862 if (yystate
== 0 && yym
== 0)
866 printf("%sdebug: after reduction, shifting from state 0 to\
867 state %d\n", YYPREFIX
, YYFINAL
);
870 *++yystack
.s_mark
= YYFINAL
;
871 *++yystack
.l_mark
= yyval
;
874 if ((yychar
= YYLEX
) < 0) yychar
= 0;
879 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
880 if (!yys
) yys
= "illegal-symbol";
881 printf("%sdebug: state %d, reading %d (%s)\n",
882 YYPREFIX
, YYFINAL
, yychar
, yys
);
886 if (yychar
== 0) goto yyaccept
;
889 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
890 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
891 yystate
= yytable
[yyn
];
893 yystate
= yydgoto
[yym
];
896 printf("%sdebug: after reduction, shifting from state %d \
897 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
899 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
903 *++yystack
.s_mark
= (short) yystate
;
904 *++yystack
.l_mark
= yyval
;
908 yyerror("yacc stack overflow");
911 yyfreestack(&yystack
);
915 yyfreestack(&yystack
);