1 /* original parser id follows */
2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
4
5 #define YYBYACC 1
6 #define YYMAJOR 2
7 #define YYMINOR 0
8 #define YYCHECK "yyyymmdd"
9
10 #define YYEMPTY (-1)
11 #define yyclearin (yychar = YYEMPTY)
12 #define yyerrok (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
14 #define YYENOMEM (-2)
15 #define YYEOF 0
16
17 #ifndef yyparse
18 #define yyparse calc1_parse
19 #endif /* yyparse */
20
21 #ifndef yylex
22 #define yylex calc1_lex
23 #endif /* yylex */
24
25 #ifndef yyerror
26 #define yyerror calc1_error
27 #endif /* yyerror */
28
29 #ifndef yychar
30 #define yychar calc1_char
31 #endif /* yychar */
32
33 #ifndef yyval
34 #define yyval calc1_val
35 #endif /* yyval */
36
37 #ifndef yylval
38 #define yylval calc1_lval
39 #endif /* yylval */
40
41 #ifndef yydebug
42 #define yydebug calc1_debug
43 #endif /* yydebug */
44
45 #ifndef yynerrs
46 #define yynerrs calc1_nerrs
47 #endif /* yynerrs */
48
49 #ifndef yyerrflag
50 #define yyerrflag calc1_errflag
51 #endif /* yyerrflag */
52
53 #ifndef yylhs
54 #define yylhs calc1_lhs
55 #endif /* yylhs */
56
57 #ifndef yylen
58 #define yylen calc1_len
59 #endif /* yylen */
60
61 #ifndef yydefred
62 #define yydefred calc1_defred
63 #endif /* yydefred */
64
65 #ifndef yydgoto
66 #define yydgoto calc1_dgoto
67 #endif /* yydgoto */
68
69 #ifndef yysindex
70 #define yysindex calc1_sindex
71 #endif /* yysindex */
72
73 #ifndef yyrindex
74 #define yyrindex calc1_rindex
75 #endif /* yyrindex */
76
77 #ifndef yygindex
78 #define yygindex calc1_gindex
79 #endif /* yygindex */
80
81 #ifndef yytable
82 #define yytable calc1_table
83 #endif /* yytable */
84
85 #ifndef yycheck
86 #define yycheck calc1_check
87 #endif /* yycheck */
88
89 #ifndef yyname
90 #define yyname calc1_name
91 #endif /* yyname */
92
93 #ifndef yyrule
94 #define yyrule calc1_rule
95 #endif /* yyrule */
96 #define YYPREFIX "calc1_"
97
98 #define YYPURE 0
99
100 #line 2 "calc1.y"
101
102 /* http://dinosaur.compilertools.net/yacc/index.html */
103
104 #include <stdlib.h>
105 #include <stdio.h>
106 #include <ctype.h>
107 #include <math.h>
108
109 typedef struct interval
110 {
111 double lo, hi;
112 }
113 INTERVAL;
114
115 INTERVAL vmul(double, double, INTERVAL);
116 INTERVAL vdiv(double, double, INTERVAL);
117
118 extern int yylex(void);
119 static void yyerror(const char *s);
120
121 int dcheck(INTERVAL);
122
123 double dreg[26];
124 INTERVAL vreg[26];
125
126 #ifdef YYSTYPE
127 #undef YYSTYPE_IS_DECLARED
128 #define YYSTYPE_IS_DECLARED 1
129 #endif
130 #ifndef YYSTYPE_IS_DECLARED
131 #define YYSTYPE_IS_DECLARED 1
132 #line 31 "calc1.y"
133 typedef union YYSTYPE
134 {
135 int ival;
136 double dval;
137 INTERVAL vval;
138 } YYSTYPE;
139 #endif /* !YYSTYPE_IS_DECLARED */
140 #line 141 "calc1.tab.c"
141
142 /* compatibility with bison */
143 #ifdef YYPARSE_PARAM
144 /* compatibility with FreeBSD */
145 # ifdef YYPARSE_PARAM_TYPE
146 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
147 # else
148 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
149 # endif
150 #else
151 # define YYPARSE_DECL() yyparse(void)
152 #endif
153
154 /* Parameters sent to lex. */
155 #ifdef YYLEX_PARAM
156 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
157 # define YYLEX yylex(YYLEX_PARAM)
158 #else
159 # define YYLEX_DECL() yylex(void)
160 # define YYLEX yylex()
161 #endif
162
163 /* Parameters sent to yyerror. */
164 #ifndef YYERROR_DECL
165 #define YYERROR_DECL() yyerror(const char *s)
166 #endif
167 #ifndef YYERROR_CALL
168 #define YYERROR_CALL(msg) yyerror(msg)
169 #endif
170
171 extern int YYPARSE_DECL();
172
173 #define DREG 257
174 #define VREG 258
175 #define CONST 259
176 #define UMINUS 260
177 #define YYERRCODE 256
178 typedef int YYINT;
179 static const YYINT calc1_lhs[] = { -1,
180 3, 3, 0, 0, 0, 0, 0, 1, 1, 1,
181 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
182 2, 2, 2, 2, 2, 2, 2, 2,
183 };
184 static const YYINT calc1_len[] = { 2,
185 0, 2, 2, 2, 4, 4, 2, 1, 1, 3,
186 3, 3, 3, 2, 3, 1, 5, 1, 3, 3,
187 3, 3, 3, 3, 3, 3, 2, 3,
188 };
189 static const YYINT calc1_defred[] = { 0,
190 0, 0, 0, 8, 0, 0, 0, 0, 0, 7,
191 0, 0, 9, 18, 14, 27, 0, 0, 0, 0,
192 0, 0, 3, 0, 0, 0, 0, 4, 0, 0,
193 0, 0, 0, 15, 0, 28, 0, 0, 0, 0,
194 12, 24, 13, 26, 0, 0, 23, 25, 14, 0,
195 0, 0, 0, 0, 5, 6, 0, 0, 0, 12,
196 13, 17,
197 };
198 static const YYINT calc1_dgoto[] = { 7,
199 32, 9, 0,
200 };
201 static const YYINT calc1_sindex[] = { -40,
202 -8, -48, -47, 0, -37, -37, 0, 2, 17, 0,
203 -34, -37, 0, 0, 0, 0, -25, 90, -37, -37,
204 -37, -37, 0, -37, -37, -37, -37, 0, -34, -34,
205 25, 125, 31, 0, -34, 0, -11, 37, -11, 37,
206 0, 0, 0, 0, 37, 37, 0, 0, 0, 111,
207 -34, -34, -34, -34, 0, 0, 118, 69, 69, 0,
208 0, 0,
209 };
210 static const YYINT calc1_rindex[] = { 0,
211 0, 38, 44, 0, 0, 0, 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, -9, 0, 0, 0, 0, 51, -3, 56, 61,
215 0, 0, 0, 0, 67, 72, 0, 0, 0, 0,
216 0, 0, 0, 0, 0, 0, 0, 78, 83, 0,
217 0, 0,
218 };
219 static const YYINT calc1_gindex[] = { 0,
220 4, 124, 0,
221 };
222 #define YYTABLESIZE 225
223 static const YYINT calc1_table[] = { 6,
224 16, 10, 6, 8, 5, 30, 20, 5, 15, 17,
225 29, 23, 11, 12, 31, 34, 21, 19, 35, 20,
226 0, 22, 37, 39, 41, 43, 28, 0, 0, 0,
227 21, 16, 49, 50, 55, 22, 0, 20, 57, 20,
228 56, 20, 0, 21, 19, 0, 20, 9, 22, 0,
229 0, 0, 0, 18, 58, 59, 60, 61, 26, 24,
230 10, 25, 0, 27, 0, 11, 53, 51, 0, 52,
231 22, 54, 26, 24, 0, 25, 19, 27, 26, 9,
232 9, 21, 9, 27, 9, 18, 18, 10, 18, 0,
233 18, 10, 11, 10, 10, 10, 11, 0, 11, 11,
234 11, 22, 0, 22, 0, 22, 0, 19, 0, 19,
235 53, 19, 21, 0, 21, 54, 21, 0, 10, 0,
236 10, 0, 10, 11, 0, 11, 0, 11, 16, 18,
237 36, 26, 24, 0, 25, 33, 27, 0, 0, 0,
238 0, 0, 38, 40, 42, 44, 0, 45, 46, 47,
239 48, 34, 53, 51, 0, 52, 0, 54, 62, 53,
240 51, 0, 52, 0, 54, 0, 21, 19, 0, 20,
241 0, 22, 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, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 1, 2, 3, 4, 13,
246 14, 4, 13, 0, 4,
247 };
248 static const YYINT calc1_check[] = { 40,
249 10, 10, 40, 0, 45, 40, 10, 45, 5, 6,
250 45, 10, 61, 61, 11, 41, 42, 43, 44, 45,
251 -1, 47, 19, 20, 21, 22, 10, -1, -1, -1,
252 42, 41, 29, 30, 10, 47, -1, 41, 35, 43,
253 10, 45, -1, 42, 43, -1, 45, 10, 47, -1,
254 -1, -1, -1, 10, 51, 52, 53, 54, 42, 43,
255 10, 45, -1, 47, -1, 10, 42, 43, -1, 45,
256 10, 47, 42, 43, -1, 45, 10, 47, 42, 42,
257 43, 10, 45, 47, 47, 42, 43, 10, 45, -1,
258 47, 41, 10, 43, 44, 45, 41, -1, 43, 44,
259 45, 41, -1, 43, -1, 45, -1, 41, -1, 43,
260 42, 45, 41, -1, 43, 47, 45, -1, 41, -1,
261 43, -1, 45, 41, -1, 43, -1, 45, 5, 6,
262 41, 42, 43, -1, 45, 12, 47, -1, -1, -1,
263 -1, -1, 19, 20, 21, 22, -1, 24, 25, 26,
264 27, 41, 42, 43, -1, 45, -1, 47, 41, 42,
265 43, -1, 45, -1, 47, -1, 42, 43, -1, 45,
266 -1, 47, -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, -1, -1, -1, -1, -1,
270 -1, -1, -1, -1, -1, 256, 257, 258, 259, 257,
271 258, 259, 257, -1, 259,
272 };
273 #define YYFINAL 7
274 #ifndef YYDEBUG
275 #define YYDEBUG 0
276 #endif
277 #define YYMAXTOKEN 260
278 #define YYUNDFTOKEN 266
279 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
280 #if YYDEBUG
281 static const char *const calc1_name[] = {
282
283 "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,
284 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,
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
288 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
289 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
290 0,0,"DREG","VREG","CONST","UMINUS",0,0,0,0,0,"illegal-symbol",
291 };
292 static const char *const calc1_rule[] = {
293 "$accept : line",
294 "lines :",
295 "lines : lines line",
296 "line : dexp '\\n'",
297 "line : vexp '\\n'",
298 "line : DREG '=' dexp '\\n'",
299 "line : VREG '=' vexp '\\n'",
300 "line : error '\\n'",
301 "dexp : CONST",
302 "dexp : DREG",
303 "dexp : dexp '+' dexp",
304 "dexp : dexp '-' dexp",
305 "dexp : dexp '*' dexp",
306 "dexp : dexp '/' dexp",
307 "dexp : '-' dexp",
308 "dexp : '(' dexp ')'",
309 "vexp : dexp",
310 "vexp : '(' dexp ',' dexp ')'",
311 "vexp : VREG",
312 "vexp : vexp '+' vexp",
313 "vexp : dexp '+' vexp",
314 "vexp : vexp '-' vexp",
315 "vexp : dexp '-' vexp",
316 "vexp : vexp '*' vexp",
317 "vexp : dexp '*' vexp",
318 "vexp : vexp '/' vexp",
319 "vexp : dexp '/' vexp",
320 "vexp : '-' vexp",
321 "vexp : '(' vexp ')'",
322
323 };
324 #endif
325
326 #if YYDEBUG
327 int yydebug;
328 #endif
329
330 int yyerrflag;
331 int yychar;
332 YYSTYPE yyval;
333 YYSTYPE yylval;
334 int yynerrs;
335
336 /* define the initial stack-sizes */
337 #ifdef YYSTACKSIZE
338 #undef YYMAXDEPTH
339 #define YYMAXDEPTH YYSTACKSIZE
340 #else
341 #ifdef YYMAXDEPTH
342 #define YYSTACKSIZE YYMAXDEPTH
343 #else
344 #define YYSTACKSIZE 10000
345 #define YYMAXDEPTH 10000
346 #endif
347 #endif
348
349 #define YYINITSTACKSIZE 200
350
351 typedef struct {
352 unsigned stacksize;
353 YYINT *s_base;
354 YYINT *s_mark;
355 YYINT *s_last;
356 YYSTYPE *l_base;
357 YYSTYPE *l_mark;
358 } YYSTACKDATA;
359 /* variables for the parser stack */
360 static YYSTACKDATA yystack;
361 #line 176 "calc1.y"
362 /* beginning of subroutines section */
363
364 #define BSZ 50 /* buffer size for floating point numbers */
365
366 /* lexical analysis */
367
368 static void
yyerror(const char * s)369 yyerror(const char *s)
370 {
371 fprintf(stderr, "%s\n", s);
372 }
373
374 int
yylex(void)375 yylex(void)
376 {
377 int c;
378
379 while ((c = getchar()) == ' ')
380 { /* skip over blanks */
381 }
382
383 if (isupper(c))
384 {
385 yylval.ival = c - 'A';
386 return (VREG);
387 }
388 if (islower(c))
389 {
390 yylval.ival = c - 'a';
391 return (DREG);
392 }
393
394 if (isdigit(c) || c == '.')
395 {
396 /* gobble up digits, points, exponents */
397 char buf[BSZ + 1], *cp = buf;
398 int dot = 0, expr = 0;
399
400 for (; (cp - buf) < BSZ; ++cp, c = getchar())
401 {
402
403 *cp = (char) c;
404 if (isdigit(c))
405 continue;
406 if (c == '.')
407 {
408 if (dot++ || expr)
409 return ('.'); /* will cause syntax error */
410 continue;
411 }
412
413 if (c == 'e')
414 {
415 if (expr++)
416 return ('e'); /* will cause syntax error */
417 continue;
418 }
419
420 /* end of number */
421 break;
422 }
423 *cp = '\0';
424
425 if ((cp - buf) >= BSZ)
426 printf("constant too long: truncated\n");
427 else
428 ungetc(c, stdin); /* push back last char read */
429 yylval.dval = atof(buf);
430 return (CONST);
431 }
432 return (c);
433 }
434
435 static INTERVAL
hilo(double a,double b,double c,double d)436 hilo(double a, double b, double c, double d)
437 {
438 /* returns the smallest interval containing a, b, c, and d */
439 /* used by *, / routines */
440 INTERVAL v;
441
442 if (a > b)
443 {
444 v.hi = a;
445 v.lo = b;
446 }
447 else
448 {
449 v.hi = b;
450 v.lo = a;
451 }
452
453 if (c > d)
454 {
455 if (c > v.hi)
456 v.hi = c;
457 if (d < v.lo)
458 v.lo = d;
459 }
460 else
461 {
462 if (d > v.hi)
463 v.hi = d;
464 if (c < v.lo)
465 v.lo = c;
466 }
467 return (v);
468 }
469
470 INTERVAL
vmul(double a,double b,INTERVAL v)471 vmul(double a, double b, INTERVAL v)
472 {
473 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo));
474 }
475
476 int
dcheck(INTERVAL v)477 dcheck(INTERVAL v)
478 {
479 if (v.hi >= 0. && v.lo <= 0.)
480 {
481 printf("divisor interval contains 0.\n");
482 return (1);
483 }
484 return (0);
485 }
486
487 INTERVAL
vdiv(double a,double b,INTERVAL v)488 vdiv(double a, double b, INTERVAL v)
489 {
490 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo));
491 }
492 #line 493 "calc1.tab.c"
493
494 #if YYDEBUG
495 #include <stdio.h> /* needed for printf */
496 #endif
497
498 #include <stdlib.h> /* needed for malloc, etc */
499 #include <string.h> /* needed for memset */
500
501 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
yygrowstack(YYSTACKDATA * data)502 static int yygrowstack(YYSTACKDATA *data)
503 {
504 int i;
505 unsigned newsize;
506 YYINT *newss;
507 YYSTYPE *newvs;
508
509 if ((newsize = data->stacksize) == 0)
510 newsize = YYINITSTACKSIZE;
511 else if (newsize >= YYMAXDEPTH)
512 return YYENOMEM;
513 else if ((newsize *= 2) > YYMAXDEPTH)
514 newsize = YYMAXDEPTH;
515
516 i = (int) (data->s_mark - data->s_base);
517 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
518 if (newss == NULL)
519 return YYENOMEM;
520
521 data->s_base = newss;
522 data->s_mark = newss + i;
523
524 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
525 if (newvs == NULL)
526 return YYENOMEM;
527
528 data->l_base = newvs;
529 data->l_mark = newvs + i;
530
531 data->stacksize = newsize;
532 data->s_last = data->s_base + newsize - 1;
533 return 0;
534 }
535
536 #if YYPURE || defined(YY_NO_LEAKS)
yyfreestack(YYSTACKDATA * data)537 static void yyfreestack(YYSTACKDATA *data)
538 {
539 free(data->s_base);
540 free(data->l_base);
541 memset(data, 0, sizeof(*data));
542 }
543 #else
544 #define yyfreestack(data) /* nothing */
545 #endif
546
547 #define YYABORT goto yyabort
548 #define YYREJECT goto yyabort
549 #define YYACCEPT goto yyaccept
550 #define YYERROR goto yyerrlab
551
552 int
YYPARSE_DECL()553 YYPARSE_DECL()
554 {
555 int yym, yyn, yystate;
556 #if YYDEBUG
557 const char *yys;
558
559 if ((yys = getenv("YYDEBUG")) != NULL)
560 {
561 yyn = *yys;
562 if (yyn >= '0' && yyn <= '9')
563 yydebug = yyn - '0';
564 }
565 #endif
566
567 /* yym is set below */
568 /* yyn is set below */
569 yynerrs = 0;
570 yyerrflag = 0;
571 yychar = YYEMPTY;
572 yystate = 0;
573
574 #if YYPURE
575 memset(&yystack, 0, sizeof(yystack));
576 #endif
577
578 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
579 yystack.s_mark = yystack.s_base;
580 yystack.l_mark = yystack.l_base;
581 yystate = 0;
582 *yystack.s_mark = 0;
583
584 yyloop:
585 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
586 if (yychar < 0)
587 {
588 yychar = YYLEX;
589 if (yychar < 0) yychar = YYEOF;
590 #if YYDEBUG
591 if (yydebug)
592 {
593 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
594 printf("%sdebug: state %d, reading %d (%s)\n",
595 YYPREFIX, yystate, yychar, yys);
596 }
597 #endif
598 }
599 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
600 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
601 {
602 #if YYDEBUG
603 if (yydebug)
604 printf("%sdebug: state %d, shifting to state %d\n",
605 YYPREFIX, yystate, yytable[yyn]);
606 #endif
607 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
608 yystate = yytable[yyn];
609 *++yystack.s_mark = yytable[yyn];
610 *++yystack.l_mark = yylval;
611 yychar = YYEMPTY;
612 if (yyerrflag > 0) --yyerrflag;
613 goto yyloop;
614 }
615 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
616 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
617 {
618 yyn = yytable[yyn];
619 goto yyreduce;
620 }
621 if (yyerrflag != 0) goto yyinrecovery;
622
623 YYERROR_CALL("syntax error");
624
625 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
626 yyerrlab:
627 ++yynerrs;
628
629 yyinrecovery:
630 if (yyerrflag < 3)
631 {
632 yyerrflag = 3;
633 for (;;)
634 {
635 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
636 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
637 {
638 #if YYDEBUG
639 if (yydebug)
640 printf("%sdebug: state %d, error recovery shifting\
641 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
642 #endif
643 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
644 yystate = yytable[yyn];
645 *++yystack.s_mark = yytable[yyn];
646 *++yystack.l_mark = yylval;
647 goto yyloop;
648 }
649 else
650 {
651 #if YYDEBUG
652 if (yydebug)
653 printf("%sdebug: error recovery discarding state %d\n",
654 YYPREFIX, *yystack.s_mark);
655 #endif
656 if (yystack.s_mark <= yystack.s_base) goto yyabort;
657 --yystack.s_mark;
658 --yystack.l_mark;
659 }
660 }
661 }
662 else
663 {
664 if (yychar == YYEOF) goto yyabort;
665 #if YYDEBUG
666 if (yydebug)
667 {
668 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
669 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
670 YYPREFIX, yystate, yychar, yys);
671 }
672 #endif
673 yychar = YYEMPTY;
674 goto yyloop;
675 }
676
677 yyreduce:
678 #if YYDEBUG
679 if (yydebug)
680 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
681 YYPREFIX, yystate, yyn, yyrule[yyn]);
682 #endif
683 yym = yylen[yyn];
684 if (yym > 0)
685 yyval = yystack.l_mark[1-yym];
686 else
687 memset(&yyval, 0, sizeof yyval);
688
689 switch (yyn)
690 {
691 case 3:
692 #line 57 "calc1.y"
693 {
694 (void) printf("%15.8f\n", yystack.l_mark[-1].dval);
695 }
696 #line 697 "calc1.tab.c"
697 break;
698 case 4:
699 #line 61 "calc1.y"
700 {
701 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi);
702 }
703 #line 704 "calc1.tab.c"
704 break;
705 case 5:
706 #line 65 "calc1.y"
707 {
708 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval;
709 }
710 #line 711 "calc1.tab.c"
711 break;
712 case 6:
713 #line 69 "calc1.y"
714 {
715 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval;
716 }
717 #line 718 "calc1.tab.c"
718 break;
719 case 7:
720 #line 73 "calc1.y"
721 {
722 yyerrok;
723 }
724 #line 725 "calc1.tab.c"
725 break;
726 case 9:
727 #line 80 "calc1.y"
728 {
729 yyval.dval = dreg[yystack.l_mark[0].ival];
730 }
731 #line 732 "calc1.tab.c"
732 break;
733 case 10:
734 #line 84 "calc1.y"
735 {
736 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval;
737 }
738 #line 739 "calc1.tab.c"
739 break;
740 case 11:
741 #line 88 "calc1.y"
742 {
743 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval;
744 }
745 #line 746 "calc1.tab.c"
746 break;
747 case 12:
748 #line 92 "calc1.y"
749 {
750 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval;
751 }
752 #line 753 "calc1.tab.c"
753 break;
754 case 13:
755 #line 96 "calc1.y"
756 {
757 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval;
758 }
759 #line 760 "calc1.tab.c"
760 break;
761 case 14:
762 #line 100 "calc1.y"
763 {
764 yyval.dval = -yystack.l_mark[0].dval;
765 }
766 #line 767 "calc1.tab.c"
767 break;
768 case 15:
769 #line 104 "calc1.y"
770 {
771 yyval.dval = yystack.l_mark[-1].dval;
772 }
773 #line 774 "calc1.tab.c"
774 break;
775 case 16:
776 #line 110 "calc1.y"
777 {
778 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval;
779 }
780 #line 781 "calc1.tab.c"
781 break;
782 case 17:
783 #line 114 "calc1.y"
784 {
785 yyval.vval.lo = yystack.l_mark[-3].dval;
786 yyval.vval.hi = yystack.l_mark[-1].dval;
787 if ( yyval.vval.lo > yyval.vval.hi )
788 {
789 (void) printf("interval out of order\n");
790 YYERROR;
791 }
792 }
793 #line 794 "calc1.tab.c"
794 break;
795 case 18:
796 #line 124 "calc1.y"
797 {
798 yyval.vval = vreg[yystack.l_mark[0].ival];
799 }
800 #line 801 "calc1.tab.c"
801 break;
802 case 19:
803 #line 128 "calc1.y"
804 {
805 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi;
806 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo;
807 }
808 #line 809 "calc1.tab.c"
809 break;
810 case 20:
811 #line 133 "calc1.y"
812 {
813 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi;
814 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo;
815 }
816 #line 817 "calc1.tab.c"
817 break;
818 case 21:
819 #line 138 "calc1.y"
820 {
821 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo;
822 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi;
823 }
824 #line 825 "calc1.tab.c"
825 break;
826 case 22:
827 #line 143 "calc1.y"
828 {
829 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo;
830 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi;
831 }
832 #line 833 "calc1.tab.c"
833 break;
834 case 23:
835 #line 148 "calc1.y"
836 {
837 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
838 }
839 #line 840 "calc1.tab.c"
840 break;
841 case 24:
842 #line 152 "calc1.y"
843 {
844 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
845 }
846 #line 847 "calc1.tab.c"
847 break;
848 case 25:
849 #line 156 "calc1.y"
850 {
851 if (dcheck(yystack.l_mark[0].vval)) YYERROR;
852 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
853 }
854 #line 855 "calc1.tab.c"
855 break;
856 case 26:
857 #line 161 "calc1.y"
858 {
859 if (dcheck ( yystack.l_mark[0].vval )) YYERROR;
860 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
861 }
862 #line 863 "calc1.tab.c"
863 break;
864 case 27:
865 #line 166 "calc1.y"
866 {
867 yyval.vval.hi = -yystack.l_mark[0].vval.lo;
868 yyval.vval.lo = -yystack.l_mark[0].vval.hi;
869 }
870 #line 871 "calc1.tab.c"
871 break;
872 case 28:
873 #line 171 "calc1.y"
874 {
875 yyval.vval = yystack.l_mark[-1].vval;
876 }
877 #line 878 "calc1.tab.c"
878 break;
879 #line 880 "calc1.tab.c"
880 }
881 yystack.s_mark -= yym;
882 yystate = *yystack.s_mark;
883 yystack.l_mark -= yym;
884 yym = yylhs[yyn];
885 if (yystate == 0 && yym == 0)
886 {
887 #if YYDEBUG
888 if (yydebug)
889 printf("%sdebug: after reduction, shifting from state 0 to\
890 state %d\n", YYPREFIX, YYFINAL);
891 #endif
892 yystate = YYFINAL;
893 *++yystack.s_mark = YYFINAL;
894 *++yystack.l_mark = yyval;
895 if (yychar < 0)
896 {
897 yychar = YYLEX;
898 if (yychar < 0) yychar = YYEOF;
899 #if YYDEBUG
900 if (yydebug)
901 {
902 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
903 printf("%sdebug: state %d, reading %d (%s)\n",
904 YYPREFIX, YYFINAL, yychar, yys);
905 }
906 #endif
907 }
908 if (yychar == YYEOF) goto yyaccept;
909 goto yyloop;
910 }
911 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
912 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
913 yystate = yytable[yyn];
914 else
915 yystate = yydgoto[yym];
916 #if YYDEBUG
917 if (yydebug)
918 printf("%sdebug: after reduction, shifting from state %d \
919 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
920 #endif
921 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
922 *++yystack.s_mark = (YYINT) yystate;
923 *++yystack.l_mark = yyval;
924 goto yyloop;
925
926 yyoverflow:
927 YYERROR_CALL("yacc stack overflow");
928
929 yyabort:
930 yyfreestack(&yystack);
931 return (1);
932
933 yyaccept:
934 yyfreestack(&yystack);
935 return (0);
936 }
937