source: liacs/coco/assignment1/gen/y.tab.c@ 179

Last change on this file since 179 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 43.5 KB
RevLine 
[2]1/* A Bison parser, made by GNU Bison 2.3. */
2
3/* Skeleton implementation for Bison's Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
7
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.
12
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.
17
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. */
22
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.
32
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
35
36/* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
38
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. */
45
46/* Identify Bison output. */
47#define YYBISON 1
48
49/* Bison version. */
50#define YYBISON_VERSION "2.3"
51
52/* Skeleton name. */
53#define YYSKELETON_NAME "yacc.c"
54
55/* Pure parsers. */
56#define YYPURE 0
57
58/* Using locations. */
59#define YYLSP_NEEDED 0
60
61
62
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 DIGIT = 258,
70 PI = 259,
71 OPEN_PAREN = 260,
72 CLOSE_PAREN = 261,
73 UMINUS = 262,
74 EXPONENT = 263
75 };
76#endif
77/* Tokens. */
78#define DIGIT 258
79#define PI 259
80#define OPEN_PAREN 260
81#define CLOSE_PAREN 261
82#define UMINUS 262
83#define EXPONENT 263
84
85
86
87
88/* Copy the first part of user declarations. */
89#line 4 "calc.y"
90
91
92#include <stdio.h>
93#include <math.h>
94
95int base = 10;
96
97/* Prototypes */
98static void yyerror(const char *);
99static int fac(int x);
100
101/* import from spascal.l */
102extern int lineno;
103extern int yylex(void);
104
105
106
107/* Enabling traces. */
108#ifndef YYDEBUG
109# define YYDEBUG 1
110#endif
111
112/* Enabling verbose error messages. */
113#ifdef YYERROR_VERBOSE
114# undef YYERROR_VERBOSE
115# define YYERROR_VERBOSE 1
116#else
117# define YYERROR_VERBOSE 0
118#endif
119
120/* Enabling the token table. */
121#ifndef YYTOKEN_TABLE
122# define YYTOKEN_TABLE 0
123#endif
124
125#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
126typedef int YYSTYPE;
127# define yystype YYSTYPE /* obsolescent; will be withdrawn */
128# define YYSTYPE_IS_DECLARED 1
129# define YYSTYPE_IS_TRIVIAL 1
130#endif
131
132
133
134/* Copy the second part of user declarations. */
135
136
137/* Line 216 of yacc.c. */
138#line 139 "gen/y.tab.c"
139
140#ifdef short
141# undef short
142#endif
143
144#ifdef YYTYPE_UINT8
145typedef YYTYPE_UINT8 yytype_uint8;
146#else
147typedef unsigned char yytype_uint8;
148#endif
149
150#ifdef YYTYPE_INT8
151typedef YYTYPE_INT8 yytype_int8;
152#elif (defined __STDC__ || defined __C99__FUNC__ \
153 || defined __cplusplus || defined _MSC_VER)
154typedef signed char yytype_int8;
155#else
156typedef short int yytype_int8;
157#endif
158
159#ifdef YYTYPE_UINT16
160typedef YYTYPE_UINT16 yytype_uint16;
161#else
162typedef unsigned short int yytype_uint16;
163#endif
164
165#ifdef YYTYPE_INT16
166typedef YYTYPE_INT16 yytype_int16;
167#else
168typedef short int yytype_int16;
169#endif
170
171#ifndef YYSIZE_T
172# ifdef __SIZE_TYPE__
173# define YYSIZE_T __SIZE_TYPE__
174# elif defined size_t
175# define YYSIZE_T size_t
176# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
177 || defined __cplusplus || defined _MSC_VER)
178# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
179# define YYSIZE_T size_t
180# else
181# define YYSIZE_T unsigned int
182# endif
183#endif
184
185#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
186
187#ifndef YY_
188# if defined YYENABLE_NLS && YYENABLE_NLS
189# if ENABLE_NLS
190# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
191# define YY_(msgid) dgettext ("bison-runtime", msgid)
192# endif
193# endif
194# ifndef YY_
195# define YY_(msgid) msgid
196# endif
197#endif
198
199/* Suppress unused-variable warnings by "using" E. */
200#if ! defined lint || defined __GNUC__
201# define YYUSE(e) ((void) (e))
202#else
203# define YYUSE(e) /* empty */
204#endif
205
206/* Identity function, used to suppress warnings about constant conditions. */
207#ifndef lint
208# define YYID(n) (n)
209#else
210#if (defined __STDC__ || defined __C99__FUNC__ \
211 || defined __cplusplus || defined _MSC_VER)
212static int
213YYID (int i)
214#else
215static int
216YYID (i)
217 int i;
218#endif
219{
220 return i;
221}
222#endif
223
224#if ! defined yyoverflow || YYERROR_VERBOSE
225
226/* The parser invokes alloca or malloc; define the necessary symbols. */
227
228# ifdef YYSTACK_USE_ALLOCA
229# if YYSTACK_USE_ALLOCA
230# ifdef __GNUC__
231# define YYSTACK_ALLOC __builtin_alloca
232# elif defined __BUILTIN_VA_ARG_INCR
233# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
234# elif defined _AIX
235# define YYSTACK_ALLOC __alloca
236# elif defined _MSC_VER
237# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
238# define alloca _alloca
239# else
240# define YYSTACK_ALLOC alloca
241# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
242 || defined __cplusplus || defined _MSC_VER)
243# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
244# ifndef _STDLIB_H
245# define _STDLIB_H 1
246# endif
247# endif
248# endif
249# endif
250# endif
251
252# ifdef YYSTACK_ALLOC
253 /* Pacify GCC's `empty if-body' warning. */
254# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
255# ifndef YYSTACK_ALLOC_MAXIMUM
256 /* The OS might guarantee only one guard page at the bottom of the stack,
257 and a page size can be as small as 4096 bytes. So we cannot safely
258 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
259 to allow for a few compiler-allocated temporary stack slots. */
260# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
261# endif
262# else
263# define YYSTACK_ALLOC YYMALLOC
264# define YYSTACK_FREE YYFREE
265# ifndef YYSTACK_ALLOC_MAXIMUM
266# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
267# endif
268# if (defined __cplusplus && ! defined _STDLIB_H \
269 && ! ((defined YYMALLOC || defined malloc) \
270 && (defined YYFREE || defined free)))
271# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
272# ifndef _STDLIB_H
273# define _STDLIB_H 1
274# endif
275# endif
276# ifndef YYMALLOC
277# define YYMALLOC malloc
278# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
279 || defined __cplusplus || defined _MSC_VER)
280void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
281# endif
282# endif
283# ifndef YYFREE
284# define YYFREE free
285# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
286 || defined __cplusplus || defined _MSC_VER)
287void free (void *); /* INFRINGES ON USER NAME SPACE */
288# endif
289# endif
290# endif
291#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
292
293
294#if (! defined yyoverflow \
295 && (! defined __cplusplus \
296 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
297
298/* A type that is properly aligned for any stack member. */
299union yyalloc
300{
301 yytype_int16 yyss;
302 YYSTYPE yyvs;
303 };
304
305/* The size of the maximum gap between one aligned stack and the next. */
306# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
307
308/* The size of an array large to enough to hold all stacks, each with
309 N elements. */
310# define YYSTACK_BYTES(N) \
311 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
312 + YYSTACK_GAP_MAXIMUM)
313
314/* Copy COUNT objects from FROM to TO. The source and destination do
315 not overlap. */
316# ifndef YYCOPY
317# if defined __GNUC__ && 1 < __GNUC__
318# define YYCOPY(To, From, Count) \
319 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
320# else
321# define YYCOPY(To, From, Count) \
322 do \
323 { \
324 YYSIZE_T yyi; \
325 for (yyi = 0; yyi < (Count); yyi++) \
326 (To)[yyi] = (From)[yyi]; \
327 } \
328 while (YYID (0))
329# endif
330# endif
331
332/* Relocate STACK from its old location to the new one. The
333 local variables YYSIZE and YYSTACKSIZE give the old and new number of
334 elements in the stack, and YYPTR gives the new location of the
335 stack. Advance YYPTR to a properly aligned location for the next
336 stack. */
337# define YYSTACK_RELOCATE(Stack) \
338 do \
339 { \
340 YYSIZE_T yynewbytes; \
341 YYCOPY (&yyptr->Stack, Stack, yysize); \
342 Stack = &yyptr->Stack; \
343 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
344 yyptr += yynewbytes / sizeof (*yyptr); \
345 } \
346 while (YYID (0))
347
348#endif
349
350/* YYFINAL -- State number of the termination state. */
351#define YYFINAL 2
352/* YYLAST -- Last index in YYTABLE. */
353#define YYLAST 57
354
355/* YYNTOKENS -- Number of terminals. */
356#define YYNTOKENS 17
357/* YYNNTS -- Number of nonterminals. */
358#define YYNNTS 5
359/* YYNRULES -- Number of rules. */
360#define YYNRULES 19
361/* YYNRULES -- Number of states. */
362#define YYNSTATES 33
363
364/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
365#define YYUNDEFTOK 2
366#define YYMAXUTOK 263
367
368#define YYTRANSLATE(YYX) \
369 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
370
371/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
372static const yytype_uint8 yytranslate[] =
373{
374 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
375 16, 2, 2, 2, 2, 2, 2, 2, 2, 2,
376 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
377 2, 2, 2, 14, 2, 2, 2, 12, 2, 2,
378 2, 2, 10, 9, 2, 8, 2, 11, 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, 7, 2, 2, 2, 2, 2,
387 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
388 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
389 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
390 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
391 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
392 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
393 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
394 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
395 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
396 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
397 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
398 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
399 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
400 5, 6, 13, 15
401};
402
403#if YYDEBUG
404/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
405 YYRHS. */
406static const yytype_uint8 yyprhs[] =
407{
408 0, 0, 3, 4, 8, 12, 14, 18, 22, 26,
409 30, 34, 38, 42, 45, 49, 52, 54, 56, 58
410};
411
412/* YYRHS -- A `-1'-separated list of the rules' RHS. */
413static const yytype_int8 yyrhs[] =
414{
415 18, 0, -1, -1, 18, 19, 16, -1, 18, 1,
416 16, -1, 20, -1, 5, 20, 6, -1, 7, 20,
417 7, -1, 20, 10, 20, -1, 20, 11, 20, -1,
418 20, 12, 20, -1, 20, 8, 20, -1, 20, 9,
419 20, -1, 20, 14, -1, 20, 15, 20, -1, 8,
420 20, -1, 21, -1, 4, -1, 3, -1, 21, 3,
421 -1
422};
423
424/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
425static const yytype_uint8 yyrline[] =
426{
427 0, 44, 44, 47, 51, 59, 67, 74, 81, 88,
428 95, 102, 109, 116, 127, 134, 141, 146, 153, 160
429};
430#endif
431
432#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
433/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
434 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
435static const char *const yytname[] =
436{
437 "$end", "error", "$undefined", "DIGIT", "PI", "OPEN_PAREN",
438 "CLOSE_PAREN", "'|'", "'-'", "'+'", "'*'", "'/'", "'%'", "UMINUS", "'!'",
439 "EXPONENT", "'\\n'", "$accept", "line", "stmt", "expr", "number", 0
440};
441#endif
442
443# ifdef YYPRINT
444/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
445 token YYLEX-NUM. */
446static const yytype_uint16 yytoknum[] =
447{
448 0, 256, 257, 258, 259, 260, 261, 124, 45, 43,
449 42, 47, 37, 262, 33, 263, 10
450};
451# endif
452
453/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
454static const yytype_uint8 yyr1[] =
455{
456 0, 17, 18, 18, 18, 19, 20, 20, 20, 20,
457 20, 20, 20, 20, 20, 20, 20, 21, 21, 21
458};
459
460/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
461static const yytype_uint8 yyr2[] =
462{
463 0, 2, 0, 3, 3, 1, 3, 3, 3, 3,
464 3, 3, 3, 2, 3, 2, 1, 1, 1, 2
465};
466
467/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
468 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
469 means the default is an error. */
470static const yytype_uint8 yydefact[] =
471{
472 2, 0, 1, 0, 18, 17, 0, 0, 0, 0,
473 5, 16, 4, 0, 0, 15, 3, 0, 0, 0,
474 0, 0, 13, 0, 19, 6, 7, 11, 12, 8,
475 9, 10, 14
476};
477
478/* YYDEFGOTO[NTERM-NUM]. */
479static const yytype_int8 yydefgoto[] =
480{
481 -1, 1, 9, 10, 11
482};
483
484/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
485 STATE-NUM. */
486#define YYPACT_NINF -9
487static const yytype_int8 yypact[] =
488{
489 -9, 35, -9, -8, -9, -9, 41, 41, 41, 7,
490 -5, 29, -9, 10, 19, 42, -9, 41, 41, 41,
491 41, 41, -9, 41, -9, -9, -9, 40, 40, 42,
492 42, 42, 22
493};
494
495/* YYPGOTO[NTERM-NUM]. */
496static const yytype_int8 yypgoto[] =
497{
498 -9, -9, -9, -6, -9
499};
500
501/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
502 positive, shift that token. If negative, reduce the rule which
503 number is the opposite. If zero, do what YYDEFACT says.
504 If YYTABLE_NINF, syntax error. */
505#define YYTABLE_NINF -1
506static const yytype_uint8 yytable[] =
507{
508 13, 14, 15, 17, 18, 19, 20, 21, 12, 22,
509 23, 27, 28, 29, 30, 31, 25, 32, 17, 18,
510 19, 20, 21, 16, 22, 23, 26, 17, 18, 19,
511 20, 21, 24, 22, 23, 2, 3, 23, 4, 5,
512 6, 0, 7, 8, 4, 5, 6, 0, 7, 8,
513 19, 20, 21, 0, 22, 23, 22, 23
514};
515
516static const yytype_int8 yycheck[] =
517{
518 6, 7, 8, 8, 9, 10, 11, 12, 16, 14,
519 15, 17, 18, 19, 20, 21, 6, 23, 8, 9,
520 10, 11, 12, 16, 14, 15, 7, 8, 9, 10,
521 11, 12, 3, 14, 15, 0, 1, 15, 3, 4,
522 5, -1, 7, 8, 3, 4, 5, -1, 7, 8,
523 10, 11, 12, -1, 14, 15, 14, 15
524};
525
526/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
527 symbol of state STATE-NUM. */
528static const yytype_uint8 yystos[] =
529{
530 0, 18, 0, 1, 3, 4, 5, 7, 8, 19,
531 20, 21, 16, 20, 20, 20, 16, 8, 9, 10,
532 11, 12, 14, 15, 3, 6, 7, 20, 20, 20,
533 20, 20, 20
534};
535
536#define yyerrok (yyerrstatus = 0)
537#define yyclearin (yychar = YYEMPTY)
538#define YYEMPTY (-2)
539#define YYEOF 0
540
541#define YYACCEPT goto yyacceptlab
542#define YYABORT goto yyabortlab
543#define YYERROR goto yyerrorlab
544
545
546/* Like YYERROR except do call yyerror. This remains here temporarily
547 to ease the transition to the new meaning of YYERROR, for GCC.
548 Once GCC version 2 has supplanted version 1, this can go. */
549
550#define YYFAIL goto yyerrlab
551
552#define YYRECOVERING() (!!yyerrstatus)
553
554#define YYBACKUP(Token, Value) \
555do \
556 if (yychar == YYEMPTY && yylen == 1) \
557 { \
558 yychar = (Token); \
559 yylval = (Value); \
560 yytoken = YYTRANSLATE (yychar); \
561 YYPOPSTACK (1); \
562 goto yybackup; \
563 } \
564 else \
565 { \
566 yyerror (YY_("syntax error: cannot back up")); \
567 YYERROR; \
568 } \
569while (YYID (0))
570
571
572#define YYTERROR 1
573#define YYERRCODE 256
574
575
576/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
577 If N is 0, then set CURRENT to the empty location which ends
578 the previous symbol: RHS[0] (always defined). */
579
580#define YYRHSLOC(Rhs, K) ((Rhs)[K])
581#ifndef YYLLOC_DEFAULT
582# define YYLLOC_DEFAULT(Current, Rhs, N) \
583 do \
584 if (YYID (N)) \
585 { \
586 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
587 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
588 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
589 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
590 } \
591 else \
592 { \
593 (Current).first_line = (Current).last_line = \
594 YYRHSLOC (Rhs, 0).last_line; \
595 (Current).first_column = (Current).last_column = \
596 YYRHSLOC (Rhs, 0).last_column; \
597 } \
598 while (YYID (0))
599#endif
600
601
602/* YY_LOCATION_PRINT -- Print the location on the stream.
603 This macro was not mandated originally: define only if we know
604 we won't break user code: when these are the locations we know. */
605
606#ifndef YY_LOCATION_PRINT
607# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
608# define YY_LOCATION_PRINT(File, Loc) \
609 fprintf (File, "%d.%d-%d.%d", \
610 (Loc).first_line, (Loc).first_column, \
611 (Loc).last_line, (Loc).last_column)
612# else
613# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
614# endif
615#endif
616
617
618/* YYLEX -- calling `yylex' with the right arguments. */
619
620#ifdef YYLEX_PARAM
621# define YYLEX yylex (YYLEX_PARAM)
622#else
623# define YYLEX yylex ()
624#endif
625
626/* Enable debugging if requested. */
627#if YYDEBUG
628
629# ifndef YYFPRINTF
630# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
631# define YYFPRINTF fprintf
632# endif
633
634# define YYDPRINTF(Args) \
635do { \
636 if (yydebug) \
637 YYFPRINTF Args; \
638} while (YYID (0))
639
640# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
641do { \
642 if (yydebug) \
643 { \
644 YYFPRINTF (stderr, "%s ", Title); \
645 yy_symbol_print (stderr, \
646 Type, Value); \
647 YYFPRINTF (stderr, "\n"); \
648 } \
649} while (YYID (0))
650
651
652/*--------------------------------.
653| Print this symbol on YYOUTPUT. |
654`--------------------------------*/
655
656/*ARGSUSED*/
657#if (defined __STDC__ || defined __C99__FUNC__ \
658 || defined __cplusplus || defined _MSC_VER)
659static void
660yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
661#else
662static void
663yy_symbol_value_print (yyoutput, yytype, yyvaluep)
664 FILE *yyoutput;
665 int yytype;
666 YYSTYPE const * const yyvaluep;
667#endif
668{
669 if (!yyvaluep)
670 return;
671# ifdef YYPRINT
672 if (yytype < YYNTOKENS)
673 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
674# else
675 YYUSE (yyoutput);
676# endif
677 switch (yytype)
678 {
679 default:
680 break;
681 }
682}
683
684
685/*--------------------------------.
686| Print this symbol on YYOUTPUT. |
687`--------------------------------*/
688
689#if (defined __STDC__ || defined __C99__FUNC__ \
690 || defined __cplusplus || defined _MSC_VER)
691static void
692yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
693#else
694static void
695yy_symbol_print (yyoutput, yytype, yyvaluep)
696 FILE *yyoutput;
697 int yytype;
698 YYSTYPE const * const yyvaluep;
699#endif
700{
701 if (yytype < YYNTOKENS)
702 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
703 else
704 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
705
706 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
707 YYFPRINTF (yyoutput, ")");
708}
709
710/*------------------------------------------------------------------.
711| yy_stack_print -- Print the state stack from its BOTTOM up to its |
712| TOP (included). |
713`------------------------------------------------------------------*/
714
715#if (defined __STDC__ || defined __C99__FUNC__ \
716 || defined __cplusplus || defined _MSC_VER)
717static void
718yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
719#else
720static void
721yy_stack_print (bottom, top)
722 yytype_int16 *bottom;
723 yytype_int16 *top;
724#endif
725{
726 YYFPRINTF (stderr, "Stack now");
727 for (; bottom <= top; ++bottom)
728 YYFPRINTF (stderr, " %d", *bottom);
729 YYFPRINTF (stderr, "\n");
730}
731
732# define YY_STACK_PRINT(Bottom, Top) \
733do { \
734 if (yydebug) \
735 yy_stack_print ((Bottom), (Top)); \
736} while (YYID (0))
737
738
739/*------------------------------------------------.
740| Report that the YYRULE is going to be reduced. |
741`------------------------------------------------*/
742
743#if (defined __STDC__ || defined __C99__FUNC__ \
744 || defined __cplusplus || defined _MSC_VER)
745static void
746yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
747#else
748static void
749yy_reduce_print (yyvsp, yyrule)
750 YYSTYPE *yyvsp;
751 int yyrule;
752#endif
753{
754 int yynrhs = yyr2[yyrule];
755 int yyi;
756 unsigned long int yylno = yyrline[yyrule];
757 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
758 yyrule - 1, yylno);
759 /* The symbols being reduced. */
760 for (yyi = 0; yyi < yynrhs; yyi++)
761 {
762 fprintf (stderr, " $%d = ", yyi + 1);
763 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
764 &(yyvsp[(yyi + 1) - (yynrhs)])
765 );
766 fprintf (stderr, "\n");
767 }
768}
769
770# define YY_REDUCE_PRINT(Rule) \
771do { \
772 if (yydebug) \
773 yy_reduce_print (yyvsp, Rule); \
774} while (YYID (0))
775
776/* Nonzero means print parse trace. It is left uninitialized so that
777 multiple parsers can coexist. */
778int yydebug;
779#else /* !YYDEBUG */
780# define YYDPRINTF(Args)
781# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
782# define YY_STACK_PRINT(Bottom, Top)
783# define YY_REDUCE_PRINT(Rule)
784#endif /* !YYDEBUG */
785
786
787/* YYINITDEPTH -- initial size of the parser's stacks. */
788#ifndef YYINITDEPTH
789# define YYINITDEPTH 200
790#endif
791
792/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
793 if the built-in stack extension method is used).
794
795 Do not make this value too large; the results are undefined if
796 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
797 evaluated with infinite-precision integer arithmetic. */
798
799#ifndef YYMAXDEPTH
800# define YYMAXDEPTH 10000
801#endif
802
803
804
805
806#if YYERROR_VERBOSE
807
808# ifndef yystrlen
809# if defined __GLIBC__ && defined _STRING_H
810# define yystrlen strlen
811# else
812/* Return the length of YYSTR. */
813#if (defined __STDC__ || defined __C99__FUNC__ \
814 || defined __cplusplus || defined _MSC_VER)
815static YYSIZE_T
816yystrlen (const char *yystr)
817#else
818static YYSIZE_T
819yystrlen (yystr)
820 const char *yystr;
821#endif
822{
823 YYSIZE_T yylen;
824 for (yylen = 0; yystr[yylen]; yylen++)
825 continue;
826 return yylen;
827}
828# endif
829# endif
830
831# ifndef yystpcpy
832# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
833# define yystpcpy stpcpy
834# else
835/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
836 YYDEST. */
837#if (defined __STDC__ || defined __C99__FUNC__ \
838 || defined __cplusplus || defined _MSC_VER)
839static char *
840yystpcpy (char *yydest, const char *yysrc)
841#else
842static char *
843yystpcpy (yydest, yysrc)
844 char *yydest;
845 const char *yysrc;
846#endif
847{
848 char *yyd = yydest;
849 const char *yys = yysrc;
850
851 while ((*yyd++ = *yys++) != '\0')
852 continue;
853
854 return yyd - 1;
855}
856# endif
857# endif
858
859# ifndef yytnamerr
860/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
861 quotes and backslashes, so that it's suitable for yyerror. The
862 heuristic is that double-quoting is unnecessary unless the string
863 contains an apostrophe, a comma, or backslash (other than
864 backslash-backslash). YYSTR is taken from yytname. If YYRES is
865 null, do not copy; instead, return the length of what the result
866 would have been. */
867static YYSIZE_T
868yytnamerr (char *yyres, const char *yystr)
869{
870 if (*yystr == '"')
871 {
872 YYSIZE_T yyn = 0;
873 char const *yyp = yystr;
874
875 for (;;)
876 switch (*++yyp)
877 {
878 case '\'':
879 case ',':
880 goto do_not_strip_quotes;
881
882 case '\\':
883 if (*++yyp != '\\')
884 goto do_not_strip_quotes;
885 /* Fall through. */
886 default:
887 if (yyres)
888 yyres[yyn] = *yyp;
889 yyn++;
890 break;
891
892 case '"':
893 if (yyres)
894 yyres[yyn] = '\0';
895 return yyn;
896 }
897 do_not_strip_quotes: ;
898 }
899
900 if (! yyres)
901 return yystrlen (yystr);
902
903 return yystpcpy (yyres, yystr) - yyres;
904}
905# endif
906
907/* Copy into YYRESULT an error message about the unexpected token
908 YYCHAR while in state YYSTATE. Return the number of bytes copied,
909 including the terminating null byte. If YYRESULT is null, do not
910 copy anything; just return the number of bytes that would be
911 copied. As a special case, return 0 if an ordinary "syntax error"
912 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
913 size calculation. */
914static YYSIZE_T
915yysyntax_error (char *yyresult, int yystate, int yychar)
916{
917 int yyn = yypact[yystate];
918
919 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
920 return 0;
921 else
922 {
923 int yytype = YYTRANSLATE (yychar);
924 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
925 YYSIZE_T yysize = yysize0;
926 YYSIZE_T yysize1;
927 int yysize_overflow = 0;
928 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
929 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
930 int yyx;
931
932# if 0
933 /* This is so xgettext sees the translatable formats that are
934 constructed on the fly. */
935 YY_("syntax error, unexpected %s");
936 YY_("syntax error, unexpected %s, expecting %s");
937 YY_("syntax error, unexpected %s, expecting %s or %s");
938 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
939 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
940# endif
941 char *yyfmt;
942 char const *yyf;
943 static char const yyunexpected[] = "syntax error, unexpected %s";
944 static char const yyexpecting[] = ", expecting %s";
945 static char const yyor[] = " or %s";
946 char yyformat[sizeof yyunexpected
947 + sizeof yyexpecting - 1
948 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
949 * (sizeof yyor - 1))];
950 char const *yyprefix = yyexpecting;
951
952 /* Start YYX at -YYN if negative to avoid negative indexes in
953 YYCHECK. */
954 int yyxbegin = yyn < 0 ? -yyn : 0;
955
956 /* Stay within bounds of both yycheck and yytname. */
957 int yychecklim = YYLAST - yyn + 1;
958 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
959 int yycount = 1;
960
961 yyarg[0] = yytname[yytype];
962 yyfmt = yystpcpy (yyformat, yyunexpected);
963
964 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
965 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
966 {
967 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
968 {
969 yycount = 1;
970 yysize = yysize0;
971 yyformat[sizeof yyunexpected - 1] = '\0';
972 break;
973 }
974 yyarg[yycount++] = yytname[yyx];
975 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
976 yysize_overflow |= (yysize1 < yysize);
977 yysize = yysize1;
978 yyfmt = yystpcpy (yyfmt, yyprefix);
979 yyprefix = yyor;
980 }
981
982 yyf = YY_(yyformat);
983 yysize1 = yysize + yystrlen (yyf);
984 yysize_overflow |= (yysize1 < yysize);
985 yysize = yysize1;
986
987 if (yysize_overflow)
988 return YYSIZE_MAXIMUM;
989
990 if (yyresult)
991 {
992 /* Avoid sprintf, as that infringes on the user's name space.
993 Don't have undefined behavior even if the translation
994 produced a string with the wrong number of "%s"s. */
995 char *yyp = yyresult;
996 int yyi = 0;
997 while ((*yyp = *yyf) != '\0')
998 {
999 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1000 {
1001 yyp += yytnamerr (yyp, yyarg[yyi++]);
1002 yyf += 2;
1003 }
1004 else
1005 {
1006 yyp++;
1007 yyf++;
1008 }
1009 }
1010 }
1011 return yysize;
1012 }
1013}
1014#endif /* YYERROR_VERBOSE */
1015
1016
1017
1018/*-----------------------------------------------.
1019| Release the memory associated to this symbol. |
1020`-----------------------------------------------*/
1021
1022/*ARGSUSED*/
1023#if (defined __STDC__ || defined __C99__FUNC__ \
1024 || defined __cplusplus || defined _MSC_VER)
1025static void
1026yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1027#else
1028static void
1029yydestruct (yymsg, yytype, yyvaluep)
1030 const char *yymsg;
1031 int yytype;
1032 YYSTYPE *yyvaluep;
1033#endif
1034{
1035 YYUSE (yyvaluep);
1036
1037 if (!yymsg)
1038 yymsg = "Deleting";
1039 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1040
1041 switch (yytype)
1042 {
1043
1044 default:
1045 break;
1046 }
1047}
1048
1049
1050
1051/* Prevent warnings from -Wmissing-prototypes. */
1052
1053#ifdef YYPARSE_PARAM
1054#if defined __STDC__ || defined __cplusplus
1055int yyparse (void *YYPARSE_PARAM);
1056#else
1057int yyparse ();
1058#endif
1059#else /* ! YYPARSE_PARAM */
1060#if defined __STDC__ || defined __cplusplus
1061int yyparse (void);
1062#else
1063int yyparse ();
1064#endif
1065#endif /* ! YYPARSE_PARAM */
1066
1067
1068
1069/* The look-ahead symbol. */
1070int yychar;
1071
1072/* The semantic value of the look-ahead symbol. */
1073YYSTYPE yylval;
1074
1075/* Number of syntax errors so far. */
1076int yynerrs;
1077
1078
1079
1080/*----------.
1081| yyparse. |
1082`----------*/
1083
1084#ifdef YYPARSE_PARAM
1085#if (defined __STDC__ || defined __C99__FUNC__ \
1086 || defined __cplusplus || defined _MSC_VER)
1087int
1088yyparse (void *YYPARSE_PARAM)
1089#else
1090int
1091yyparse (YYPARSE_PARAM)
1092 void *YYPARSE_PARAM;
1093#endif
1094#else /* ! YYPARSE_PARAM */
1095#if (defined __STDC__ || defined __C99__FUNC__ \
1096 || defined __cplusplus || defined _MSC_VER)
1097int
1098yyparse (void)
1099#else
1100int
1101yyparse ()
1102
1103#endif
1104#endif
1105{
1106
1107 int yystate;
1108 int yyn;
1109 int yyresult;
1110 /* Number of tokens to shift before error messages enabled. */
1111 int yyerrstatus;
1112 /* Look-ahead token as an internal (translated) token number. */
1113 int yytoken = 0;
1114#if YYERROR_VERBOSE
1115 /* Buffer for error messages, and its allocated size. */
1116 char yymsgbuf[128];
1117 char *yymsg = yymsgbuf;
1118 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1119#endif
1120
1121 /* Three stacks and their tools:
1122 `yyss': related to states,
1123 `yyvs': related to semantic values,
1124 `yyls': related to locations.
1125
1126 Refer to the stacks thru separate pointers, to allow yyoverflow
1127 to reallocate them elsewhere. */
1128
1129 /* The state stack. */
1130 yytype_int16 yyssa[YYINITDEPTH];
1131 yytype_int16 *yyss = yyssa;
1132 yytype_int16 *yyssp;
1133
1134 /* The semantic value stack. */
1135 YYSTYPE yyvsa[YYINITDEPTH];
1136 YYSTYPE *yyvs = yyvsa;
1137 YYSTYPE *yyvsp;
1138
1139
1140
1141#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1142
1143 YYSIZE_T yystacksize = YYINITDEPTH;
1144
1145 /* The variables used to return semantic value and location from the
1146 action routines. */
1147 YYSTYPE yyval;
1148
1149
1150 /* The number of symbols on the RHS of the reduced rule.
1151 Keep to zero when no symbol should be popped. */
1152 int yylen = 0;
1153
1154 YYDPRINTF ((stderr, "Starting parse\n"));
1155
1156 yystate = 0;
1157 yyerrstatus = 0;
1158 yynerrs = 0;
1159 yychar = YYEMPTY; /* Cause a token to be read. */
1160
1161 /* Initialize stack pointers.
1162 Waste one element of value and location stack
1163 so that they stay on the same level as the state stack.
1164 The wasted elements are never initialized. */
1165
1166 yyssp = yyss;
1167 yyvsp = yyvs;
1168
1169 goto yysetstate;
1170
1171/*------------------------------------------------------------.
1172| yynewstate -- Push a new state, which is found in yystate. |
1173`------------------------------------------------------------*/
1174 yynewstate:
1175 /* In all cases, when you get here, the value and location stacks
1176 have just been pushed. So pushing a state here evens the stacks. */
1177 yyssp++;
1178
1179 yysetstate:
1180 *yyssp = yystate;
1181
1182 if (yyss + yystacksize - 1 <= yyssp)
1183 {
1184 /* Get the current used size of the three stacks, in elements. */
1185 YYSIZE_T yysize = yyssp - yyss + 1;
1186
1187#ifdef yyoverflow
1188 {
1189 /* Give user a chance to reallocate the stack. Use copies of
1190 these so that the &'s don't force the real ones into
1191 memory. */
1192 YYSTYPE *yyvs1 = yyvs;
1193 yytype_int16 *yyss1 = yyss;
1194
1195
1196 /* Each stack pointer address is followed by the size of the
1197 data in use in that stack, in bytes. This used to be a
1198 conditional around just the two extra args, but that might
1199 be undefined if yyoverflow is a macro. */
1200 yyoverflow (YY_("memory exhausted"),
1201 &yyss1, yysize * sizeof (*yyssp),
1202 &yyvs1, yysize * sizeof (*yyvsp),
1203
1204 &yystacksize);
1205
1206 yyss = yyss1;
1207 yyvs = yyvs1;
1208 }
1209#else /* no yyoverflow */
1210# ifndef YYSTACK_RELOCATE
1211 goto yyexhaustedlab;
1212# else
1213 /* Extend the stack our own way. */
1214 if (YYMAXDEPTH <= yystacksize)
1215 goto yyexhaustedlab;
1216 yystacksize *= 2;
1217 if (YYMAXDEPTH < yystacksize)
1218 yystacksize = YYMAXDEPTH;
1219
1220 {
1221 yytype_int16 *yyss1 = yyss;
1222 union yyalloc *yyptr =
1223 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1224 if (! yyptr)
1225 goto yyexhaustedlab;
1226 YYSTACK_RELOCATE (yyss);
1227 YYSTACK_RELOCATE (yyvs);
1228
1229# undef YYSTACK_RELOCATE
1230 if (yyss1 != yyssa)
1231 YYSTACK_FREE (yyss1);
1232 }
1233# endif
1234#endif /* no yyoverflow */
1235
1236 yyssp = yyss + yysize - 1;
1237 yyvsp = yyvs + yysize - 1;
1238
1239
1240 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1241 (unsigned long int) yystacksize));
1242
1243 if (yyss + yystacksize - 1 <= yyssp)
1244 YYABORT;
1245 }
1246
1247 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1248
1249 goto yybackup;
1250
1251/*-----------.
1252| yybackup. |
1253`-----------*/
1254yybackup:
1255
1256 /* Do appropriate processing given the current state. Read a
1257 look-ahead token if we need one and don't already have one. */
1258
1259 /* First try to decide what to do without reference to look-ahead token. */
1260 yyn = yypact[yystate];
1261 if (yyn == YYPACT_NINF)
1262 goto yydefault;
1263
1264 /* Not known => get a look-ahead token if don't already have one. */
1265
1266 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1267 if (yychar == YYEMPTY)
1268 {
1269 YYDPRINTF ((stderr, "Reading a token: "));
1270 yychar = YYLEX;
1271 }
1272
1273 if (yychar <= YYEOF)
1274 {
1275 yychar = yytoken = YYEOF;
1276 YYDPRINTF ((stderr, "Now at end of input.\n"));
1277 }
1278 else
1279 {
1280 yytoken = YYTRANSLATE (yychar);
1281 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1282 }
1283
1284 /* If the proper action on seeing token YYTOKEN is to reduce or to
1285 detect an error, take that action. */
1286 yyn += yytoken;
1287 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1288 goto yydefault;
1289 yyn = yytable[yyn];
1290 if (yyn <= 0)
1291 {
1292 if (yyn == 0 || yyn == YYTABLE_NINF)
1293 goto yyerrlab;
1294 yyn = -yyn;
1295 goto yyreduce;
1296 }
1297
1298 if (yyn == YYFINAL)
1299 YYACCEPT;
1300
1301 /* Count tokens shifted since error; after three, turn off error
1302 status. */
1303 if (yyerrstatus)
1304 yyerrstatus--;
1305
1306 /* Shift the look-ahead token. */
1307 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1308
1309 /* Discard the shifted token unless it is eof. */
1310 if (yychar != YYEOF)
1311 yychar = YYEMPTY;
1312
1313 yystate = yyn;
1314 *++yyvsp = yylval;
1315
1316 goto yynewstate;
1317
1318
1319/*-----------------------------------------------------------.
1320| yydefault -- do the default action for the current state. |
1321`-----------------------------------------------------------*/
1322yydefault:
1323 yyn = yydefact[yystate];
1324 if (yyn == 0)
1325 goto yyerrlab;
1326 goto yyreduce;
1327
1328
1329/*-----------------------------.
1330| yyreduce -- Do a reduction. |
1331`-----------------------------*/
1332yyreduce:
1333 /* yyn is the number of a rule to reduce with. */
1334 yylen = yyr2[yyn];
1335
1336 /* If YYLEN is nonzero, implement the default value of the action:
1337 `$$ = $1'.
1338
1339 Otherwise, the following line sets YYVAL to garbage.
1340 This behavior is undocumented and Bison
1341 users should not rely upon it. Assigning to YYVAL
1342 unconditionally makes the parser a bit smaller, and it avoids a
1343 GCC warning that YYVAL may be used uninitialized. */
1344 yyval = yyvsp[1-yylen];
1345
1346
1347 YY_REDUCE_PRINT (yyn);
1348 switch (yyn)
1349 {
1350 case 4:
1351#line 52 "calc.y"
1352 {
1353 yyerrok;
1354 }
1355 break;
1356
1357 case 5:
1358#line 60 "calc.y"
1359 {
1360 printf("%d\n",(yyvsp[(1) - (1)]));
1361 }
1362 break;
1363
1364 case 6:
1365#line 68 "calc.y"
1366 {
1367 (yyval) = (yyvsp[(2) - (3)]);
1368 }
1369 break;
1370
1371 case 7:
1372#line 75 "calc.y"
1373 {
1374 (yyval) = (int)fabs((double)(yyvsp[(2) - (3)]));
1375 }
1376 break;
1377
1378 case 8:
1379#line 82 "calc.y"
1380 {
1381 (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]);
1382 }
1383 break;
1384
1385 case 9:
1386#line 89 "calc.y"
1387 {
1388 (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]);
1389 }
1390 break;
1391
1392 case 10:
1393#line 96 "calc.y"
1394 {
1395 (yyval) = (yyvsp[(1) - (3)]) % (yyvsp[(3) - (3)]);
1396 }
1397 break;
1398
1399 case 11:
1400#line 103 "calc.y"
1401 {
1402 (yyval) = (yyvsp[(1) - (3)]) - (yyvsp[(3) - (3)]);
1403 }
1404 break;
1405
1406 case 12:
1407#line 110 "calc.y"
1408 {
1409 (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]);
1410 }
1411 break;
1412
1413 case 13:
1414#line 117 "calc.y"
1415 {
1416 if ((yyvsp[(1) - (2)]) < 0) {
1417 fprintf(stderr, "Negative values for faculty are undefined.\n");
1418 YYERROR;
1419 }
1420 (yyval) = fac((yyvsp[(1) - (2)]));
1421 }
1422 break;
1423
1424 case 14:
1425#line 128 "calc.y"
1426 {
1427 (yyval) = (int)pow((double)(yyvsp[(1) - (3)]), (double)(yyvsp[(3) - (3)]));
1428 }
1429 break;
1430
1431 case 15:
1432#line 135 "calc.y"
1433 {
1434 (yyval) = -(yyvsp[(2) - (2)]);
1435 }
1436 break;
1437
1438 case 17:
1439#line 147 "calc.y"
1440 {
1441 (yyval) = 3;
1442 }
1443 break;
1444
1445 case 18:
1446#line 154 "calc.y"
1447 {
1448 (yyval) = (yyvsp[(1) - (1)]);
1449 }
1450 break;
1451
1452 case 19:
1453#line 161 "calc.y"
1454 {
1455 (yyval) = base * (yyvsp[(1) - (2)]) + (yyvsp[(2) - (2)]);
1456 }
1457 break;
1458
1459
1460/* Line 1267 of yacc.c. */
1461#line 1459 "gen/y.tab.c"
1462 default: break;
1463 }
1464 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1465
1466 YYPOPSTACK (yylen);
1467 yylen = 0;
1468 YY_STACK_PRINT (yyss, yyssp);
1469
1470 *++yyvsp = yyval;
1471
1472
1473 /* Now `shift' the result of the reduction. Determine what state
1474 that goes to, based on the state we popped back to and the rule
1475 number reduced by. */
1476
1477 yyn = yyr1[yyn];
1478
1479 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1480 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1481 yystate = yytable[yystate];
1482 else
1483 yystate = yydefgoto[yyn - YYNTOKENS];
1484
1485 goto yynewstate;
1486
1487
1488/*------------------------------------.
1489| yyerrlab -- here on detecting error |
1490`------------------------------------*/
1491yyerrlab:
1492 /* If not already recovering from an error, report this error. */
1493 if (!yyerrstatus)
1494 {
1495 ++yynerrs;
1496#if ! YYERROR_VERBOSE
1497 yyerror (YY_("syntax error"));
1498#else
1499 {
1500 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1501 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1502 {
1503 YYSIZE_T yyalloc = 2 * yysize;
1504 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1505 yyalloc = YYSTACK_ALLOC_MAXIMUM;
1506 if (yymsg != yymsgbuf)
1507 YYSTACK_FREE (yymsg);
1508 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1509 if (yymsg)
1510 yymsg_alloc = yyalloc;
1511 else
1512 {
1513 yymsg = yymsgbuf;
1514 yymsg_alloc = sizeof yymsgbuf;
1515 }
1516 }
1517
1518 if (0 < yysize && yysize <= yymsg_alloc)
1519 {
1520 (void) yysyntax_error (yymsg, yystate, yychar);
1521 yyerror (yymsg);
1522 }
1523 else
1524 {
1525 yyerror (YY_("syntax error"));
1526 if (yysize != 0)
1527 goto yyexhaustedlab;
1528 }
1529 }
1530#endif
1531 }
1532
1533
1534
1535 if (yyerrstatus == 3)
1536 {
1537 /* If just tried and failed to reuse look-ahead token after an
1538 error, discard it. */
1539
1540 if (yychar <= YYEOF)
1541 {
1542 /* Return failure if at end of input. */
1543 if (yychar == YYEOF)
1544 YYABORT;
1545 }
1546 else
1547 {
1548 yydestruct ("Error: discarding",
1549 yytoken, &yylval);
1550 yychar = YYEMPTY;
1551 }
1552 }
1553
1554 /* Else will try to reuse look-ahead token after shifting the error
1555 token. */
1556 goto yyerrlab1;
1557
1558
1559/*---------------------------------------------------.
1560| yyerrorlab -- error raised explicitly by YYERROR. |
1561`---------------------------------------------------*/
1562yyerrorlab:
1563
1564 /* Pacify compilers like GCC when the user code never invokes
1565 YYERROR and the label yyerrorlab therefore never appears in user
1566 code. */
1567 if (/*CONSTCOND*/ 0)
1568 goto yyerrorlab;
1569
1570 /* Do not reclaim the symbols of the rule which action triggered
1571 this YYERROR. */
1572 YYPOPSTACK (yylen);
1573 yylen = 0;
1574 YY_STACK_PRINT (yyss, yyssp);
1575 yystate = *yyssp;
1576 goto yyerrlab1;
1577
1578
1579/*-------------------------------------------------------------.
1580| yyerrlab1 -- common code for both syntax error and YYERROR. |
1581`-------------------------------------------------------------*/
1582yyerrlab1:
1583 yyerrstatus = 3; /* Each real token shifted decrements this. */
1584
1585 for (;;)
1586 {
1587 yyn = yypact[yystate];
1588 if (yyn != YYPACT_NINF)
1589 {
1590 yyn += YYTERROR;
1591 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1592 {
1593 yyn = yytable[yyn];
1594 if (0 < yyn)
1595 break;
1596 }
1597 }
1598
1599 /* Pop the current state because it cannot handle the error token. */
1600 if (yyssp == yyss)
1601 YYABORT;
1602
1603
1604 yydestruct ("Error: popping",
1605 yystos[yystate], yyvsp);
1606 YYPOPSTACK (1);
1607 yystate = *yyssp;
1608 YY_STACK_PRINT (yyss, yyssp);
1609 }
1610
1611 if (yyn == YYFINAL)
1612 YYACCEPT;
1613
1614 *++yyvsp = yylval;
1615
1616
1617 /* Shift the error token. */
1618 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1619
1620 yystate = yyn;
1621 goto yynewstate;
1622
1623
1624/*-------------------------------------.
1625| yyacceptlab -- YYACCEPT comes here. |
1626`-------------------------------------*/
1627yyacceptlab:
1628 yyresult = 0;
1629 goto yyreturn;
1630
1631/*-----------------------------------.
1632| yyabortlab -- YYABORT comes here. |
1633`-----------------------------------*/
1634yyabortlab:
1635 yyresult = 1;
1636 goto yyreturn;
1637
1638#ifndef yyoverflow
1639/*-------------------------------------------------.
1640| yyexhaustedlab -- memory exhaustion comes here. |
1641`-------------------------------------------------*/
1642yyexhaustedlab:
1643 yyerror (YY_("memory exhausted"));
1644 yyresult = 2;
1645 /* Fall through. */
1646#endif
1647
1648yyreturn:
1649 if (yychar != YYEOF && yychar != YYEMPTY)
1650 yydestruct ("Cleanup: discarding lookahead",
1651 yytoken, &yylval);
1652 /* Do not reclaim the symbols of the rule which action triggered
1653 this YYABORT or YYACCEPT. */
1654 YYPOPSTACK (yylen);
1655 YY_STACK_PRINT (yyss, yyssp);
1656 while (yyssp != yyss)
1657 {
1658 yydestruct ("Cleanup: popping",
1659 yystos[*yyssp], yyvsp);
1660 YYPOPSTACK (1);
1661 }
1662#ifndef yyoverflow
1663 if (yyss != yyssa)
1664 YYSTACK_FREE (yyss);
1665#endif
1666#if YYERROR_VERBOSE
1667 if (yymsg != yymsgbuf)
1668 YYSTACK_FREE (yymsg);
1669#endif
1670 /* Make sure YYID is used. */
1671 return YYID (yyresult);
1672}
1673
1674
1675#line 165 "calc.y"
1676
1677/* End of rules, more C code will follow now */
1678
1679
1680int main()
1681{
1682 return yyparse();
1683}
1684
1685static void yyerror(const char *s)
1686{
1687 fprintf(stderr, "%s\n",s);
1688}
1689
1690int yywrap()
1691{
1692 return(1);
1693}
1694
1695int fac(int x)
1696{
1697 return (x > 1) ? x*fac(x-1) : 1;
1698}
1699
Note: See TracBrowser for help on using the repository browser.