2 /* A Bison parser, made from rpcalc.y
3 by GNU Bison version 1.27
6 #define YYBISON 1 /* Identify Bison output. */
12 #define YYSTYPE double
31 #define YYTRANSLATE(x) ((unsigned)(x) <= 257 ? yytranslate[x] : 14)
33 static const char yytranslate[] = { 0,
34 2, 2, 2, 2, 2, 2, 2, 2, 2, 4,
35 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
36 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
37 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
38 2, 7, 5, 2, 6, 2, 8, 2, 2, 2,
39 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
40 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
41 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
42 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
43 2, 2, 2, 9, 2, 2, 2, 2, 2, 2,
44 2, 2, 2, 2, 2, 2, 2, 2, 2, 10,
45 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
46 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
47 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
48 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
50 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
51 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
52 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
53 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
54 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
55 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
56 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
57 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
58 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
63 static const short yyprhs[] = { 0,
64 0, 1, 4, 6, 9, 11, 15, 19, 23, 27,
68 static const short yyrhs[] = { -1,
69 11, 12, 0, 4, 0, 13, 4, 0, 3, 0,
70 13, 13, 5, 0, 13, 13, 6, 0, 13, 13,
71 7, 0, 13, 13, 8, 0, 13, 13, 9, 0,
78 static const short yyrline[] = { 0,
79 11, 12, 15, 16, 19, 20, 21, 22, 23, 25,
85 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
87 static const char * const yytname[] = { "$","error","$undefined.","NUM","'\\n'",
88 "'+'","'-'","'*'","'/'","'^'","'n'","input","line","exp", NULL
92 static const short yyr1[] = { 0,
93 11, 11, 12, 12, 13, 13, 13, 13, 13, 13,
97 static const short yyr2[] = { 0,
98 0, 2, 1, 2, 1, 3, 3, 3, 3, 3,
102 static const short yydefact[] = { 1,
103 0, 5, 3, 2, 0, 4, 11, 0, 6, 7,
107 static const short yydefgoto[] = { 1,
111 static const short yypact[] = {-32768,
112 10,-32768,-32768,-32768, 5,-32768,-32768, -3,-32768,-32768,
113 -32768,-32768,-32768, 1,-32768
116 static const short yypgoto[] = {-32768,
124 static const short yytable[] = { 2,
125 15, 9, 10, 11, 12, 13, 7, 2, 6, 14,
129 static const short yycheck[] = { 3,
130 0, 5, 6, 7, 8, 9, 10, 3, 4, 0,
133 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
134 #line 3 "/usr/lib/bison.simple"
135 /* This file comes from bison-1.27. */
137 /* Skeleton output parser for bison,
138 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
140 This program is free software; you can redistribute it and/or modify
141 it under the terms of the GNU General Public License as published by
142 the Free Software Foundation; either version 2, or (at your option)
145 This program is distributed in the hope that it will be useful,
146 but WITHOUT ANY WARRANTY; without even the implied warranty of
147 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148 GNU General Public License for more details.
150 You should have received a copy of the GNU General Public License
151 along with this program; if not, write to the Free Software
152 Foundation, Inc., 59 Temple Place - Suite 330,
153 Boston, MA 02111-1307, USA. */
155 /* As a special exception, when this file is copied by Bison into a
156 Bison output file, you may use that output file without restriction.
157 This special exception was added by the Free Software Foundation
158 in version 1.24 of Bison. */
160 /* This is the parser code that is written into each bison parser
161 when the %semantic_parser declaration is not specified in the grammar.
162 It was written by Richard Stallman by simplifying the hairy parser
163 used when %semantic_parser is specified. */
165 #ifndef YYSTACK_USE_ALLOCA
167 #define YYSTACK_USE_ALLOCA
168 #else /* alloca not defined */
170 #define YYSTACK_USE_ALLOCA
171 #define alloca __builtin_alloca
172 #else /* not GNU C. */
173 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
174 #define YYSTACK_USE_ALLOCA
176 #else /* not sparc */
177 /* We think this test detects Watcom and Microsoft C. */
178 /* This used to test MSDOS, but that is a bad idea
179 since that symbol is in the user namespace. */
180 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
181 #if 0 /* No need for malloc.h, which pollutes the namespace;
182 instead, just don't use alloca. */
185 #else /* not MSDOS, or __TURBOC__ */
187 /* I don't know what this was needed for, but it pollutes the namespace.
188 So I turned it off. rms, 2 May 1997. */
189 /* #include <malloc.h> */
191 #define YYSTACK_USE_ALLOCA
192 #else /* not MSDOS, or __TURBOC__, or _AIX */
194 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
195 and on HPUX 10. Eventually we can turn this on. */
196 #define YYSTACK_USE_ALLOCA
197 #define alloca __builtin_alloca
200 #endif /* not _AIX */
201 #endif /* not MSDOS, or __TURBOC__ */
202 #endif /* not sparc */
203 #endif /* not GNU C */
204 #endif /* alloca not defined */
205 #endif /* YYSTACK_USE_ALLOCA not defined */
207 #ifdef YYSTACK_USE_ALLOCA
208 #define YYSTACK_ALLOC alloca
210 #define YYSTACK_ALLOC malloc
213 /* Note: there must be only one dollar sign in this file.
214 It is replaced by the list of actions, each action
215 as one case of the switch. */
217 #define yyerrok (yyerrstatus = 0)
218 #define yyclearin (yychar = YYEMPTY)
221 #define YYACCEPT goto yyacceptlab
222 #define YYABORT goto yyabortlab
223 #define YYERROR goto yyerrlab1
224 /* Like YYERROR except do call yyerror.
225 This remains here temporarily to ease the
226 transition to the new meaning of YYERROR, for GCC.
227 Once GCC version 2 has supplanted version 1, this can go. */
228 #define YYFAIL goto yyerrlab
229 #define YYRECOVERING() (!!yyerrstatus)
230 #define YYBACKUP(token, value) \
232 if (yychar == YYEMPTY && yylen == 1) \
233 { yychar = (token), yylval = (value); \
234 yychar1 = YYTRANSLATE (yychar); \
239 { yyerror ("syntax error: cannot back up"); YYERROR; } \
243 #define YYERRCODE 256
246 #define YYLEX yylex()
252 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
254 #define YYLEX yylex(&yylval, &yylloc)
256 #else /* not YYLSP_NEEDED */
258 #define YYLEX yylex(&yylval, YYLEX_PARAM)
260 #define YYLEX yylex(&yylval)
262 #endif /* not YYLSP_NEEDED */
265 /* If nonreentrant, generate the variables here */
269 int yychar; /* the lookahead symbol */
270 YYSTYPE yylval; /* the semantic value of the */
271 /* lookahead symbol */
274 YYLTYPE yylloc; /* location data for the lookahead */
278 int yynerrs; /* number of parse errors so far */
279 #endif /* not YYPURE */
282 int yydebug; /* nonzero means print parse trace */
283 /* Since this is uninitialized, it does not stop multiple parsers
287 /* YYINITDEPTH indicates the initial size of the parser's stacks */
290 #define YYINITDEPTH 200
293 /* YYMAXDEPTH is the maximum size the stacks can grow to
294 (effective only if the built-in stack extension method is used). */
301 #define YYMAXDEPTH 10000
304 /* Define __yy_memcpy. Note that the size argument
305 should be passed with type unsigned int, because that is what the non-GCC
306 definitions require. With GCC, __builtin_memcpy takes an arg
307 of type size_t, but it can handle unsigned int. */
309 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
310 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
311 #else /* not GNU C or C++ */
314 /* This is the most reliable way to avoid incompatibilities
315 in available built-in functions on various systems. */
317 __yy_memcpy (to, from, count)
322 register char *f = from;
323 register char *t = to;
324 register int i = count;
330 #else /* __cplusplus */
332 /* This is the most reliable way to avoid incompatibilities
333 in available built-in functions on various systems. */
335 __yy_memcpy (char *to, char *from, unsigned int count)
337 register char *t = to;
338 register char *f = from;
339 register int i = count;
348 #line 216 "/usr/lib/bison.simple"
350 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
351 into yyparse. The argument should have type void *.
352 It should actually point to an object.
353 Grammar actions can access the variable by casting it
354 to the proper pointer type. */
358 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
359 #define YYPARSE_PARAM_DECL
360 #else /* not __cplusplus */
361 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
362 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
363 #endif /* not __cplusplus */
364 #else /* not YYPARSE_PARAM */
365 #define YYPARSE_PARAM_ARG
366 #define YYPARSE_PARAM_DECL
367 #endif /* not YYPARSE_PARAM */
369 /* Prevent warning if -Wstrict-prototypes. */
372 int yyparse (void *);
379 yyparse(YYPARSE_PARAM_ARG)
382 register int yystate;
384 register short *yyssp;
385 register YYSTYPE *yyvsp;
386 int yyerrstatus; /* number of tokens to shift before error messages enabled */
387 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
389 short yyssa[YYINITDEPTH]; /* the state stack */
390 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
392 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
393 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
396 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
397 YYLTYPE *yyls = yylsa;
400 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
402 #define YYPOPSTACK (yyvsp--, yyssp--)
405 int yystacksize = YYINITDEPTH;
406 int yyfree_stacks = 0;
417 YYSTYPE yyval; /* the variable used to return */
418 /* semantic values from the action */
425 fprintf(stderr, "Starting parse\n");
431 yychar = YYEMPTY; /* Cause a token to be read. */
433 /* Initialize stack pointers.
434 Waste one element of value and location stack
435 so that they stay on the same level as the state stack.
436 The wasted elements are never initialized. */
444 /* Push a new state, which is found in yystate . */
445 /* In all cases, when you get here, the value and location stacks
446 have just been pushed. so pushing a state here evens the stacks. */
451 if (yyssp >= yyss + yystacksize - 1)
453 /* Give user a chance to reallocate the stack */
454 /* Use copies of these so that the &'s don't force the real ones into memory. */
455 YYSTYPE *yyvs1 = yyvs;
458 YYLTYPE *yyls1 = yyls;
461 /* Get the current used size of the three stacks, in elements. */
462 int size = yyssp - yyss + 1;
465 /* Each stack pointer address is followed by the size of
466 the data in use in that stack, in bytes. */
468 /* This used to be a conditional around just the two extra args,
469 but that might be undefined if yyoverflow is a macro. */
470 yyoverflow("parser stack overflow",
471 &yyss1, size * sizeof (*yyssp),
472 &yyvs1, size * sizeof (*yyvsp),
473 &yyls1, size * sizeof (*yylsp),
476 yyoverflow("parser stack overflow",
477 &yyss1, size * sizeof (*yyssp),
478 &yyvs1, size * sizeof (*yyvsp),
482 yyss = yyss1; yyvs = yyvs1;
486 #else /* no yyoverflow */
487 /* Extend the stack our own way. */
488 if (yystacksize >= YYMAXDEPTH)
490 yyerror("parser stack overflow");
502 if (yystacksize > YYMAXDEPTH)
503 yystacksize = YYMAXDEPTH;
504 #ifndef YYSTACK_USE_ALLOCA
507 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
508 __yy_memcpy ((char *)yyss, (char *)yyss1,
509 size * (unsigned int) sizeof (*yyssp));
510 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
511 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
512 size * (unsigned int) sizeof (*yyvsp));
514 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
515 __yy_memcpy ((char *)yyls, (char *)yyls1,
516 size * (unsigned int) sizeof (*yylsp));
518 #endif /* no yyoverflow */
520 yyssp = yyss + size - 1;
521 yyvsp = yyvs + size - 1;
523 yylsp = yyls + size - 1;
528 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
531 if (yyssp >= yyss + yystacksize - 1)
537 fprintf(stderr, "Entering state %d\n", yystate);
543 /* Do appropriate processing given the current state. */
544 /* Read a lookahead token if we need one and don't already have one. */
547 /* First try to decide what to do without reference to lookahead token. */
549 yyn = yypact[yystate];
553 /* Not known => get a lookahead token if don't already have one. */
555 /* yychar is either YYEMPTY or YYEOF
556 or a valid token in external form. */
558 if (yychar == YYEMPTY)
562 fprintf(stderr, "Reading a token: ");
567 /* Convert token to internal form (in yychar1) for indexing tables with */
569 if (yychar <= 0) /* This means end of input. */
572 yychar = YYEOF; /* Don't call YYLEX any more */
576 fprintf(stderr, "Now at end of input.\n");
581 yychar1 = YYTRANSLATE(yychar);
586 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
587 /* Give the individual parser a way to print the precise meaning
588 of a token, for further debugging info. */
590 YYPRINT (stderr, yychar, yylval);
592 fprintf (stderr, ")\n");
598 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
603 /* yyn is what to do for this token type in this state.
604 Negative => reduce, -yyn is rule number.
605 Positive => shift, yyn is new state.
606 New state is final state => don't bother to shift,
608 0, or most negative number => error. */
623 /* Shift the lookahead token. */
627 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
630 /* Discard the token being shifted unless it is eof. */
639 /* count tokens shifted since error; after three, turn off error status. */
640 if (yyerrstatus) yyerrstatus--;
645 /* Do the default action for the current state. */
648 yyn = yydefact[yystate];
652 /* Do a reduction. yyn is the number of a rule to reduce with. */
656 yyval = yyvsp[1-yylen]; /* implement default value of the action */
663 fprintf (stderr, "Reducing via rule %d (line %d), ",
666 /* Print the symbols being reduced, and their result. */
667 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
668 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
669 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
678 { printf ("\t%.10g\n", yyvsp[-1]); ;
682 { yyval = yyvsp[0]; ;
686 { yyval = yyvsp[-2] + yyvsp[-1]; ;
690 { yyval = yyvsp[-2] - yyvsp[-1]; ;
694 { yyval = yyvsp[-2] * yyvsp[-1]; ;
698 { yyval = yyvsp[-2] / yyvsp[-1]; ;
702 { yyval = pow (yyvsp[-2], yyvsp[-1]); ;
706 { yyval = -yyvsp[-1]; ;
709 /* the action file gets copied in in place of this dollarsign */
710 #line 542 "/usr/lib/bison.simple"
721 short *ssp1 = yyss - 1;
722 fprintf (stderr, "state stack now");
723 while (ssp1 != yyssp)
724 fprintf (stderr, " %d", *++ssp1);
725 fprintf (stderr, "\n");
735 yylsp->first_line = yylloc.first_line;
736 yylsp->first_column = yylloc.first_column;
737 yylsp->last_line = (yylsp-1)->last_line;
738 yylsp->last_column = (yylsp-1)->last_column;
743 yylsp->last_line = (yylsp+yylen-1)->last_line;
744 yylsp->last_column = (yylsp+yylen-1)->last_column;
748 /* Now "shift" the result of the reduction.
749 Determine what state that goes to,
750 based on the state we popped back to
751 and the rule number reduced by. */
755 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
756 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
757 yystate = yytable[yystate];
759 yystate = yydefgoto[yyn - YYNTBASE];
763 yyerrlab: /* here on detecting error */
766 /* If not already recovering from an error, report this error. */
770 #ifdef YYERROR_VERBOSE
771 yyn = yypact[yystate];
773 if (yyn > YYFLAG && yyn < YYLAST)
780 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
781 for (x = (yyn < 0 ? -yyn : 0);
782 x < (sizeof(yytname) / sizeof(char *)); x++)
783 if (yycheck[x + yyn] == x)
784 size += strlen(yytname[x]) + 15, count++;
785 msg = (char *) malloc(size + 15);
788 strcpy(msg, "parse error");
793 for (x = (yyn < 0 ? -yyn : 0);
794 x < (sizeof(yytname) / sizeof(char *)); x++)
795 if (yycheck[x + yyn] == x)
797 strcat(msg, count == 0 ? ", expecting `" : " or `");
798 strcat(msg, yytname[x]);
807 yyerror ("parse error; also virtual memory exceeded");
810 #endif /* YYERROR_VERBOSE */
811 yyerror("parse error");
815 yyerrlab1: /* here on error raised explicitly by an action */
817 if (yyerrstatus == 3)
819 /* if just tried and failed to reuse lookahead token after an error, discard it. */
821 /* return failure if at end of input */
827 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
833 /* Else will try to reuse lookahead token
834 after shifting the error token. */
836 yyerrstatus = 3; /* Each real token shifted decrements this */
840 yyerrdefault: /* current state does not do anything special for the error token. */
843 /* This is wrong; only states that explicitly want error tokens
844 should shift them. */
845 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
846 if (yyn) goto yydefault;
849 yyerrpop: /* pop the current state because it cannot handle the error token */
851 if (yyssp == yyss) YYABORT;
861 short *ssp1 = yyss - 1;
862 fprintf (stderr, "Error: state stack now");
863 while (ssp1 != yyssp)
864 fprintf (stderr, " %d", *++ssp1);
865 fprintf (stderr, "\n");
871 yyn = yypact[yystate];
876 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
895 fprintf(stderr, "Shifting error token, ");
907 /* YYACCEPT comes here. */
919 /* YYABORT comes here. */
934 /* Lexical analyzer returns a double floating point
935 number on the stack and the token NUM, or the ASCII
936 character read if not a number. Skips all blanks
937 and tabs, returns 0 for EOF. */
945 /* skip white space */
946 while ((c = getchar ()) == ' ' || c == '\t')
948 /* process numbers */
949 if (c == '.' || isdigit (c))
952 scanf ("%lf", &yylval);
955 /* return end-of-file */
958 /* return single chars */
972 yyerror (s) /* Called by yyparse on error */