High-level changes:
[xuni.git] / src / calc.c
blobfb2ddfcf8484886c01e93f1cc3cdfa11fd2d5aca
1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
39 /* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
46 /* Identify Bison output. */
47 #define YYBISON 1
49 /* Bison version. */
50 #define YYBISON_VERSION "2.3"
52 /* Skeleton name. */
53 #define YYSKELETON_NAME "yacc.c"
55 /* Pure parsers. */
56 #define YYPURE 0
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
63 /* Tokens. */
64 #ifndef YYTOKENTYPE
65 # define YYTOKENTYPE
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
67 know about them. */
68 enum yytokentype {
69 NUM = 258,
70 NEG = 259
72 #endif
73 /* Tokens. */
74 #define NUM 258
75 #define NEG 259
80 /* Copy the first part of user declarations. */
81 #line 1 "calc.y"
83 #include <stdio.h> /* for printf() */
84 #include <stdlib.h> /* for strtod() */
85 #include <ctype.h>
86 #include <math.h> /* for pow() */
88 #define YYSTYPE double
90 int yylex(void);
91 void yyerror(const char *);
93 YYSTYPE yyreturn;
96 /* Enabling traces. */
97 #ifndef YYDEBUG
98 # define YYDEBUG 0
99 #endif
101 /* Enabling verbose error messages. */
102 #ifdef YYERROR_VERBOSE
103 # undef YYERROR_VERBOSE
104 # define YYERROR_VERBOSE 1
105 #else
106 # define YYERROR_VERBOSE 0
107 #endif
109 /* Enabling the token table. */
110 #ifndef YYTOKEN_TABLE
111 # define YYTOKEN_TABLE 0
112 #endif
114 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
115 typedef int YYSTYPE;
116 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
117 # define YYSTYPE_IS_DECLARED 1
118 # define YYSTYPE_IS_TRIVIAL 1
119 #endif
123 /* Copy the second part of user declarations. */
126 /* Line 216 of yacc.c. */
127 #line 128 "calc.c"
129 #ifdef short
130 # undef short
131 #endif
133 #ifdef YYTYPE_UINT8
134 typedef YYTYPE_UINT8 yytype_uint8;
135 #else
136 typedef unsigned char yytype_uint8;
137 #endif
139 #ifdef YYTYPE_INT8
140 typedef YYTYPE_INT8 yytype_int8;
141 #elif (defined __STDC__ || defined __C99__FUNC__ \
142 || defined __cplusplus || defined _MSC_VER)
143 typedef signed char yytype_int8;
144 #else
145 typedef short int yytype_int8;
146 #endif
148 #ifdef YYTYPE_UINT16
149 typedef YYTYPE_UINT16 yytype_uint16;
150 #else
151 typedef unsigned short int yytype_uint16;
152 #endif
154 #ifdef YYTYPE_INT16
155 typedef YYTYPE_INT16 yytype_int16;
156 #else
157 typedef short int yytype_int16;
158 #endif
160 #ifndef YYSIZE_T
161 # ifdef __SIZE_TYPE__
162 # define YYSIZE_T __SIZE_TYPE__
163 # elif defined size_t
164 # define YYSIZE_T size_t
165 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
166 || defined __cplusplus || defined _MSC_VER)
167 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
168 # define YYSIZE_T size_t
169 # else
170 # define YYSIZE_T unsigned int
171 # endif
172 #endif
174 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
176 #ifndef YY_
177 # if YYENABLE_NLS
178 # if ENABLE_NLS
179 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
180 # define YY_(msgid) dgettext ("bison-runtime", msgid)
181 # endif
182 # endif
183 # ifndef YY_
184 # define YY_(msgid) msgid
185 # endif
186 #endif
188 /* Suppress unused-variable warnings by "using" E. */
189 #if ! defined lint || defined __GNUC__
190 # define YYUSE(e) ((void) (e))
191 #else
192 # define YYUSE(e) /* empty */
193 #endif
195 /* Identity function, used to suppress warnings about constant conditions. */
196 #ifndef lint
197 # define YYID(n) (n)
198 #else
199 #if (defined __STDC__ || defined __C99__FUNC__ \
200 || defined __cplusplus || defined _MSC_VER)
201 static int
202 YYID (int i)
203 #else
204 static int
205 YYID (i)
206 int i;
207 #endif
209 return i;
211 #endif
213 #if ! defined yyoverflow || YYERROR_VERBOSE
215 /* The parser invokes alloca or malloc; define the necessary symbols. */
217 # ifdef YYSTACK_USE_ALLOCA
218 # if YYSTACK_USE_ALLOCA
219 # ifdef __GNUC__
220 # define YYSTACK_ALLOC __builtin_alloca
221 # elif defined __BUILTIN_VA_ARG_INCR
222 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
223 # elif defined _AIX
224 # define YYSTACK_ALLOC __alloca
225 # elif defined _MSC_VER
226 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
227 # define alloca _alloca
228 # else
229 # define YYSTACK_ALLOC alloca
230 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
231 || defined __cplusplus || defined _MSC_VER)
232 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
233 # ifndef _STDLIB_H
234 # define _STDLIB_H 1
235 # endif
236 # endif
237 # endif
238 # endif
239 # endif
241 # ifdef YYSTACK_ALLOC
242 /* Pacify GCC's `empty if-body' warning. */
243 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
244 # ifndef YYSTACK_ALLOC_MAXIMUM
245 /* The OS might guarantee only one guard page at the bottom of the stack,
246 and a page size can be as small as 4096 bytes. So we cannot safely
247 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
248 to allow for a few compiler-allocated temporary stack slots. */
249 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
250 # endif
251 # else
252 # define YYSTACK_ALLOC YYMALLOC
253 # define YYSTACK_FREE YYFREE
254 # ifndef YYSTACK_ALLOC_MAXIMUM
255 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
256 # endif
257 # if (defined __cplusplus && ! defined _STDLIB_H \
258 && ! ((defined YYMALLOC || defined malloc) \
259 && (defined YYFREE || defined free)))
260 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
261 # ifndef _STDLIB_H
262 # define _STDLIB_H 1
263 # endif
264 # endif
265 # ifndef YYMALLOC
266 # define YYMALLOC malloc
267 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
268 || defined __cplusplus || defined _MSC_VER)
269 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
270 # endif
271 # endif
272 # ifndef YYFREE
273 # define YYFREE free
274 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
275 || defined __cplusplus || defined _MSC_VER)
276 void free (void *); /* INFRINGES ON USER NAME SPACE */
277 # endif
278 # endif
279 # endif
280 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
283 #if (! defined yyoverflow \
284 && (! defined __cplusplus \
285 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
287 /* A type that is properly aligned for any stack member. */
288 union yyalloc
290 yytype_int16 yyss;
291 YYSTYPE yyvs;
294 /* The size of the maximum gap between one aligned stack and the next. */
295 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
297 /* The size of an array large to enough to hold all stacks, each with
298 N elements. */
299 # define YYSTACK_BYTES(N) \
300 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
301 + YYSTACK_GAP_MAXIMUM)
303 /* Copy COUNT objects from FROM to TO. The source and destination do
304 not overlap. */
305 # ifndef YYCOPY
306 # if defined __GNUC__ && 1 < __GNUC__
307 # define YYCOPY(To, From, Count) \
308 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
309 # else
310 # define YYCOPY(To, From, Count) \
311 do \
313 YYSIZE_T yyi; \
314 for (yyi = 0; yyi < (Count); yyi++) \
315 (To)[yyi] = (From)[yyi]; \
317 while (YYID (0))
318 # endif
319 # endif
321 /* Relocate STACK from its old location to the new one. The
322 local variables YYSIZE and YYSTACKSIZE give the old and new number of
323 elements in the stack, and YYPTR gives the new location of the
324 stack. Advance YYPTR to a properly aligned location for the next
325 stack. */
326 # define YYSTACK_RELOCATE(Stack) \
327 do \
329 YYSIZE_T yynewbytes; \
330 YYCOPY (&yyptr->Stack, Stack, yysize); \
331 Stack = &yyptr->Stack; \
332 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
333 yyptr += yynewbytes / sizeof (*yyptr); \
335 while (YYID (0))
337 #endif
339 /* YYFINAL -- State number of the termination state. */
340 #define YYFINAL 8
341 /* YYLAST -- Last index in YYTABLE. */
342 #define YYLAST 28
344 /* YYNTOKENS -- Number of terminals. */
345 #define YYNTOKENS 12
346 /* YYNNTS -- Number of nonterminals. */
347 #define YYNNTS 3
348 /* YYNRULES -- Number of rules. */
349 #define YYNRULES 10
350 /* YYNRULES -- Number of states. */
351 #define YYNSTATES 20
353 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
354 #define YYUNDEFTOK 2
355 #define YYMAXUTOK 259
357 #define YYTRANSLATE(YYX) \
358 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
360 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
361 static const yytype_uint8 yytranslate[] =
363 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
364 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
365 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
366 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
367 10, 11, 6, 5, 2, 4, 2, 7, 2, 2,
368 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
369 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
370 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
371 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
372 2, 2, 2, 2, 9, 2, 2, 2, 2, 2,
373 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
374 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
375 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
376 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
377 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
378 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
379 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
380 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
381 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
382 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
383 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
384 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
385 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
386 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
387 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
388 2, 2, 2, 2, 2, 2, 1, 2, 3, 8
391 #if YYDEBUG
392 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
393 YYRHS. */
394 static const yytype_uint8 yyprhs[] =
396 0, 0, 3, 5, 7, 11, 15, 19, 23, 26,
400 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
401 static const yytype_int8 yyrhs[] =
403 13, 0, -1, 14, -1, 3, -1, 14, 5, 14,
404 -1, 14, 4, 14, -1, 14, 6, 14, -1, 14,
405 7, 14, -1, 4, 14, -1, 14, 9, 14, -1,
406 10, 14, 11, -1
409 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
410 static const yytype_uint8 yyrline[] =
412 0, 23, 23, 26, 27, 28, 29, 30, 31, 32,
415 #endif
417 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
418 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
419 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
420 static const char *const yytname[] =
422 "$end", "error", "$undefined", "NUM", "'-'", "'+'", "'*'", "'/'", "NEG",
423 "'^'", "'('", "')'", "$accept", "line", "exp", 0
425 #endif
427 # ifdef YYPRINT
428 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
429 token YYLEX-NUM. */
430 static const yytype_uint16 yytoknum[] =
432 0, 256, 257, 258, 45, 43, 42, 47, 259, 94,
433 40, 41
435 # endif
437 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
438 static const yytype_uint8 yyr1[] =
440 0, 12, 13, 14, 14, 14, 14, 14, 14, 14,
444 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
445 static const yytype_uint8 yyr2[] =
447 0, 2, 1, 1, 3, 3, 3, 3, 2, 3,
451 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
452 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
453 means the default is an error. */
454 static const yytype_uint8 yydefact[] =
456 0, 3, 0, 0, 0, 2, 8, 0, 1, 0,
457 0, 0, 0, 0, 10, 5, 4, 6, 7, 9
460 /* YYDEFGOTO[NTERM-NUM]. */
461 static const yytype_int8 yydefgoto[] =
463 -1, 4, 5
466 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
467 STATE-NUM. */
468 #define YYPACT_NINF -5
469 static const yytype_int8 yypact[] =
471 17, -5, 17, 17, 4, 19, -3, 8, -5, 17,
472 17, 17, 17, 17, -5, -4, -4, -3, -3, -3
475 /* YYPGOTO[NTERM-NUM]. */
476 static const yytype_int8 yypgoto[] =
478 -5, -5, -2
481 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
482 positive, shift that token. If negative, reduce the rule which
483 number is the opposite. If zero, do what YYDEFACT says.
484 If YYTABLE_NINF, syntax error. */
485 #define YYTABLE_NINF -1
486 static const yytype_uint8 yytable[] =
488 6, 7, 11, 12, 8, 13, 13, 15, 16, 17,
489 18, 19, 9, 10, 11, 12, 0, 13, 0, 14,
490 1, 2, 0, 9, 10, 11, 12, 3, 13
493 static const yytype_int8 yycheck[] =
495 2, 3, 6, 7, 0, 9, 9, 9, 10, 11,
496 12, 13, 4, 5, 6, 7, -1, 9, -1, 11,
497 3, 4, -1, 4, 5, 6, 7, 10, 9
500 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
501 symbol of state STATE-NUM. */
502 static const yytype_uint8 yystos[] =
504 0, 3, 4, 10, 13, 14, 14, 14, 0, 4,
505 5, 6, 7, 9, 11, 14, 14, 14, 14, 14
508 #define yyerrok (yyerrstatus = 0)
509 #define yyclearin (yychar = YYEMPTY)
510 #define YYEMPTY (-2)
511 #define YYEOF 0
513 #define YYACCEPT goto yyacceptlab
514 #define YYABORT goto yyabortlab
515 #define YYERROR goto yyerrorlab
518 /* Like YYERROR except do call yyerror. This remains here temporarily
519 to ease the transition to the new meaning of YYERROR, for GCC.
520 Once GCC version 2 has supplanted version 1, this can go. */
522 #define YYFAIL goto yyerrlab
524 #define YYRECOVERING() (!!yyerrstatus)
526 #define YYBACKUP(Token, Value) \
527 do \
528 if (yychar == YYEMPTY && yylen == 1) \
530 yychar = (Token); \
531 yylval = (Value); \
532 yytoken = YYTRANSLATE (yychar); \
533 YYPOPSTACK (1); \
534 goto yybackup; \
536 else \
538 yyerror (YY_("syntax error: cannot back up")); \
539 YYERROR; \
541 while (YYID (0))
544 #define YYTERROR 1
545 #define YYERRCODE 256
548 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
549 If N is 0, then set CURRENT to the empty location which ends
550 the previous symbol: RHS[0] (always defined). */
552 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
553 #ifndef YYLLOC_DEFAULT
554 # define YYLLOC_DEFAULT(Current, Rhs, N) \
555 do \
556 if (YYID (N)) \
558 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
559 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
560 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
561 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
563 else \
565 (Current).first_line = (Current).last_line = \
566 YYRHSLOC (Rhs, 0).last_line; \
567 (Current).first_column = (Current).last_column = \
568 YYRHSLOC (Rhs, 0).last_column; \
570 while (YYID (0))
571 #endif
574 /* YY_LOCATION_PRINT -- Print the location on the stream.
575 This macro was not mandated originally: define only if we know
576 we won't break user code: when these are the locations we know. */
578 #ifndef YY_LOCATION_PRINT
579 # if YYLTYPE_IS_TRIVIAL
580 # define YY_LOCATION_PRINT(File, Loc) \
581 fprintf (File, "%d.%d-%d.%d", \
582 (Loc).first_line, (Loc).first_column, \
583 (Loc).last_line, (Loc).last_column)
584 # else
585 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
586 # endif
587 #endif
590 /* YYLEX -- calling `yylex' with the right arguments. */
592 #ifdef YYLEX_PARAM
593 # define YYLEX yylex (YYLEX_PARAM)
594 #else
595 # define YYLEX yylex ()
596 #endif
598 /* Enable debugging if requested. */
599 #if YYDEBUG
601 # ifndef YYFPRINTF
602 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
603 # define YYFPRINTF fprintf
604 # endif
606 # define YYDPRINTF(Args) \
607 do { \
608 if (yydebug) \
609 YYFPRINTF Args; \
610 } while (YYID (0))
612 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
613 do { \
614 if (yydebug) \
616 YYFPRINTF (stderr, "%s ", Title); \
617 yy_symbol_print (stderr, \
618 Type, Value); \
619 YYFPRINTF (stderr, "\n"); \
621 } while (YYID (0))
624 /*--------------------------------.
625 | Print this symbol on YYOUTPUT. |
626 `--------------------------------*/
628 /*ARGSUSED*/
629 #if (defined __STDC__ || defined __C99__FUNC__ \
630 || defined __cplusplus || defined _MSC_VER)
631 static void
632 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
633 #else
634 static void
635 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
636 FILE *yyoutput;
637 int yytype;
638 YYSTYPE const * const yyvaluep;
639 #endif
641 if (!yyvaluep)
642 return;
643 # ifdef YYPRINT
644 if (yytype < YYNTOKENS)
645 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
646 # else
647 YYUSE (yyoutput);
648 # endif
649 switch (yytype)
651 default:
652 break;
657 /*--------------------------------.
658 | Print this symbol on YYOUTPUT. |
659 `--------------------------------*/
661 #if (defined __STDC__ || defined __C99__FUNC__ \
662 || defined __cplusplus || defined _MSC_VER)
663 static void
664 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
665 #else
666 static void
667 yy_symbol_print (yyoutput, yytype, yyvaluep)
668 FILE *yyoutput;
669 int yytype;
670 YYSTYPE const * const yyvaluep;
671 #endif
673 if (yytype < YYNTOKENS)
674 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
675 else
676 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
678 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
679 YYFPRINTF (yyoutput, ")");
682 /*------------------------------------------------------------------.
683 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
684 | TOP (included). |
685 `------------------------------------------------------------------*/
687 #if (defined __STDC__ || defined __C99__FUNC__ \
688 || defined __cplusplus || defined _MSC_VER)
689 static void
690 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
691 #else
692 static void
693 yy_stack_print (bottom, top)
694 yytype_int16 *bottom;
695 yytype_int16 *top;
696 #endif
698 YYFPRINTF (stderr, "Stack now");
699 for (; bottom <= top; ++bottom)
700 YYFPRINTF (stderr, " %d", *bottom);
701 YYFPRINTF (stderr, "\n");
704 # define YY_STACK_PRINT(Bottom, Top) \
705 do { \
706 if (yydebug) \
707 yy_stack_print ((Bottom), (Top)); \
708 } while (YYID (0))
711 /*------------------------------------------------.
712 | Report that the YYRULE is going to be reduced. |
713 `------------------------------------------------*/
715 #if (defined __STDC__ || defined __C99__FUNC__ \
716 || defined __cplusplus || defined _MSC_VER)
717 static void
718 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
719 #else
720 static void
721 yy_reduce_print (yyvsp, yyrule)
722 YYSTYPE *yyvsp;
723 int yyrule;
724 #endif
726 int yynrhs = yyr2[yyrule];
727 int yyi;
728 unsigned long int yylno = yyrline[yyrule];
729 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
730 yyrule - 1, yylno);
731 /* The symbols being reduced. */
732 for (yyi = 0; yyi < yynrhs; yyi++)
734 fprintf (stderr, " $%d = ", yyi + 1);
735 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
736 &(yyvsp[(yyi + 1) - (yynrhs)])
738 fprintf (stderr, "\n");
742 # define YY_REDUCE_PRINT(Rule) \
743 do { \
744 if (yydebug) \
745 yy_reduce_print (yyvsp, Rule); \
746 } while (YYID (0))
748 /* Nonzero means print parse trace. It is left uninitialized so that
749 multiple parsers can coexist. */
750 int yydebug;
751 #else /* !YYDEBUG */
752 # define YYDPRINTF(Args)
753 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
754 # define YY_STACK_PRINT(Bottom, Top)
755 # define YY_REDUCE_PRINT(Rule)
756 #endif /* !YYDEBUG */
759 /* YYINITDEPTH -- initial size of the parser's stacks. */
760 #ifndef YYINITDEPTH
761 # define YYINITDEPTH 200
762 #endif
764 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
765 if the built-in stack extension method is used).
767 Do not make this value too large; the results are undefined if
768 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
769 evaluated with infinite-precision integer arithmetic. */
771 #ifndef YYMAXDEPTH
772 # define YYMAXDEPTH 10000
773 #endif
777 #if YYERROR_VERBOSE
779 # ifndef yystrlen
780 # if defined __GLIBC__ && defined _STRING_H
781 # define yystrlen strlen
782 # else
783 /* Return the length of YYSTR. */
784 #if (defined __STDC__ || defined __C99__FUNC__ \
785 || defined __cplusplus || defined _MSC_VER)
786 static YYSIZE_T
787 yystrlen (const char *yystr)
788 #else
789 static YYSIZE_T
790 yystrlen (yystr)
791 const char *yystr;
792 #endif
794 YYSIZE_T yylen;
795 for (yylen = 0; yystr[yylen]; yylen++)
796 continue;
797 return yylen;
799 # endif
800 # endif
802 # ifndef yystpcpy
803 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
804 # define yystpcpy stpcpy
805 # else
806 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
807 YYDEST. */
808 #if (defined __STDC__ || defined __C99__FUNC__ \
809 || defined __cplusplus || defined _MSC_VER)
810 static char *
811 yystpcpy (char *yydest, const char *yysrc)
812 #else
813 static char *
814 yystpcpy (yydest, yysrc)
815 char *yydest;
816 const char *yysrc;
817 #endif
819 char *yyd = yydest;
820 const char *yys = yysrc;
822 while ((*yyd++ = *yys++) != '\0')
823 continue;
825 return yyd - 1;
827 # endif
828 # endif
830 # ifndef yytnamerr
831 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
832 quotes and backslashes, so that it's suitable for yyerror. The
833 heuristic is that double-quoting is unnecessary unless the string
834 contains an apostrophe, a comma, or backslash (other than
835 backslash-backslash). YYSTR is taken from yytname. If YYRES is
836 null, do not copy; instead, return the length of what the result
837 would have been. */
838 static YYSIZE_T
839 yytnamerr (char *yyres, const char *yystr)
841 if (*yystr == '"')
843 YYSIZE_T yyn = 0;
844 char const *yyp = yystr;
846 for (;;)
847 switch (*++yyp)
849 case '\'':
850 case ',':
851 goto do_not_strip_quotes;
853 case '\\':
854 if (*++yyp != '\\')
855 goto do_not_strip_quotes;
856 /* Fall through. */
857 default:
858 if (yyres)
859 yyres[yyn] = *yyp;
860 yyn++;
861 break;
863 case '"':
864 if (yyres)
865 yyres[yyn] = '\0';
866 return yyn;
868 do_not_strip_quotes: ;
871 if (! yyres)
872 return yystrlen (yystr);
874 return yystpcpy (yyres, yystr) - yyres;
876 # endif
878 /* Copy into YYRESULT an error message about the unexpected token
879 YYCHAR while in state YYSTATE. Return the number of bytes copied,
880 including the terminating null byte. If YYRESULT is null, do not
881 copy anything; just return the number of bytes that would be
882 copied. As a special case, return 0 if an ordinary "syntax error"
883 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
884 size calculation. */
885 static YYSIZE_T
886 yysyntax_error (char *yyresult, int yystate, int yychar)
888 int yyn = yypact[yystate];
890 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
891 return 0;
892 else
894 int yytype = YYTRANSLATE (yychar);
895 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
896 YYSIZE_T yysize = yysize0;
897 YYSIZE_T yysize1;
898 int yysize_overflow = 0;
899 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
900 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
901 int yyx;
903 # if 0
904 /* This is so xgettext sees the translatable formats that are
905 constructed on the fly. */
906 YY_("syntax error, unexpected %s");
907 YY_("syntax error, unexpected %s, expecting %s");
908 YY_("syntax error, unexpected %s, expecting %s or %s");
909 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
910 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
911 # endif
912 char *yyfmt;
913 char const *yyf;
914 static char const yyunexpected[] = "syntax error, unexpected %s";
915 static char const yyexpecting[] = ", expecting %s";
916 static char const yyor[] = " or %s";
917 char yyformat[sizeof yyunexpected
918 + sizeof yyexpecting - 1
919 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
920 * (sizeof yyor - 1))];
921 char const *yyprefix = yyexpecting;
923 /* Start YYX at -YYN if negative to avoid negative indexes in
924 YYCHECK. */
925 int yyxbegin = yyn < 0 ? -yyn : 0;
927 /* Stay within bounds of both yycheck and yytname. */
928 int yychecklim = YYLAST - yyn + 1;
929 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
930 int yycount = 1;
932 yyarg[0] = yytname[yytype];
933 yyfmt = yystpcpy (yyformat, yyunexpected);
935 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
936 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
938 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
940 yycount = 1;
941 yysize = yysize0;
942 yyformat[sizeof yyunexpected - 1] = '\0';
943 break;
945 yyarg[yycount++] = yytname[yyx];
946 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
947 yysize_overflow |= (yysize1 < yysize);
948 yysize = yysize1;
949 yyfmt = yystpcpy (yyfmt, yyprefix);
950 yyprefix = yyor;
953 yyf = YY_(yyformat);
954 yysize1 = yysize + yystrlen (yyf);
955 yysize_overflow |= (yysize1 < yysize);
956 yysize = yysize1;
958 if (yysize_overflow)
959 return YYSIZE_MAXIMUM;
961 if (yyresult)
963 /* Avoid sprintf, as that infringes on the user's name space.
964 Don't have undefined behavior even if the translation
965 produced a string with the wrong number of "%s"s. */
966 char *yyp = yyresult;
967 int yyi = 0;
968 while ((*yyp = *yyf) != '\0')
970 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
972 yyp += yytnamerr (yyp, yyarg[yyi++]);
973 yyf += 2;
975 else
977 yyp++;
978 yyf++;
982 return yysize;
985 #endif /* YYERROR_VERBOSE */
988 /*-----------------------------------------------.
989 | Release the memory associated to this symbol. |
990 `-----------------------------------------------*/
992 /*ARGSUSED*/
993 #if (defined __STDC__ || defined __C99__FUNC__ \
994 || defined __cplusplus || defined _MSC_VER)
995 static void
996 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
997 #else
998 static void
999 yydestruct (yymsg, yytype, yyvaluep)
1000 const char *yymsg;
1001 int yytype;
1002 YYSTYPE *yyvaluep;
1003 #endif
1005 YYUSE (yyvaluep);
1007 if (!yymsg)
1008 yymsg = "Deleting";
1009 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1011 switch (yytype)
1014 default:
1015 break;
1020 /* Prevent warnings from -Wmissing-prototypes. */
1022 #ifdef YYPARSE_PARAM
1023 #if defined __STDC__ || defined __cplusplus
1024 int yyparse (void *YYPARSE_PARAM);
1025 #else
1026 int yyparse ();
1027 #endif
1028 #else /* ! YYPARSE_PARAM */
1029 #if defined __STDC__ || defined __cplusplus
1030 int yyparse (void);
1031 #else
1032 int yyparse ();
1033 #endif
1034 #endif /* ! YYPARSE_PARAM */
1038 /* The look-ahead symbol. */
1039 int yychar;
1041 /* The semantic value of the look-ahead symbol. */
1042 YYSTYPE yylval;
1044 /* Number of syntax errors so far. */
1045 int yynerrs;
1049 /*----------.
1050 | yyparse. |
1051 `----------*/
1053 #ifdef YYPARSE_PARAM
1054 #if (defined __STDC__ || defined __C99__FUNC__ \
1055 || defined __cplusplus || defined _MSC_VER)
1057 yyparse (void *YYPARSE_PARAM)
1058 #else
1060 yyparse (YYPARSE_PARAM)
1061 void *YYPARSE_PARAM;
1062 #endif
1063 #else /* ! YYPARSE_PARAM */
1064 #if (defined __STDC__ || defined __C99__FUNC__ \
1065 || defined __cplusplus || defined _MSC_VER)
1067 yyparse (void)
1068 #else
1070 yyparse ()
1072 #endif
1073 #endif
1076 int yystate;
1077 int yyn;
1078 int yyresult;
1079 /* Number of tokens to shift before error messages enabled. */
1080 int yyerrstatus;
1081 /* Look-ahead token as an internal (translated) token number. */
1082 int yytoken = 0;
1083 #if YYERROR_VERBOSE
1084 /* Buffer for error messages, and its allocated size. */
1085 char yymsgbuf[128];
1086 char *yymsg = yymsgbuf;
1087 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1088 #endif
1090 /* Three stacks and their tools:
1091 `yyss': related to states,
1092 `yyvs': related to semantic values,
1093 `yyls': related to locations.
1095 Refer to the stacks thru separate pointers, to allow yyoverflow
1096 to reallocate them elsewhere. */
1098 /* The state stack. */
1099 yytype_int16 yyssa[YYINITDEPTH];
1100 yytype_int16 *yyss = yyssa;
1101 yytype_int16 *yyssp;
1103 /* The semantic value stack. */
1104 YYSTYPE yyvsa[YYINITDEPTH];
1105 YYSTYPE *yyvs = yyvsa;
1106 YYSTYPE *yyvsp;
1110 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1112 YYSIZE_T yystacksize = YYINITDEPTH;
1114 /* The variables used to return semantic value and location from the
1115 action routines. */
1116 YYSTYPE yyval;
1119 /* The number of symbols on the RHS of the reduced rule.
1120 Keep to zero when no symbol should be popped. */
1121 int yylen = 0;
1123 YYDPRINTF ((stderr, "Starting parse\n"));
1125 yystate = 0;
1126 yyerrstatus = 0;
1127 yynerrs = 0;
1128 yychar = YYEMPTY; /* Cause a token to be read. */
1130 /* Initialize stack pointers.
1131 Waste one element of value and location stack
1132 so that they stay on the same level as the state stack.
1133 The wasted elements are never initialized. */
1135 yyssp = yyss;
1136 yyvsp = yyvs;
1138 goto yysetstate;
1140 /*------------------------------------------------------------.
1141 | yynewstate -- Push a new state, which is found in yystate. |
1142 `------------------------------------------------------------*/
1143 yynewstate:
1144 /* In all cases, when you get here, the value and location stacks
1145 have just been pushed. So pushing a state here evens the stacks. */
1146 yyssp++;
1148 yysetstate:
1149 *yyssp = yystate;
1151 if (yyss + yystacksize - 1 <= yyssp)
1153 /* Get the current used size of the three stacks, in elements. */
1154 YYSIZE_T yysize = yyssp - yyss + 1;
1156 #ifdef yyoverflow
1158 /* Give user a chance to reallocate the stack. Use copies of
1159 these so that the &'s don't force the real ones into
1160 memory. */
1161 YYSTYPE *yyvs1 = yyvs;
1162 yytype_int16 *yyss1 = yyss;
1165 /* Each stack pointer address is followed by the size of the
1166 data in use in that stack, in bytes. This used to be a
1167 conditional around just the two extra args, but that might
1168 be undefined if yyoverflow is a macro. */
1169 yyoverflow (YY_("memory exhausted"),
1170 &yyss1, yysize * sizeof (*yyssp),
1171 &yyvs1, yysize * sizeof (*yyvsp),
1173 &yystacksize);
1175 yyss = yyss1;
1176 yyvs = yyvs1;
1178 #else /* no yyoverflow */
1179 # ifndef YYSTACK_RELOCATE
1180 goto yyexhaustedlab;
1181 # else
1182 /* Extend the stack our own way. */
1183 if (YYMAXDEPTH <= yystacksize)
1184 goto yyexhaustedlab;
1185 yystacksize *= 2;
1186 if (YYMAXDEPTH < yystacksize)
1187 yystacksize = YYMAXDEPTH;
1190 yytype_int16 *yyss1 = yyss;
1191 union yyalloc *yyptr =
1192 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1193 if (! yyptr)
1194 goto yyexhaustedlab;
1195 YYSTACK_RELOCATE (yyss);
1196 YYSTACK_RELOCATE (yyvs);
1198 # undef YYSTACK_RELOCATE
1199 if (yyss1 != yyssa)
1200 YYSTACK_FREE (yyss1);
1202 # endif
1203 #endif /* no yyoverflow */
1205 yyssp = yyss + yysize - 1;
1206 yyvsp = yyvs + yysize - 1;
1209 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1210 (unsigned long int) yystacksize));
1212 if (yyss + yystacksize - 1 <= yyssp)
1213 YYABORT;
1216 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1218 goto yybackup;
1220 /*-----------.
1221 | yybackup. |
1222 `-----------*/
1223 yybackup:
1225 /* Do appropriate processing given the current state. Read a
1226 look-ahead token if we need one and don't already have one. */
1228 /* First try to decide what to do without reference to look-ahead token. */
1229 yyn = yypact[yystate];
1230 if (yyn == YYPACT_NINF)
1231 goto yydefault;
1233 /* Not known => get a look-ahead token if don't already have one. */
1235 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1236 if (yychar == YYEMPTY)
1238 YYDPRINTF ((stderr, "Reading a token: "));
1239 yychar = YYLEX;
1242 if (yychar <= YYEOF)
1244 yychar = yytoken = YYEOF;
1245 YYDPRINTF ((stderr, "Now at end of input.\n"));
1247 else
1249 yytoken = YYTRANSLATE (yychar);
1250 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1253 /* If the proper action on seeing token YYTOKEN is to reduce or to
1254 detect an error, take that action. */
1255 yyn += yytoken;
1256 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1257 goto yydefault;
1258 yyn = yytable[yyn];
1259 if (yyn <= 0)
1261 if (yyn == 0 || yyn == YYTABLE_NINF)
1262 goto yyerrlab;
1263 yyn = -yyn;
1264 goto yyreduce;
1267 if (yyn == YYFINAL)
1268 YYACCEPT;
1270 /* Count tokens shifted since error; after three, turn off error
1271 status. */
1272 if (yyerrstatus)
1273 yyerrstatus--;
1275 /* Shift the look-ahead token. */
1276 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1278 /* Discard the shifted token unless it is eof. */
1279 if (yychar != YYEOF)
1280 yychar = YYEMPTY;
1282 yystate = yyn;
1283 *++yyvsp = yylval;
1285 goto yynewstate;
1288 /*-----------------------------------------------------------.
1289 | yydefault -- do the default action for the current state. |
1290 `-----------------------------------------------------------*/
1291 yydefault:
1292 yyn = yydefact[yystate];
1293 if (yyn == 0)
1294 goto yyerrlab;
1295 goto yyreduce;
1298 /*-----------------------------.
1299 | yyreduce -- Do a reduction. |
1300 `-----------------------------*/
1301 yyreduce:
1302 /* yyn is the number of a rule to reduce with. */
1303 yylen = yyr2[yyn];
1305 /* If YYLEN is nonzero, implement the default value of the action:
1306 `$$ = $1'.
1308 Otherwise, the following line sets YYVAL to garbage.
1309 This behavior is undocumented and Bison
1310 users should not rely upon it. Assigning to YYVAL
1311 unconditionally makes the parser a bit smaller, and it avoids a
1312 GCC warning that YYVAL may be used uninitialized. */
1313 yyval = yyvsp[1-yylen];
1316 YY_REDUCE_PRINT (yyn);
1317 switch (yyn)
1319 case 2:
1320 #line 23 "calc.y"
1321 { yyreturn = (yyvsp[(1) - (1)]); ;}
1322 break;
1324 case 3:
1325 #line 26 "calc.y"
1326 { (yyval) = (yyvsp[(1) - (1)]); ;}
1327 break;
1329 case 4:
1330 #line 27 "calc.y"
1331 { (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]); ;}
1332 break;
1334 case 5:
1335 #line 28 "calc.y"
1336 { (yyval) = (yyvsp[(1) - (3)]) - (yyvsp[(3) - (3)]); ;}
1337 break;
1339 case 6:
1340 #line 29 "calc.y"
1341 { (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]); ;}
1342 break;
1344 case 7:
1345 #line 30 "calc.y"
1346 { (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]); ;}
1347 break;
1349 case 8:
1350 #line 31 "calc.y"
1351 { (yyval) = -(yyvsp[(2) - (2)]); ;}
1352 break;
1354 case 9:
1355 #line 32 "calc.y"
1356 { (yyval) = pow((yyvsp[(1) - (3)]), (yyvsp[(3) - (3)])); ;}
1357 break;
1359 case 10:
1360 #line 33 "calc.y"
1361 { (yyval) = (yyvsp[(2) - (3)]); ;}
1362 break;
1365 /* Line 1267 of yacc.c. */
1366 #line 1367 "calc.c"
1367 default: break;
1369 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1371 YYPOPSTACK (yylen);
1372 yylen = 0;
1373 YY_STACK_PRINT (yyss, yyssp);
1375 *++yyvsp = yyval;
1378 /* Now `shift' the result of the reduction. Determine what state
1379 that goes to, based on the state we popped back to and the rule
1380 number reduced by. */
1382 yyn = yyr1[yyn];
1384 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1385 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1386 yystate = yytable[yystate];
1387 else
1388 yystate = yydefgoto[yyn - YYNTOKENS];
1390 goto yynewstate;
1393 /*------------------------------------.
1394 | yyerrlab -- here on detecting error |
1395 `------------------------------------*/
1396 yyerrlab:
1397 /* If not already recovering from an error, report this error. */
1398 if (!yyerrstatus)
1400 ++yynerrs;
1401 #if ! YYERROR_VERBOSE
1402 yyerror (YY_("syntax error"));
1403 #else
1405 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1406 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1408 YYSIZE_T yyalloc = 2 * yysize;
1409 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1410 yyalloc = YYSTACK_ALLOC_MAXIMUM;
1411 if (yymsg != yymsgbuf)
1412 YYSTACK_FREE (yymsg);
1413 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1414 if (yymsg)
1415 yymsg_alloc = yyalloc;
1416 else
1418 yymsg = yymsgbuf;
1419 yymsg_alloc = sizeof yymsgbuf;
1423 if (0 < yysize && yysize <= yymsg_alloc)
1425 (void) yysyntax_error (yymsg, yystate, yychar);
1426 yyerror (yymsg);
1428 else
1430 yyerror (YY_("syntax error"));
1431 if (yysize != 0)
1432 goto yyexhaustedlab;
1435 #endif
1440 if (yyerrstatus == 3)
1442 /* If just tried and failed to reuse look-ahead token after an
1443 error, discard it. */
1445 if (yychar <= YYEOF)
1447 /* Return failure if at end of input. */
1448 if (yychar == YYEOF)
1449 YYABORT;
1451 else
1453 yydestruct ("Error: discarding",
1454 yytoken, &yylval);
1455 yychar = YYEMPTY;
1459 /* Else will try to reuse look-ahead token after shifting the error
1460 token. */
1461 goto yyerrlab1;
1464 /*---------------------------------------------------.
1465 | yyerrorlab -- error raised explicitly by YYERROR. |
1466 `---------------------------------------------------*/
1467 yyerrorlab:
1469 /* Pacify compilers like GCC when the user code never invokes
1470 YYERROR and the label yyerrorlab therefore never appears in user
1471 code. */
1472 if (/*CONSTCOND*/ 0)
1473 goto yyerrorlab;
1475 /* Do not reclaim the symbols of the rule which action triggered
1476 this YYERROR. */
1477 YYPOPSTACK (yylen);
1478 yylen = 0;
1479 YY_STACK_PRINT (yyss, yyssp);
1480 yystate = *yyssp;
1481 goto yyerrlab1;
1484 /*-------------------------------------------------------------.
1485 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1486 `-------------------------------------------------------------*/
1487 yyerrlab1:
1488 yyerrstatus = 3; /* Each real token shifted decrements this. */
1490 for (;;)
1492 yyn = yypact[yystate];
1493 if (yyn != YYPACT_NINF)
1495 yyn += YYTERROR;
1496 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1498 yyn = yytable[yyn];
1499 if (0 < yyn)
1500 break;
1504 /* Pop the current state because it cannot handle the error token. */
1505 if (yyssp == yyss)
1506 YYABORT;
1509 yydestruct ("Error: popping",
1510 yystos[yystate], yyvsp);
1511 YYPOPSTACK (1);
1512 yystate = *yyssp;
1513 YY_STACK_PRINT (yyss, yyssp);
1516 if (yyn == YYFINAL)
1517 YYACCEPT;
1519 *++yyvsp = yylval;
1522 /* Shift the error token. */
1523 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1525 yystate = yyn;
1526 goto yynewstate;
1529 /*-------------------------------------.
1530 | yyacceptlab -- YYACCEPT comes here. |
1531 `-------------------------------------*/
1532 yyacceptlab:
1533 yyresult = 0;
1534 goto yyreturn;
1536 /*-----------------------------------.
1537 | yyabortlab -- YYABORT comes here. |
1538 `-----------------------------------*/
1539 yyabortlab:
1540 yyresult = 1;
1541 goto yyreturn;
1543 #ifndef yyoverflow
1544 /*-------------------------------------------------.
1545 | yyexhaustedlab -- memory exhaustion comes here. |
1546 `-------------------------------------------------*/
1547 yyexhaustedlab:
1548 yyerror (YY_("memory exhausted"));
1549 yyresult = 2;
1550 /* Fall through. */
1551 #endif
1553 yyreturn:
1554 if (yychar != YYEOF && yychar != YYEMPTY)
1555 yydestruct ("Cleanup: discarding lookahead",
1556 yytoken, &yylval);
1557 /* Do not reclaim the symbols of the rule which action triggered
1558 this YYABORT or YYACCEPT. */
1559 YYPOPSTACK (yylen);
1560 YY_STACK_PRINT (yyss, yyssp);
1561 while (yyssp != yyss)
1563 yydestruct ("Cleanup: popping",
1564 yystos[*yyssp], yyvsp);
1565 YYPOPSTACK (1);
1567 #ifndef yyoverflow
1568 if (yyss != yyssa)
1569 YYSTACK_FREE (yyss);
1570 #endif
1571 #if YYERROR_VERBOSE
1572 if (yymsg != yymsgbuf)
1573 YYSTACK_FREE (yymsg);
1574 #endif
1575 /* Make sure YYID is used. */
1576 return YYID (yyresult);
1580 #line 36 "calc.y"
1583 /*#define EXPRESSION_VERBOSE*/
1585 static const char *yydata;
1587 int parse_expression(const char *data, double *d) {
1588 int r;
1590 #ifdef EXPRESSION_VERBOSE
1591 printf("%s = ", data);
1592 #endif
1594 if(!data) {
1595 #ifdef EXPRESSION_VERBOSE
1596 printf(" [NULL]\n");
1597 #endif
1598 return 1;
1601 yydata = data;
1602 r = yyparse();
1604 *d = yyreturn;
1605 #ifdef EXPRESSION_VERBOSE
1606 printf("%f\n", yyreturn);
1607 #endif
1609 return r;
1612 int yylex(void) {
1613 char *p;
1615 while(isspace(*yydata)) yydata ++;
1617 if(!*yydata) return 0;
1619 if(isdigit(*yydata) || *yydata == '.') {
1620 yylval = strtod(yydata, &p);
1621 if(p == yydata) return 0;
1622 yydata = p;
1624 while(isspace(*yydata)) yydata ++;
1626 return NUM;
1629 return *yydata++;
1632 void yyerror(const char *s) {
1633 fprintf(stderr, "%s: \"%s\"\n", s, yydata);