2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
10 #define yyclearin (yychar = YYEMPTY)
11 #define yyerrok (yyerrflag = 0)
12 #define YYRECOVERING() (yyerrflag != 0)
16 #define yyparse calc1_parse
20 #define yylex calc1_lex
24 #define yyerror calc1_error
28 #define yychar calc1_char
32 #define yyval calc1_val
36 #define yylval calc1_lval
40 #define yydebug calc1_debug
44 #define yynerrs calc1_nerrs
48 #define yyerrflag calc1_errflag
49 #endif /* yyerrflag */
52 #define yylhs calc1_lhs
56 #define yylen calc1_len
60 #define yydefred calc1_defred
64 #define yydgoto calc1_dgoto
68 #define yysindex calc1_sindex
72 #define yyrindex calc1_rindex
76 #define yygindex calc1_gindex
80 #define yytable calc1_table
84 #define yycheck calc1_check
88 #define yyname calc1_name
92 #define yyrule calc1_rule
94 #define YYPREFIX "calc1_"
100 /* http://dinosaur.compilertools.net/yacc/index.html */
107 typedef struct interval
113 INTERVAL vmul(double, double, INTERVAL);
114 INTERVAL vdiv(double, double, INTERVAL);
116 extern int yylex(void);
117 static void yyerror(const char *s);
119 int dcheck(INTERVAL);
126 #undef YYSTYPE_IS_DECLARED
127 #define YYSTYPE_IS_DECLARED 1
129 #ifndef YYSTYPE_IS_DECLARED
130 #define YYSTYPE_IS_DECLARED 1
137 #endif /* !YYSTYPE_IS_DECLARED */
138 #line 139 "calc1.tab.c"
140 /* compatibility with bison */
142 /* compatibility with FreeBSD */
143 # ifdef YYPARSE_PARAM_TYPE
144 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
146 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
149 # define YYPARSE_DECL() yyparse(void)
152 /* Parameters sent to lex. */
154 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
155 # define YYLEX yylex(YYLEX_PARAM)
157 # define YYLEX_DECL() yylex(void)
158 # define YYLEX yylex()
161 /* Parameters sent to yyerror. */
163 #define YYERROR_DECL() yyerror(const char *s)
166 #define YYERROR_CALL(msg) yyerror(msg)
169 extern int YYPARSE_DECL();
175 #define YYERRCODE 256
176 static const short calc1_lhs[] = { -1,
177 3, 3, 0, 0, 0, 0, 0, 1, 1, 1,
178 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
179 2, 2, 2, 2, 2, 2, 2, 2,
181 static const short calc1_len[] = { 2,
182 0, 2, 2, 2, 4, 4, 2, 1, 1, 3,
183 3, 3, 3, 2, 3, 1, 5, 1, 3, 3,
184 3, 3, 3, 3, 3, 3, 2, 3,
186 static const short calc1_defred[] = { 0,
187 0, 0, 0, 8, 0, 0, 0, 0, 0, 7,
188 0, 0, 9, 18, 14, 27, 0, 0, 0, 0,
189 0, 0, 3, 0, 0, 0, 0, 4, 0, 0,
190 0, 0, 0, 15, 0, 28, 0, 0, 0, 0,
191 12, 24, 13, 26, 0, 0, 23, 25, 14, 0,
192 0, 0, 0, 0, 5, 6, 0, 0, 0, 12,
195 static const short calc1_dgoto[] = { 7,
198 static const short calc1_sindex[] = { -40,
199 -8, -48, -47, 0, -37, -37, 0, 2, 17, 0,
200 -34, -37, 0, 0, 0, 0, -25, 90, -37, -37,
201 -37, -37, 0, -37, -37, -37, -37, 0, -34, -34,
202 25, 125, 31, 0, -34, 0, -11, 37, -11, 37,
203 0, 0, 0, 0, 37, 37, 0, 0, 0, 111,
204 -34, -34, -34, -34, 0, 0, 118, 69, 69, 0,
207 static const short calc1_rindex[] = { 0,
208 0, 38, 44, 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, -9, 0, 0, 0, 0, 51, -3, 56, 61,
212 0, 0, 0, 0, 67, 72, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 0, 0, 78, 83, 0,
216 static const short calc1_gindex[] = { 0,
219 #define YYTABLESIZE 225
220 static const short calc1_table[] = { 6,
221 16, 10, 6, 8, 5, 30, 20, 5, 15, 17,
222 29, 23, 11, 12, 31, 34, 21, 19, 35, 20,
223 0, 22, 37, 39, 41, 43, 28, 0, 0, 0,
224 21, 16, 49, 50, 55, 22, 0, 20, 57, 20,
225 56, 20, 0, 21, 19, 0, 20, 9, 22, 0,
226 0, 0, 0, 18, 58, 59, 60, 61, 26, 24,
227 10, 25, 0, 27, 0, 11, 53, 51, 0, 52,
228 22, 54, 26, 24, 0, 25, 19, 27, 26, 9,
229 9, 21, 9, 27, 9, 18, 18, 10, 18, 0,
230 18, 10, 11, 10, 10, 10, 11, 0, 11, 11,
231 11, 22, 0, 22, 0, 22, 0, 19, 0, 19,
232 53, 19, 21, 0, 21, 54, 21, 0, 10, 0,
233 10, 0, 10, 11, 0, 11, 0, 11, 16, 18,
234 36, 26, 24, 0, 25, 33, 27, 0, 0, 0,
235 0, 0, 38, 40, 42, 44, 0, 45, 46, 47,
236 48, 34, 53, 51, 0, 52, 0, 54, 62, 53,
237 51, 0, 52, 0, 54, 0, 21, 19, 0, 20,
238 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 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, 1, 2, 3, 4, 13,
245 static const short calc1_check[] = { 40,
246 10, 10, 40, 0, 45, 40, 10, 45, 5, 6,
247 45, 10, 61, 61, 11, 41, 42, 43, 44, 45,
248 -1, 47, 19, 20, 21, 22, 10, -1, -1, -1,
249 42, 41, 29, 30, 10, 47, -1, 41, 35, 43,
250 10, 45, -1, 42, 43, -1, 45, 10, 47, -1,
251 -1, -1, -1, 10, 51, 52, 53, 54, 42, 43,
252 10, 45, -1, 47, -1, 10, 42, 43, -1, 45,
253 10, 47, 42, 43, -1, 45, 10, 47, 42, 42,
254 43, 10, 45, 47, 47, 42, 43, 10, 45, -1,
255 47, 41, 10, 43, 44, 45, 41, -1, 43, 44,
256 45, 41, -1, 43, -1, 45, -1, 41, -1, 43,
257 42, 45, 41, -1, 43, 47, 45, -1, 41, -1,
258 43, -1, 45, 41, -1, 43, -1, 45, 5, 6,
259 41, 42, 43, -1, 45, 12, 47, -1, -1, -1,
260 -1, -1, 19, 20, 21, 22, -1, 24, 25, 26,
261 27, 41, 42, 43, -1, 45, -1, 47, 41, 42,
262 43, -1, 45, -1, 47, -1, 42, 43, -1, 45,
263 -1, 47, -1, -1, -1, -1, -1, -1, -1, -1,
264 -1, -1, -1, -1, -1, -1, -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, 256, 257, 258, 259, 257,
268 258, 259, 257, -1, 259,
274 #define YYMAXTOKEN 260
276 static const char *yyname[] = {
278 "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,
279 0,0,0,0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,
280 0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,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,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,"DREG","VREG","CONST","UMINUS",
287 static const char *yyrule[] = {
290 "lines : lines line",
293 "line : DREG '=' dexp '\\n'",
294 "line : VREG '=' vexp '\\n'",
295 "line : error '\\n'",
298 "dexp : dexp '+' dexp",
299 "dexp : dexp '-' dexp",
300 "dexp : dexp '*' dexp",
301 "dexp : dexp '/' dexp",
303 "dexp : '(' dexp ')'",
305 "vexp : '(' dexp ',' dexp ')'",
307 "vexp : vexp '+' vexp",
308 "vexp : dexp '+' vexp",
309 "vexp : vexp '-' vexp",
310 "vexp : dexp '-' vexp",
311 "vexp : vexp '*' vexp",
312 "vexp : dexp '*' vexp",
313 "vexp : vexp '/' vexp",
314 "vexp : dexp '/' vexp",
316 "vexp : '(' vexp ')'",
329 /* define the initial stack-sizes */
332 #define YYMAXDEPTH YYSTACKSIZE
335 #define YYSTACKSIZE YYMAXDEPTH
337 #define YYSTACKSIZE 500
338 #define YYMAXDEPTH 500
342 #define YYINITSTACKSIZE 500
352 /* variables for the parser stack */
353 static YYSTACKDATA yystack;
355 /* beginning of subroutines section */
357 #define BSZ 50 /* buffer size for floating point numbers */
359 /* lexical analysis */
362 yyerror(const char *s)
364 fprintf(stderr, "%s\n", s);
372 while ((c = getchar()) == ' ')
373 { /* skip over blanks */
378 yylval.ival = c - 'A';
383 yylval.ival = c - 'a';
387 if (isdigit(c) || c == '.')
389 /* gobble up digits, points, exponents */
390 char buf[BSZ + 1], *cp = buf;
391 int dot = 0, expr = 0;
393 for (; (cp - buf) < BSZ; ++cp, c = getchar())
402 return ('.'); /* will cause syntax error */
409 return ('e'); /* will cause syntax error */
418 if ((cp - buf) >= BSZ)
419 printf("constant too long: truncated\n");
421 ungetc(c, stdin); /* push back last char read */
422 yylval.dval = atof(buf);
429 hilo(double a, double b, double c, double d)
431 /* returns the smallest interval containing a, b, c, and d */
432 /* used by *, / routines */
464 vmul(double a, double b, INTERVAL v)
466 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo));
472 if (v.hi >= 0. && v.lo <= 0.)
474 printf("divisor interval contains 0.\n");
481 vdiv(double a, double b, INTERVAL v)
483 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo));
485 #line 486 "calc1.tab.c"
488 #include <stdio.h> /* needed for printf */
491 #include <stdlib.h> /* needed for malloc, etc */
492 #include <string.h> /* needed for memset */
494 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
495 static int yygrowstack(YYSTACKDATA *data)
502 if ((newsize = data->stacksize) == 0)
503 newsize = YYINITSTACKSIZE;
504 else if (newsize >= YYMAXDEPTH)
506 else if ((newsize *= 2) > YYMAXDEPTH)
507 newsize = YYMAXDEPTH;
509 i = (int) (data->s_mark - data->s_base);
510 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
514 data->s_base = newss;
515 data->s_mark = newss + i;
517 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
521 data->l_base = newvs;
522 data->l_mark = newvs + i;
524 data->stacksize = newsize;
525 data->s_last = data->s_base + newsize - 1;
529 #if YYPURE || defined(YY_NO_LEAKS)
530 static void yyfreestack(YYSTACKDATA *data)
534 memset(data, 0, sizeof(*data));
537 #define yyfreestack(data) /* nothing */
540 #define YYABORT goto yyabort
541 #define YYREJECT goto yyabort
542 #define YYACCEPT goto yyaccept
543 #define YYERROR goto yyerrlab
548 int yym, yyn, yystate;
552 if ((yys = getenv("YYDEBUG")) != 0)
555 if (yyn >= '0' && yyn <= '9')
566 memset(&yystack, 0, sizeof(yystack));
569 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
570 yystack.s_mark = yystack.s_base;
571 yystack.l_mark = yystack.l_base;
576 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
579 if ((yychar = YYLEX) < 0) yychar = 0;
584 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
585 if (!yys) yys = "illegal-symbol";
586 printf("%sdebug: state %d, reading %d (%s)\n",
587 YYPREFIX, yystate, yychar, yys);
591 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
592 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
596 printf("%sdebug: state %d, shifting to state %d\n",
597 YYPREFIX, yystate, yytable[yyn]);
599 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
603 yystate = yytable[yyn];
604 *++yystack.s_mark = yytable[yyn];
605 *++yystack.l_mark = yylval;
607 if (yyerrflag > 0) --yyerrflag;
610 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
611 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
616 if (yyerrflag) goto yyinrecovery;
618 yyerror("syntax error");
631 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
632 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
636 printf("%sdebug: state %d, error recovery shifting\
637 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
639 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
643 yystate = yytable[yyn];
644 *++yystack.s_mark = yytable[yyn];
645 *++yystack.l_mark = yylval;
652 printf("%sdebug: error recovery discarding state %d\n",
653 YYPREFIX, *yystack.s_mark);
655 if (yystack.s_mark <= yystack.s_base) goto yyabort;
663 if (yychar == 0) goto yyabort;
668 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
669 if (!yys) yys = "illegal-symbol";
670 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
671 YYPREFIX, yystate, yychar, yys);
681 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
682 YYPREFIX, yystate, yyn, yyrule[yyn]);
686 yyval = yystack.l_mark[1-yym];
688 memset(&yyval, 0, sizeof yyval);
694 (void) printf("%15.8f\n", yystack.l_mark[-1].dval);
700 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi);
706 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval;
712 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval;
724 yyval.dval = dreg[yystack.l_mark[0].ival];
730 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval;
736 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval;
742 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval;
748 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval;
754 yyval.dval = -yystack.l_mark[0].dval;
760 yyval.dval = yystack.l_mark[-1].dval;
766 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval;
772 yyval.vval.lo = yystack.l_mark[-3].dval;
773 yyval.vval.hi = yystack.l_mark[-1].dval;
774 if ( yyval.vval.lo > yyval.vval.hi )
776 (void) printf("interval out of order\n");
784 yyval.vval = vreg[yystack.l_mark[0].ival];
790 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi;
791 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo;
797 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi;
798 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo;
804 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo;
805 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi;
811 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo;
812 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi;
818 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
824 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
830 if (dcheck(yystack.l_mark[0].vval)) YYERROR;
831 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
837 if (dcheck ( yystack.l_mark[0].vval )) YYERROR;
838 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
844 yyval.vval.hi = -yystack.l_mark[0].vval.lo;
845 yyval.vval.lo = -yystack.l_mark[0].vval.hi;
851 yyval.vval = yystack.l_mark[-1].vval;
854 #line 855 "calc1.tab.c"
856 yystack.s_mark -= yym;
857 yystate = *yystack.s_mark;
858 yystack.l_mark -= yym;
860 if (yystate == 0 && yym == 0)
864 printf("%sdebug: after reduction, shifting from state 0 to\
865 state %d\n", YYPREFIX, YYFINAL);
868 *++yystack.s_mark = YYFINAL;
869 *++yystack.l_mark = yyval;
872 if ((yychar = YYLEX) < 0) yychar = 0;
877 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
878 if (!yys) yys = "illegal-symbol";
879 printf("%sdebug: state %d, reading %d (%s)\n",
880 YYPREFIX, YYFINAL, yychar, yys);
884 if (yychar == 0) goto yyaccept;
887 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
888 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
889 yystate = yytable[yyn];
891 yystate = yydgoto[yym];
894 printf("%sdebug: after reduction, shifting from state %d \
895 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
897 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
901 *++yystack.s_mark = (short) yystate;
902 *++yystack.l_mark = yyval;
906 yyerror("yacc stack overflow");
909 yyfreestack(&yystack);
913 yyfreestack(&yystack);