Remove dependency on configdb when auto-generating CSR, because it has not been initi...
[citadel.git] / citadel / parsedate.c
1 /* A Bison parser, made by GNU Bison 3.0.2.  */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42
43 /* Identify Bison output.  */
44 #define YYBISON 1
45
46 /* Bison version.  */
47 #define YYBISON_VERSION "3.0.2"
48
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers.  */
53 #define YYPURE 0
54
55 /* Push parsers.  */
56 #define YYPUSH 0
57
58 /* Pull parsers.  */
59 #define YYPULL 1
60
61
62
63
64 /* Copy the first part of user declarations.  */
65 #line 1 "parsedate.y" /* yacc.c:339  */
66
67 /* $Revision$
68 **
69 **  Originally written by Steven M. Bellovin <smb@research.att.com> while
70 **  at the University of North Carolina at Chapel Hill.  Later tweaked by
71 **  a couple of people on Usenet.  Completely overhauled by Rich $alz
72 **  <rsalz@osf.org> and Jim Berets <jberets@bbn.com> in August, 1990.
73 **  Further revised (removed obsolete constructs and cleaned up timezone
74 **  names) in August, 1991, by Rich.  Paul Eggert <eggert@twinsun.com>
75 **  helped in September, 1992.  Art Cancro <ajc@citadel.org> cleaned
76 **  it up for ANSI C in December, 1999.
77 **
78 **  This grammar has six shift/reduce conflicts.
79 **
80 **  This code is in the public domain and has no copyright.
81 */
82 /* SUPPRESS 530 *//* Empty body for statement */
83 /* SUPPRESS 593 on yyerrlab *//* Label was not used */
84 /* SUPPRESS 593 on yynewstate *//* Label was not used */
85 /* SUPPRESS 595 on yypvt *//* Automatic variable may be used before set */
86
87 #include "sysdep.h"
88
89 #include <stdio.h>
90 #include <stdlib.h>
91 #include <sys/types.h>
92 #include <ctype.h>
93 #include <time.h>
94 #if HAVE_STRING_H
95 # if !STDC_HEADERS && HAVE_MEMORY_H
96 #  include <memory.h>
97 # endif
98 # include <string.h>
99 #endif
100 #if HAVE_STRINGS_H
101 # include <strings.h>
102 #endif
103
104 #include "parsedate.h"
105
106 int date_lex(void);
107
108 #define yyparse         date_parse
109 #define yylex           date_lex
110 #define yyerror         date_error
111
112
113     /* See the LeapYears table in Convert. */
114 #define EPOCH           1970
115 #define END_OF_TIME     2038
116     /* Constants for general time calculations. */
117 #define DST_OFFSET      1
118 #define SECSPERDAY      (24L * 60L * 60L)
119     /* Readability for TABLE stuff. */
120 #define HOUR(x)         (x * 60)
121
122 #define LPAREN          '('
123 #define RPAREN          ')'
124 #define IS7BIT(x)       ((unsigned int)(x) < 0200)
125
126 #define SIZEOF(array)   ((int)(sizeof array / sizeof array[0]))
127 #define ENDOF(array)    (&array[SIZEOF(array)])
128
129
130 /*
131 **  An entry in the lexical lookup table.
132 */
133 typedef struct _TABLE {
134     char        *name;
135     int         type;
136     time_t      value;
137 } TABLE;
138
139 /*
140 **  Daylight-savings mode:  on, off, or not yet known.
141 */
142 typedef enum _DSTMODE {
143     DSTon, DSToff, DSTmaybe
144 } DSTMODE;
145
146 /*
147 **  Meridian:  am, pm, or 24-hour style.
148 */
149 typedef enum _MERIDIAN {
150     MERam, MERpm, MER24
151 } MERIDIAN;
152
153
154 /*
155 **  Global variables.  We could get rid of most of them by using a yacc
156 **  union, but this is more efficient.  (This routine predates the
157 **  yacc %union construct.)
158 */
159 static const char       *yyInput;
160 static DSTMODE  yyDSTmode;
161 static int      yyHaveDate;
162 static int      yyHaveRel;
163 static int      yyHaveTime;
164 static time_t   yyTimezone;
165 static time_t   yyDay;
166 static time_t   yyHour;
167 static time_t   yyMinutes;
168 static time_t   yyMonth;
169 static time_t   yySeconds;
170 static time_t   yyYear;
171 static MERIDIAN yyMeridian;
172 static time_t   yyRelMonth;
173 static time_t   yyRelSeconds;
174
175
176 static void             date_error(char *);
177
178 #line 179 "y.tab.c" /* yacc.c:339  */
179
180 # ifndef YY_NULLPTR
181 #  if defined __cplusplus && 201103L <= __cplusplus
182 #   define YY_NULLPTR nullptr
183 #  else
184 #   define YY_NULLPTR 0
185 #  endif
186 # endif
187
188 /* Enabling verbose error messages.  */
189 #ifdef YYERROR_VERBOSE
190 # undef YYERROR_VERBOSE
191 # define YYERROR_VERBOSE 1
192 #else
193 # define YYERROR_VERBOSE 0
194 #endif
195
196
197 /* Debug traces.  */
198 #ifndef YYDEBUG
199 # define YYDEBUG 0
200 #endif
201 #if YYDEBUG
202 extern int yydebug;
203 #endif
204
205 /* Token type.  */
206 #ifndef YYTOKENTYPE
207 # define YYTOKENTYPE
208   enum yytokentype
209   {
210     tDAY = 258,
211     tDAYZONE = 259,
212     tMERIDIAN = 260,
213     tMONTH = 261,
214     tMONTH_UNIT = 262,
215     tSEC_UNIT = 263,
216     tSNUMBER = 264,
217     tUNUMBER = 265,
218     tZONE = 266
219   };
220 #endif
221 /* Tokens.  */
222 #define tDAY 258
223 #define tDAYZONE 259
224 #define tMERIDIAN 260
225 #define tMONTH 261
226 #define tMONTH_UNIT 262
227 #define tSEC_UNIT 263
228 #define tSNUMBER 264
229 #define tUNUMBER 265
230 #define tZONE 266
231
232 /* Value type.  */
233 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
234 typedef union YYSTYPE YYSTYPE;
235 union YYSTYPE
236 {
237 #line 114 "parsedate.y" /* yacc.c:355  */
238
239     time_t              Number;
240     enum _MERIDIAN      Meridian;
241
242 #line 243 "y.tab.c" /* yacc.c:355  */
243 };
244 # define YYSTYPE_IS_TRIVIAL 1
245 # define YYSTYPE_IS_DECLARED 1
246 #endif
247
248
249 extern YYSTYPE yylval;
250
251 int yyparse (void);
252
253
254
255 /* Copy the second part of user declarations.  */
256
257 #line 258 "y.tab.c" /* yacc.c:358  */
258
259 #ifdef short
260 # undef short
261 #endif
262
263 #ifdef YYTYPE_UINT8
264 typedef YYTYPE_UINT8 yytype_uint8;
265 #else
266 typedef unsigned char yytype_uint8;
267 #endif
268
269 #ifdef YYTYPE_INT8
270 typedef YYTYPE_INT8 yytype_int8;
271 #else
272 typedef signed char yytype_int8;
273 #endif
274
275 #ifdef YYTYPE_UINT16
276 typedef YYTYPE_UINT16 yytype_uint16;
277 #else
278 typedef unsigned short int yytype_uint16;
279 #endif
280
281 #ifdef YYTYPE_INT16
282 typedef YYTYPE_INT16 yytype_int16;
283 #else
284 typedef short int yytype_int16;
285 #endif
286
287 #ifndef YYSIZE_T
288 # ifdef __SIZE_TYPE__
289 #  define YYSIZE_T __SIZE_TYPE__
290 # elif defined size_t
291 #  define YYSIZE_T size_t
292 # elif ! defined YYSIZE_T
293 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
294 #  define YYSIZE_T size_t
295 # else
296 #  define YYSIZE_T unsigned int
297 # endif
298 #endif
299
300 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
301
302 #ifndef YY_
303 # if defined YYENABLE_NLS && YYENABLE_NLS
304 #  if ENABLE_NLS
305 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
306 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
307 #  endif
308 # endif
309 # ifndef YY_
310 #  define YY_(Msgid) Msgid
311 # endif
312 #endif
313
314 #ifndef YY_ATTRIBUTE
315 # if (defined __GNUC__                                               \
316       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
317      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
318 #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
319 # else
320 #  define YY_ATTRIBUTE(Spec) /* empty */
321 # endif
322 #endif
323
324 #ifndef YY_ATTRIBUTE_PURE
325 # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
326 #endif
327
328 #ifndef YY_ATTRIBUTE_UNUSED
329 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
330 #endif
331
332 #if !defined _Noreturn \
333      && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
334 # if defined _MSC_VER && 1200 <= _MSC_VER
335 #  define _Noreturn __declspec (noreturn)
336 # else
337 #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
338 # endif
339 #endif
340
341 /* Suppress unused-variable warnings by "using" E.  */
342 #if ! defined lint || defined __GNUC__
343 # define YYUSE(E) ((void) (E))
344 #else
345 # define YYUSE(E) /* empty */
346 #endif
347
348 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
349 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
350 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
351     _Pragma ("GCC diagnostic push") \
352     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
353     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
354 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
355     _Pragma ("GCC diagnostic pop")
356 #else
357 # define YY_INITIAL_VALUE(Value) Value
358 #endif
359 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
360 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
361 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
362 #endif
363 #ifndef YY_INITIAL_VALUE
364 # define YY_INITIAL_VALUE(Value) /* Nothing. */
365 #endif
366
367
368 #if ! defined yyoverflow || YYERROR_VERBOSE
369
370 /* The parser invokes alloca or malloc; define the necessary symbols.  */
371
372 # ifdef YYSTACK_USE_ALLOCA
373 #  if YYSTACK_USE_ALLOCA
374 #   ifdef __GNUC__
375 #    define YYSTACK_ALLOC __builtin_alloca
376 #   elif defined __BUILTIN_VA_ARG_INCR
377 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
378 #   elif defined _AIX
379 #    define YYSTACK_ALLOC __alloca
380 #   elif defined _MSC_VER
381 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
382 #    define alloca _alloca
383 #   else
384 #    define YYSTACK_ALLOC alloca
385 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
386 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
387       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
388 #     ifndef EXIT_SUCCESS
389 #      define EXIT_SUCCESS 0
390 #     endif
391 #    endif
392 #   endif
393 #  endif
394 # endif
395
396 # ifdef YYSTACK_ALLOC
397    /* Pacify GCC's 'empty if-body' warning.  */
398 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
399 #  ifndef YYSTACK_ALLOC_MAXIMUM
400     /* The OS might guarantee only one guard page at the bottom of the stack,
401        and a page size can be as small as 4096 bytes.  So we cannot safely
402        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
403        to allow for a few compiler-allocated temporary stack slots.  */
404 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
405 #  endif
406 # else
407 #  define YYSTACK_ALLOC YYMALLOC
408 #  define YYSTACK_FREE YYFREE
409 #  ifndef YYSTACK_ALLOC_MAXIMUM
410 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
411 #  endif
412 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
413        && ! ((defined YYMALLOC || defined malloc) \
414              && (defined YYFREE || defined free)))
415 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
416 #   ifndef EXIT_SUCCESS
417 #    define EXIT_SUCCESS 0
418 #   endif
419 #  endif
420 #  ifndef YYMALLOC
421 #   define YYMALLOC malloc
422 #   if ! defined malloc && ! defined EXIT_SUCCESS
423 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
424 #   endif
425 #  endif
426 #  ifndef YYFREE
427 #   define YYFREE free
428 #   if ! defined free && ! defined EXIT_SUCCESS
429 void free (void *); /* INFRINGES ON USER NAME SPACE */
430 #   endif
431 #  endif
432 # endif
433 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
434
435
436 #if (! defined yyoverflow \
437      && (! defined __cplusplus \
438          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
439
440 /* A type that is properly aligned for any stack member.  */
441 union yyalloc
442 {
443   yytype_int16 yyss_alloc;
444   YYSTYPE yyvs_alloc;
445 };
446
447 /* The size of the maximum gap between one aligned stack and the next.  */
448 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
449
450 /* The size of an array large to enough to hold all stacks, each with
451    N elements.  */
452 # define YYSTACK_BYTES(N) \
453      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
454       + YYSTACK_GAP_MAXIMUM)
455
456 # define YYCOPY_NEEDED 1
457
458 /* Relocate STACK from its old location to the new one.  The
459    local variables YYSIZE and YYSTACKSIZE give the old and new number of
460    elements in the stack, and YYPTR gives the new location of the
461    stack.  Advance YYPTR to a properly aligned location for the next
462    stack.  */
463 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
464     do                                                                  \
465       {                                                                 \
466         YYSIZE_T yynewbytes;                                            \
467         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
468         Stack = &yyptr->Stack_alloc;                                    \
469         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
470         yyptr += yynewbytes / sizeof (*yyptr);                          \
471       }                                                                 \
472     while (0)
473
474 #endif
475
476 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
477 /* Copy COUNT objects from SRC to DST.  The source and destination do
478    not overlap.  */
479 # ifndef YYCOPY
480 #  if defined __GNUC__ && 1 < __GNUC__
481 #   define YYCOPY(Dst, Src, Count) \
482       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
483 #  else
484 #   define YYCOPY(Dst, Src, Count)              \
485       do                                        \
486         {                                       \
487           YYSIZE_T yyi;                         \
488           for (yyi = 0; yyi < (Count); yyi++)   \
489             (Dst)[yyi] = (Src)[yyi];            \
490         }                                       \
491       while (0)
492 #  endif
493 # endif
494 #endif /* !YYCOPY_NEEDED */
495
496 /* YYFINAL -- State number of the termination state.  */
497 #define YYFINAL  2
498 /* YYLAST -- Last index in YYTABLE.  */
499 #define YYLAST   40
500
501 /* YYNTOKENS -- Number of terminals.  */
502 #define YYNTOKENS  15
503 /* YYNNTS -- Number of nonterminals.  */
504 #define YYNNTS  9
505 /* YYNRULES -- Number of rules.  */
506 #define YYNRULES  30
507 /* YYNSTATES -- Number of states.  */
508 #define YYNSTATES  44
509
510 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
511    by yylex, with out-of-bounds checking.  */
512 #define YYUNDEFTOK  2
513 #define YYMAXUTOK   266
514
515 #define YYTRANSLATE(YYX)                                                \
516   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
517
518 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
519    as returned by yylex, without out-of-bounds checking.  */
520 static const yytype_uint8 yytranslate[] =
521 {
522        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
523        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
524        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
525        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
526        2,     2,     2,     2,    14,     2,     2,    13,     2,     2,
527        2,     2,     2,     2,     2,     2,     2,     2,    12,     2,
528        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
529        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
530        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
531        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
532        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
533        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
534        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
535        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
536        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
537        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
538        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
539        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
540        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
541        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
542        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
543        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
544        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
545        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
546        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
547        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
548        5,     6,     7,     8,     9,    10,    11
549 };
550
551 #if YYDEBUG
552   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
553 static const yytype_uint16 yyrline[] =
554 {
555        0,   128,   128,   129,   132,   141,   145,   148,   153,   165,
556      171,   178,   184,   194,   198,   202,   210,   216,   237,   241,
557      253,   257,   262,   266,   271,   278,   281,   284,   287,   292,
558      295
559 };
560 #endif
561
562 #if YYDEBUG || YYERROR_VERBOSE || 0
563 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
564    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
565 static const char *const yytname[] =
566 {
567   "$end", "error", "$undefined", "tDAY", "tDAYZONE", "tMERIDIAN",
568   "tMONTH", "tMONTH_UNIT", "tSEC_UNIT", "tSNUMBER", "tUNUMBER", "tZONE",
569   "':'", "'/'", "','", "$accept", "spec", "item", "time", "zone",
570   "numzone", "date", "rel", "o_merid", YY_NULLPTR
571 };
572 #endif
573
574 # ifdef YYPRINT
575 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
576    (internal) symbol number NUM (which must be that of a token).  */
577 static const yytype_uint16 yytoknum[] =
578 {
579        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
580      265,   266,    58,    47,    44
581 };
582 # endif
583
584 #define YYPACT_NINF -29
585
586 #define yypact_value_is_default(Yystate) \
587   (!!((Yystate) == (-29)))
588
589 #define YYTABLE_NINF -1
590
591 #define yytable_value_is_error(Yytable_value) \
592   0
593
594   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
595      STATE-NUM.  */
596 static const yytype_int8 yypact[] =
597 {
598      -29,     1,   -29,   -11,    11,    20,    12,   -29,     4,   -29,
599      -29,    13,    16,   -29,   -29,   -29,    21,   -29,   -29,    22,
600       23,   -29,   -29,   -29,     5,   -29,   -29,    28,    25,   -29,
601       17,    24,   -29,    26,   -29,    29,   -29,   -29,    30,   -29,
602        0,   -29,   -29,   -29
603 };
604
605   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
606      Performed when YYTABLE does not specify something else to do.  Zero
607      means the default is an error.  */
608 static const yytype_uint8 yydefact[] =
609 {
610        2,     0,     1,     0,     0,     0,    29,     3,     4,     6,
611        7,     0,    20,    27,    25,    30,    22,    28,    26,     0,
612        0,     8,    14,    17,    13,     5,    16,     0,     0,    23,
613       29,    18,    15,     0,    21,     0,    10,     9,     0,    24,
614       29,    19,    12,    11
615 };
616
617   /* YYPGOTO[NTERM-NUM].  */
618 static const yytype_int8 yypgoto[] =
619 {
620      -29,   -29,   -29,   -29,   -29,   -24,   -29,   -29,   -28
621 };
622
623   /* YYDEFGOTO[NTERM-NUM].  */
624 static const yytype_int8 yydefgoto[] =
625 {
626       -1,     1,     7,     8,    25,    26,     9,    10,    21
627 };
628
629   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
630      positive, shift that token.  If negative, reduce the rule whose
631      number is the opposite.  If YYTABLE_NINF, syntax error.  */
632 static const yytype_uint8 yytable[] =
633 {
634       32,     2,    37,    11,     3,    15,    36,     4,    22,    23,
635        5,     6,    43,    23,    23,    24,    42,    15,    16,    17,
636       18,    12,    15,    27,    19,    20,    23,    13,    14,    35,
637       28,    29,    30,    31,    33,    34,    39,    38,     0,    40,
638       41
639 };
640
641 static const yytype_int8 yycheck[] =
642 {
643       24,     0,    30,    14,     3,     5,    30,     6,     4,     9,
644        9,    10,    40,     9,     9,    11,    40,     5,     6,     7,
645        8,    10,     5,    10,    12,    13,     9,     7,     8,    12,
646       14,    10,    10,    10,     6,    10,    10,    13,    -1,    10,
647       10
648 };
649
650   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
651      symbol of state STATE-NUM.  */
652 static const yytype_uint8 yystos[] =
653 {
654        0,    16,     0,     3,     6,     9,    10,    17,    18,    21,
655       22,    14,    10,     7,     8,     5,     6,     7,     8,    12,
656       13,    23,     4,     9,    11,    19,    20,    10,    14,    10,
657       10,    10,    20,     6,    10,    12,    20,    23,    13,    10,
658       10,    10,    20,    23
659 };
660
661   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
662 static const yytype_uint8 yyr1[] =
663 {
664        0,    15,    16,    16,    17,    17,    17,    17,    18,    18,
665       18,    18,    18,    19,    19,    19,    19,    20,    21,    21,
666       21,    21,    21,    21,    21,    22,    22,    22,    22,    23,
667       23
668 };
669
670   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
671 static const yytype_uint8 yyr2[] =
672 {
673        0,     2,     0,     2,     1,     2,     1,     1,     2,     4,
674        4,     6,     6,     1,     1,     2,     1,     1,     3,     5,
675        2,     4,     2,     3,     5,     2,     2,     2,     2,     0,
676        1
677 };
678
679
680 #define yyerrok         (yyerrstatus = 0)
681 #define yyclearin       (yychar = YYEMPTY)
682 #define YYEMPTY         (-2)
683 #define YYEOF           0
684
685 #define YYACCEPT        goto yyacceptlab
686 #define YYABORT         goto yyabortlab
687 #define YYERROR         goto yyerrorlab
688
689
690 #define YYRECOVERING()  (!!yyerrstatus)
691
692 #define YYBACKUP(Token, Value)                                  \
693 do                                                              \
694   if (yychar == YYEMPTY)                                        \
695     {                                                           \
696       yychar = (Token);                                         \
697       yylval = (Value);                                         \
698       YYPOPSTACK (yylen);                                       \
699       yystate = *yyssp;                                         \
700       goto yybackup;                                            \
701     }                                                           \
702   else                                                          \
703     {                                                           \
704       yyerror (YY_("syntax error: cannot back up")); \
705       YYERROR;                                                  \
706     }                                                           \
707 while (0)
708
709 /* Error token number */
710 #define YYTERROR        1
711 #define YYERRCODE       256
712
713
714
715 /* Enable debugging if requested.  */
716 #if YYDEBUG
717
718 # ifndef YYFPRINTF
719 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
720 #  define YYFPRINTF fprintf
721 # endif
722
723 # define YYDPRINTF(Args)                        \
724 do {                                            \
725   if (yydebug)                                  \
726     YYFPRINTF Args;                             \
727 } while (0)
728
729 /* This macro is provided for backward compatibility. */
730 #ifndef YY_LOCATION_PRINT
731 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
732 #endif
733
734
735 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
736 do {                                                                      \
737   if (yydebug)                                                            \
738     {                                                                     \
739       YYFPRINTF (stderr, "%s ", Title);                                   \
740       yy_symbol_print (stderr,                                            \
741                   Type, Value); \
742       YYFPRINTF (stderr, "\n");                                           \
743     }                                                                     \
744 } while (0)
745
746
747 /*----------------------------------------.
748 | Print this symbol's value on YYOUTPUT.  |
749 `----------------------------------------*/
750
751 static void
752 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
753 {
754   FILE *yyo = yyoutput;
755   YYUSE (yyo);
756   if (!yyvaluep)
757     return;
758 # ifdef YYPRINT
759   if (yytype < YYNTOKENS)
760     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
761 # endif
762   YYUSE (yytype);
763 }
764
765
766 /*--------------------------------.
767 | Print this symbol on YYOUTPUT.  |
768 `--------------------------------*/
769
770 static void
771 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
772 {
773   YYFPRINTF (yyoutput, "%s %s (",
774              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
775
776   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
777   YYFPRINTF (yyoutput, ")");
778 }
779
780 /*------------------------------------------------------------------.
781 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
782 | TOP (included).                                                   |
783 `------------------------------------------------------------------*/
784
785 static void
786 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
787 {
788   YYFPRINTF (stderr, "Stack now");
789   for (; yybottom <= yytop; yybottom++)
790     {
791       int yybot = *yybottom;
792       YYFPRINTF (stderr, " %d", yybot);
793     }
794   YYFPRINTF (stderr, "\n");
795 }
796
797 # define YY_STACK_PRINT(Bottom, Top)                            \
798 do {                                                            \
799   if (yydebug)                                                  \
800     yy_stack_print ((Bottom), (Top));                           \
801 } while (0)
802
803
804 /*------------------------------------------------.
805 | Report that the YYRULE is going to be reduced.  |
806 `------------------------------------------------*/
807
808 static void
809 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
810 {
811   unsigned long int yylno = yyrline[yyrule];
812   int yynrhs = yyr2[yyrule];
813   int yyi;
814   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
815              yyrule - 1, yylno);
816   /* The symbols being reduced.  */
817   for (yyi = 0; yyi < yynrhs; yyi++)
818     {
819       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
820       yy_symbol_print (stderr,
821                        yystos[yyssp[yyi + 1 - yynrhs]],
822                        &(yyvsp[(yyi + 1) - (yynrhs)])
823                                               );
824       YYFPRINTF (stderr, "\n");
825     }
826 }
827
828 # define YY_REDUCE_PRINT(Rule)          \
829 do {                                    \
830   if (yydebug)                          \
831     yy_reduce_print (yyssp, yyvsp, Rule); \
832 } while (0)
833
834 /* Nonzero means print parse trace.  It is left uninitialized so that
835    multiple parsers can coexist.  */
836 int yydebug;
837 #else /* !YYDEBUG */
838 # define YYDPRINTF(Args)
839 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
840 # define YY_STACK_PRINT(Bottom, Top)
841 # define YY_REDUCE_PRINT(Rule)
842 #endif /* !YYDEBUG */
843
844
845 /* YYINITDEPTH -- initial size of the parser's stacks.  */
846 #ifndef YYINITDEPTH
847 # define YYINITDEPTH 200
848 #endif
849
850 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
851    if the built-in stack extension method is used).
852
853    Do not make this value too large; the results are undefined if
854    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
855    evaluated with infinite-precision integer arithmetic.  */
856
857 #ifndef YYMAXDEPTH
858 # define YYMAXDEPTH 10000
859 #endif
860
861
862 #if YYERROR_VERBOSE
863
864 # ifndef yystrlen
865 #  if defined __GLIBC__ && defined _STRING_H
866 #   define yystrlen strlen
867 #  else
868 /* Return the length of YYSTR.  */
869 static YYSIZE_T
870 yystrlen (const char *yystr)
871 {
872   YYSIZE_T yylen;
873   for (yylen = 0; yystr[yylen]; yylen++)
874     continue;
875   return yylen;
876 }
877 #  endif
878 # endif
879
880 # ifndef yystpcpy
881 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
882 #   define yystpcpy stpcpy
883 #  else
884 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
885    YYDEST.  */
886 static char *
887 yystpcpy (char *yydest, const char *yysrc)
888 {
889   char *yyd = yydest;
890   const char *yys = yysrc;
891
892   while ((*yyd++ = *yys++) != '\0')
893     continue;
894
895   return yyd - 1;
896 }
897 #  endif
898 # endif
899
900 # ifndef yytnamerr
901 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
902    quotes and backslashes, so that it's suitable for yyerror.  The
903    heuristic is that double-quoting is unnecessary unless the string
904    contains an apostrophe, a comma, or backslash (other than
905    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
906    null, do not copy; instead, return the length of what the result
907    would have been.  */
908 static YYSIZE_T
909 yytnamerr (char *yyres, const char *yystr)
910 {
911   if (*yystr == '"')
912     {
913       YYSIZE_T yyn = 0;
914       char const *yyp = yystr;
915
916       for (;;)
917         switch (*++yyp)
918           {
919           case '\'':
920           case ',':
921             goto do_not_strip_quotes;
922
923           case '\\':
924             if (*++yyp != '\\')
925               goto do_not_strip_quotes;
926             /* Fall through.  */
927           default:
928             if (yyres)
929               yyres[yyn] = *yyp;
930             yyn++;
931             break;
932
933           case '"':
934             if (yyres)
935               yyres[yyn] = '\0';
936             return yyn;
937           }
938     do_not_strip_quotes: ;
939     }
940
941   if (! yyres)
942     return yystrlen (yystr);
943
944   return yystpcpy (yyres, yystr) - yyres;
945 }
946 # endif
947
948 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
949    about the unexpected token YYTOKEN for the state stack whose top is
950    YYSSP.
951
952    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
953    not large enough to hold the message.  In that case, also set
954    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
955    required number of bytes is too large to store.  */
956 static int
957 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
958                 yytype_int16 *yyssp, int yytoken)
959 {
960   YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
961   YYSIZE_T yysize = yysize0;
962   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
963   /* Internationalized format string. */
964   const char *yyformat = YY_NULLPTR;
965   /* Arguments of yyformat. */
966   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
967   /* Number of reported tokens (one for the "unexpected", one per
968      "expected"). */
969   int yycount = 0;
970
971   /* There are many possibilities here to consider:
972      - If this state is a consistent state with a default action, then
973        the only way this function was invoked is if the default action
974        is an error action.  In that case, don't check for expected
975        tokens because there are none.
976      - The only way there can be no lookahead present (in yychar) is if
977        this state is a consistent state with a default action.  Thus,
978        detecting the absence of a lookahead is sufficient to determine
979        that there is no unexpected or expected token to report.  In that
980        case, just report a simple "syntax error".
981      - Don't assume there isn't a lookahead just because this state is a
982        consistent state with a default action.  There might have been a
983        previous inconsistent state, consistent state with a non-default
984        action, or user semantic action that manipulated yychar.
985      - Of course, the expected token list depends on states to have
986        correct lookahead information, and it depends on the parser not
987        to perform extra reductions after fetching a lookahead from the
988        scanner and before detecting a syntax error.  Thus, state merging
989        (from LALR or IELR) and default reductions corrupt the expected
990        token list.  However, the list is correct for canonical LR with
991        one exception: it will still contain any token that will not be
992        accepted due to an error action in a later state.
993   */
994   if (yytoken != YYEMPTY)
995     {
996       int yyn = yypact[*yyssp];
997       yyarg[yycount++] = yytname[yytoken];
998       if (!yypact_value_is_default (yyn))
999         {
1000           /* Start YYX at -YYN if negative to avoid negative indexes in
1001              YYCHECK.  In other words, skip the first -YYN actions for
1002              this state because they are default actions.  */
1003           int yyxbegin = yyn < 0 ? -yyn : 0;
1004           /* Stay within bounds of both yycheck and yytname.  */
1005           int yychecklim = YYLAST - yyn + 1;
1006           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1007           int yyx;
1008
1009           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1010             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1011                 && !yytable_value_is_error (yytable[yyx + yyn]))
1012               {
1013                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1014                   {
1015                     yycount = 1;
1016                     yysize = yysize0;
1017                     break;
1018                   }
1019                 yyarg[yycount++] = yytname[yyx];
1020                 {
1021                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1022                   if (! (yysize <= yysize1
1023                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1024                     return 2;
1025                   yysize = yysize1;
1026                 }
1027               }
1028         }
1029     }
1030
1031   switch (yycount)
1032     {
1033 # define YYCASE_(N, S)                      \
1034       case N:                               \
1035         yyformat = S;                       \
1036       break
1037       YYCASE_(0, YY_("syntax error"));
1038       YYCASE_(1, YY_("syntax error, unexpected %s"));
1039       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1040       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1041       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1042       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1043 # undef YYCASE_
1044     }
1045
1046   {
1047     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1048     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1049       return 2;
1050     yysize = yysize1;
1051   }
1052
1053   if (*yymsg_alloc < yysize)
1054     {
1055       *yymsg_alloc = 2 * yysize;
1056       if (! (yysize <= *yymsg_alloc
1057              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1058         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1059       return 1;
1060     }
1061
1062   /* Avoid sprintf, as that infringes on the user's name space.
1063      Don't have undefined behavior even if the translation
1064      produced a string with the wrong number of "%s"s.  */
1065   {
1066     char *yyp = *yymsg;
1067     int yyi = 0;
1068     while ((*yyp = *yyformat) != '\0')
1069       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1070         {
1071           yyp += yytnamerr (yyp, yyarg[yyi++]);
1072           yyformat += 2;
1073         }
1074       else
1075         {
1076           yyp++;
1077           yyformat++;
1078         }
1079   }
1080   return 0;
1081 }
1082 #endif /* YYERROR_VERBOSE */
1083
1084 /*-----------------------------------------------.
1085 | Release the memory associated to this symbol.  |
1086 `-----------------------------------------------*/
1087
1088 static void
1089 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1090 {
1091   YYUSE (yyvaluep);
1092   if (!yymsg)
1093     yymsg = "Deleting";
1094   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1095
1096   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1097   YYUSE (yytype);
1098   YY_IGNORE_MAYBE_UNINITIALIZED_END
1099 }
1100
1101
1102
1103
1104 /* The lookahead symbol.  */
1105 int yychar;
1106
1107 /* The semantic value of the lookahead symbol.  */
1108 YYSTYPE yylval;
1109 /* Number of syntax errors so far.  */
1110 int yynerrs;
1111
1112
1113 /*----------.
1114 | yyparse.  |
1115 `----------*/
1116
1117 int
1118 yyparse (void)
1119 {
1120     int yystate;
1121     /* Number of tokens to shift before error messages enabled.  */
1122     int yyerrstatus;
1123
1124     /* The stacks and their tools:
1125        'yyss': related to states.
1126        'yyvs': related to semantic values.
1127
1128        Refer to the stacks through separate pointers, to allow yyoverflow
1129        to reallocate them elsewhere.  */
1130
1131     /* The state stack.  */
1132     yytype_int16 yyssa[YYINITDEPTH];
1133     yytype_int16 *yyss;
1134     yytype_int16 *yyssp;
1135
1136     /* The semantic value stack.  */
1137     YYSTYPE yyvsa[YYINITDEPTH];
1138     YYSTYPE *yyvs;
1139     YYSTYPE *yyvsp;
1140
1141     YYSIZE_T yystacksize;
1142
1143   int yyn;
1144   int yyresult;
1145   /* Lookahead token as an internal (translated) token number.  */
1146   int yytoken = 0;
1147   /* The variables used to return semantic value and location from the
1148      action routines.  */
1149   YYSTYPE yyval;
1150
1151 #if YYERROR_VERBOSE
1152   /* Buffer for error messages, and its allocated size.  */
1153   char yymsgbuf[128];
1154   char *yymsg = yymsgbuf;
1155   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1156 #endif
1157
1158 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1159
1160   /* The number of symbols on the RHS of the reduced rule.
1161      Keep to zero when no symbol should be popped.  */
1162   int yylen = 0;
1163
1164   yyssp = yyss = yyssa;
1165   yyvsp = yyvs = yyvsa;
1166   yystacksize = YYINITDEPTH;
1167
1168   YYDPRINTF ((stderr, "Starting parse\n"));
1169
1170   yystate = 0;
1171   yyerrstatus = 0;
1172   yynerrs = 0;
1173   yychar = YYEMPTY; /* Cause a token to be read.  */
1174   goto yysetstate;
1175
1176 /*------------------------------------------------------------.
1177 | yynewstate -- Push a new state, which is found in yystate.  |
1178 `------------------------------------------------------------*/
1179  yynewstate:
1180   /* In all cases, when you get here, the value and location stacks
1181      have just been pushed.  So pushing a state here evens the stacks.  */
1182   yyssp++;
1183
1184  yysetstate:
1185   *yyssp = yystate;
1186
1187   if (yyss + yystacksize - 1 <= yyssp)
1188     {
1189       /* Get the current used size of the three stacks, in elements.  */
1190       YYSIZE_T yysize = yyssp - yyss + 1;
1191
1192 #ifdef yyoverflow
1193       {
1194         /* Give user a chance to reallocate the stack.  Use copies of
1195            these so that the &'s don't force the real ones into
1196            memory.  */
1197         YYSTYPE *yyvs1 = yyvs;
1198         yytype_int16 *yyss1 = yyss;
1199
1200         /* Each stack pointer address is followed by the size of the
1201            data in use in that stack, in bytes.  This used to be a
1202            conditional around just the two extra args, but that might
1203            be undefined if yyoverflow is a macro.  */
1204         yyoverflow (YY_("memory exhausted"),
1205                     &yyss1, yysize * sizeof (*yyssp),
1206                     &yyvs1, yysize * sizeof (*yyvsp),
1207                     &yystacksize);
1208
1209         yyss = yyss1;
1210         yyvs = yyvs1;
1211       }
1212 #else /* no yyoverflow */
1213 # ifndef YYSTACK_RELOCATE
1214       goto yyexhaustedlab;
1215 # else
1216       /* Extend the stack our own way.  */
1217       if (YYMAXDEPTH <= yystacksize)
1218         goto yyexhaustedlab;
1219       yystacksize *= 2;
1220       if (YYMAXDEPTH < yystacksize)
1221         yystacksize = YYMAXDEPTH;
1222
1223       {
1224         yytype_int16 *yyss1 = yyss;
1225         union yyalloc *yyptr =
1226           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1227         if (! yyptr)
1228           goto yyexhaustedlab;
1229         YYSTACK_RELOCATE (yyss_alloc, yyss);
1230         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1231 #  undef YYSTACK_RELOCATE
1232         if (yyss1 != yyssa)
1233           YYSTACK_FREE (yyss1);
1234       }
1235 # endif
1236 #endif /* no yyoverflow */
1237
1238       yyssp = yyss + yysize - 1;
1239       yyvsp = yyvs + yysize - 1;
1240
1241       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1242                   (unsigned long int) yystacksize));
1243
1244       if (yyss + yystacksize - 1 <= yyssp)
1245         YYABORT;
1246     }
1247
1248   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1249
1250   if (yystate == YYFINAL)
1251     YYACCEPT;
1252
1253   goto yybackup;
1254
1255 /*-----------.
1256 | yybackup.  |
1257 `-----------*/
1258 yybackup:
1259
1260   /* Do appropriate processing given the current state.  Read a
1261      lookahead token if we need one and don't already have one.  */
1262
1263   /* First try to decide what to do without reference to lookahead token.  */
1264   yyn = yypact[yystate];
1265   if (yypact_value_is_default (yyn))
1266     goto yydefault;
1267
1268   /* Not known => get a lookahead token if don't already have one.  */
1269
1270   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1271   if (yychar == YYEMPTY)
1272     {
1273       YYDPRINTF ((stderr, "Reading a token: "));
1274       yychar = yylex ();
1275     }
1276
1277   if (yychar <= YYEOF)
1278     {
1279       yychar = yytoken = YYEOF;
1280       YYDPRINTF ((stderr, "Now at end of input.\n"));
1281     }
1282   else
1283     {
1284       yytoken = YYTRANSLATE (yychar);
1285       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1286     }
1287
1288   /* If the proper action on seeing token YYTOKEN is to reduce or to
1289      detect an error, take that action.  */
1290   yyn += yytoken;
1291   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1292     goto yydefault;
1293   yyn = yytable[yyn];
1294   if (yyn <= 0)
1295     {
1296       if (yytable_value_is_error (yyn))
1297         goto yyerrlab;
1298       yyn = -yyn;
1299       goto yyreduce;
1300     }
1301
1302   /* Count tokens shifted since error; after three, turn off error
1303      status.  */
1304   if (yyerrstatus)
1305     yyerrstatus--;
1306
1307   /* Shift the lookahead token.  */
1308   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1309
1310   /* Discard the shifted token.  */
1311   yychar = YYEMPTY;
1312
1313   yystate = yyn;
1314   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1315   *++yyvsp = yylval;
1316   YY_IGNORE_MAYBE_UNINITIALIZED_END
1317
1318   goto yynewstate;
1319
1320
1321 /*-----------------------------------------------------------.
1322 | yydefault -- do the default action for the current state.  |
1323 `-----------------------------------------------------------*/
1324 yydefault:
1325   yyn = yydefact[yystate];
1326   if (yyn == 0)
1327     goto yyerrlab;
1328   goto yyreduce;
1329
1330
1331 /*-----------------------------.
1332 | yyreduce -- Do a reduction.  |
1333 `-----------------------------*/
1334 yyreduce:
1335   /* yyn is the number of a rule to reduce with.  */
1336   yylen = yyr2[yyn];
1337
1338   /* If YYLEN is nonzero, implement the default value of the action:
1339      '$$ = $1'.
1340
1341      Otherwise, the following line sets YYVAL to garbage.
1342      This behavior is undocumented and Bison
1343      users should not rely upon it.  Assigning to YYVAL
1344      unconditionally makes the parser a bit smaller, and it avoids a
1345      GCC warning that YYVAL may be used uninitialized.  */
1346   yyval = yyvsp[1-yylen];
1347
1348
1349   YY_REDUCE_PRINT (yyn);
1350   switch (yyn)
1351     {
1352         case 4:
1353 #line 132 "parsedate.y" /* yacc.c:1646  */
1354     {
1355             yyHaveTime++;
1356 #ifdef lint
1357             /* I am compulsive about lint natterings... */
1358             if (yyHaveTime == -1) {
1359                 YYERROR;
1360             }
1361 #endif /* lint */
1362         }
1363 #line 1364 "y.tab.c" /* yacc.c:1646  */
1364     break;
1365
1366   case 5:
1367 #line 141 "parsedate.y" /* yacc.c:1646  */
1368     {
1369             yyHaveTime++;
1370             yyTimezone = (yyvsp[0].Number);
1371         }
1372 #line 1373 "y.tab.c" /* yacc.c:1646  */
1373     break;
1374
1375   case 6:
1376 #line 145 "parsedate.y" /* yacc.c:1646  */
1377     {
1378             yyHaveDate++;
1379         }
1380 #line 1381 "y.tab.c" /* yacc.c:1646  */
1381     break;
1382
1383   case 7:
1384 #line 148 "parsedate.y" /* yacc.c:1646  */
1385     {
1386             yyHaveRel = 1;
1387         }
1388 #line 1389 "y.tab.c" /* yacc.c:1646  */
1389     break;
1390
1391   case 8:
1392 #line 153 "parsedate.y" /* yacc.c:1646  */
1393     {
1394             if ((yyvsp[-1].Number) < 100) {
1395                 yyHour = (yyvsp[-1].Number);
1396                 yyMinutes = 0;
1397             }
1398             else {
1399                 yyHour = (yyvsp[-1].Number) / 100;
1400                 yyMinutes = (yyvsp[-1].Number) % 100;
1401             }
1402             yySeconds = 0;
1403             yyMeridian = (yyvsp[0].Meridian);
1404         }
1405 #line 1406 "y.tab.c" /* yacc.c:1646  */
1406     break;
1407
1408   case 9:
1409 #line 165 "parsedate.y" /* yacc.c:1646  */
1410     {
1411             yyHour = (yyvsp[-3].Number);
1412             yyMinutes = (yyvsp[-1].Number);
1413             yySeconds = 0;
1414             yyMeridian = (yyvsp[0].Meridian);
1415         }
1416 #line 1417 "y.tab.c" /* yacc.c:1646  */
1417     break;
1418
1419   case 10:
1420 #line 171 "parsedate.y" /* yacc.c:1646  */
1421     {
1422             yyHour = (yyvsp[-3].Number);
1423             yyMinutes = (yyvsp[-1].Number);
1424             yyTimezone = (yyvsp[0].Number);
1425             yyMeridian = MER24;
1426             yyDSTmode = DSToff;
1427         }
1428 #line 1429 "y.tab.c" /* yacc.c:1646  */
1429     break;
1430
1431   case 11:
1432 #line 178 "parsedate.y" /* yacc.c:1646  */
1433     {
1434             yyHour = (yyvsp[-5].Number);
1435             yyMinutes = (yyvsp[-3].Number);
1436             yySeconds = (yyvsp[-1].Number);
1437             yyMeridian = (yyvsp[0].Meridian);
1438         }
1439 #line 1440 "y.tab.c" /* yacc.c:1646  */
1440     break;
1441
1442   case 12:
1443 #line 184 "parsedate.y" /* yacc.c:1646  */
1444     {
1445             yyHour = (yyvsp[-5].Number);
1446             yyMinutes = (yyvsp[-3].Number);
1447             yySeconds = (yyvsp[-1].Number);
1448             yyTimezone = (yyvsp[0].Number);
1449             yyMeridian = MER24;
1450             yyDSTmode = DSToff;
1451         }
1452 #line 1453 "y.tab.c" /* yacc.c:1646  */
1453     break;
1454
1455   case 13:
1456 #line 194 "parsedate.y" /* yacc.c:1646  */
1457     {
1458             (yyval.Number) = (yyvsp[0].Number);
1459             yyDSTmode = DSToff;
1460         }
1461 #line 1462 "y.tab.c" /* yacc.c:1646  */
1462     break;
1463
1464   case 14:
1465 #line 198 "parsedate.y" /* yacc.c:1646  */
1466     {
1467             (yyval.Number) = (yyvsp[0].Number);
1468             yyDSTmode = DSTon;
1469         }
1470 #line 1471 "y.tab.c" /* yacc.c:1646  */
1471     break;
1472
1473   case 15:
1474 #line 202 "parsedate.y" /* yacc.c:1646  */
1475     {
1476             /* Only allow "GMT+300" and "GMT-0800" */
1477             if ((yyvsp[-1].Number) != 0) {
1478                 YYABORT;
1479             }
1480             (yyval.Number) = (yyvsp[0].Number);
1481             yyDSTmode = DSToff;
1482         }
1483 #line 1484 "y.tab.c" /* yacc.c:1646  */
1484     break;
1485
1486   case 16:
1487 #line 210 "parsedate.y" /* yacc.c:1646  */
1488     {
1489             (yyval.Number) = (yyvsp[0].Number);
1490             yyDSTmode = DSToff;
1491         }
1492 #line 1493 "y.tab.c" /* yacc.c:1646  */
1493     break;
1494
1495   case 17:
1496 #line 216 "parsedate.y" /* yacc.c:1646  */
1497     {
1498             int         i;
1499
1500             /* Unix and GMT and numeric timezones -- a little confusing. */
1501             if ((yyvsp[0].Number) < 0) {
1502                 /* Don't work with negative modulus. */
1503                 (yyvsp[0].Number) = -(yyvsp[0].Number);
1504                 if ((yyvsp[0].Number) > 9999 || (i = (yyvsp[0].Number) % 100) >= 60) {
1505                     YYABORT;
1506                 }
1507                 (yyval.Number) = ((yyvsp[0].Number) / 100) * 60 + i;
1508             }
1509             else {
1510                 if ((yyvsp[0].Number) > 9999 || (i = (yyvsp[0].Number) % 100) >= 60) {
1511                     YYABORT;
1512                 }
1513                 (yyval.Number) = -(((yyvsp[0].Number) / 100) * 60 + i);
1514             }
1515         }
1516 #line 1517 "y.tab.c" /* yacc.c:1646  */
1517     break;
1518
1519   case 18:
1520 #line 237 "parsedate.y" /* yacc.c:1646  */
1521     {
1522             yyMonth = (yyvsp[-2].Number);
1523             yyDay = (yyvsp[0].Number);
1524         }
1525 #line 1526 "y.tab.c" /* yacc.c:1646  */
1526     break;
1527
1528   case 19:
1529 #line 241 "parsedate.y" /* yacc.c:1646  */
1530     {
1531             if ((yyvsp[-4].Number) > 100) {
1532                 yyYear = (yyvsp[-4].Number);
1533                 yyMonth = (yyvsp[-2].Number);
1534                 yyDay = (yyvsp[0].Number);
1535             }
1536             else {
1537                 yyMonth = (yyvsp[-4].Number);
1538                 yyDay = (yyvsp[-2].Number);
1539                 yyYear = (yyvsp[0].Number);
1540             }
1541         }
1542 #line 1543 "y.tab.c" /* yacc.c:1646  */
1543     break;
1544
1545   case 20:
1546 #line 253 "parsedate.y" /* yacc.c:1646  */
1547     {
1548             yyMonth = (yyvsp[-1].Number);
1549             yyDay = (yyvsp[0].Number);
1550         }
1551 #line 1552 "y.tab.c" /* yacc.c:1646  */
1552     break;
1553
1554   case 21:
1555 #line 257 "parsedate.y" /* yacc.c:1646  */
1556     {
1557             yyMonth = (yyvsp[-3].Number);
1558             yyDay = (yyvsp[-2].Number);
1559             yyYear = (yyvsp[0].Number);
1560         }
1561 #line 1562 "y.tab.c" /* yacc.c:1646  */
1562     break;
1563
1564   case 22:
1565 #line 262 "parsedate.y" /* yacc.c:1646  */
1566     {
1567             yyDay = (yyvsp[-1].Number);
1568             yyMonth = (yyvsp[0].Number);
1569         }
1570 #line 1571 "y.tab.c" /* yacc.c:1646  */
1571     break;
1572
1573   case 23:
1574 #line 266 "parsedate.y" /* yacc.c:1646  */
1575     {
1576             yyDay = (yyvsp[-2].Number);
1577             yyMonth = (yyvsp[-1].Number);
1578             yyYear = (yyvsp[0].Number);
1579         }
1580 #line 1581 "y.tab.c" /* yacc.c:1646  */
1581     break;
1582
1583   case 24:
1584 #line 271 "parsedate.y" /* yacc.c:1646  */
1585     {
1586             yyDay = (yyvsp[-2].Number);
1587             yyMonth = (yyvsp[-1].Number);
1588             yyYear = (yyvsp[0].Number);
1589         }
1590 #line 1591 "y.tab.c" /* yacc.c:1646  */
1591     break;
1592
1593   case 25:
1594 #line 278 "parsedate.y" /* yacc.c:1646  */
1595     {
1596             yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
1597         }
1598 #line 1599 "y.tab.c" /* yacc.c:1646  */
1599     break;
1600
1601   case 26:
1602 #line 281 "parsedate.y" /* yacc.c:1646  */
1603     {
1604             yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
1605         }
1606 #line 1607 "y.tab.c" /* yacc.c:1646  */
1607     break;
1608
1609   case 27:
1610 #line 284 "parsedate.y" /* yacc.c:1646  */
1611     {
1612             yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
1613         }
1614 #line 1615 "y.tab.c" /* yacc.c:1646  */
1615     break;
1616
1617   case 28:
1618 #line 287 "parsedate.y" /* yacc.c:1646  */
1619     {
1620             yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
1621         }
1622 #line 1623 "y.tab.c" /* yacc.c:1646  */
1623     break;
1624
1625   case 29:
1626 #line 292 "parsedate.y" /* yacc.c:1646  */
1627     {
1628             (yyval.Meridian) = MER24;
1629         }
1630 #line 1631 "y.tab.c" /* yacc.c:1646  */
1631     break;
1632
1633   case 30:
1634 #line 295 "parsedate.y" /* yacc.c:1646  */
1635     {
1636             (yyval.Meridian) = (yyvsp[0].Meridian);
1637         }
1638 #line 1639 "y.tab.c" /* yacc.c:1646  */
1639     break;
1640
1641
1642 #line 1643 "y.tab.c" /* yacc.c:1646  */
1643       default: break;
1644     }
1645   /* User semantic actions sometimes alter yychar, and that requires
1646      that yytoken be updated with the new translation.  We take the
1647      approach of translating immediately before every use of yytoken.
1648      One alternative is translating here after every semantic action,
1649      but that translation would be missed if the semantic action invokes
1650      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1651      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
1652      incorrect destructor might then be invoked immediately.  In the
1653      case of YYERROR or YYBACKUP, subsequent parser actions might lead
1654      to an incorrect destructor call or verbose syntax error message
1655      before the lookahead is translated.  */
1656   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1657
1658   YYPOPSTACK (yylen);
1659   yylen = 0;
1660   YY_STACK_PRINT (yyss, yyssp);
1661
1662   *++yyvsp = yyval;
1663
1664   /* Now 'shift' the result of the reduction.  Determine what state
1665      that goes to, based on the state we popped back to and the rule
1666      number reduced by.  */
1667
1668   yyn = yyr1[yyn];
1669
1670   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1671   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1672     yystate = yytable[yystate];
1673   else
1674     yystate = yydefgoto[yyn - YYNTOKENS];
1675
1676   goto yynewstate;
1677
1678
1679 /*--------------------------------------.
1680 | yyerrlab -- here on detecting error.  |
1681 `--------------------------------------*/
1682 yyerrlab:
1683   /* Make sure we have latest lookahead translation.  See comments at
1684      user semantic actions for why this is necessary.  */
1685   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1686
1687   /* If not already recovering from an error, report this error.  */
1688   if (!yyerrstatus)
1689     {
1690       ++yynerrs;
1691 #if ! YYERROR_VERBOSE
1692       yyerror (YY_("syntax error"));
1693 #else
1694 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1695                                         yyssp, yytoken)
1696       {
1697         char const *yymsgp = YY_("syntax error");
1698         int yysyntax_error_status;
1699         yysyntax_error_status = YYSYNTAX_ERROR;
1700         if (yysyntax_error_status == 0)
1701           yymsgp = yymsg;
1702         else if (yysyntax_error_status == 1)
1703           {
1704             if (yymsg != yymsgbuf)
1705               YYSTACK_FREE (yymsg);
1706             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1707             if (!yymsg)
1708               {
1709                 yymsg = yymsgbuf;
1710                 yymsg_alloc = sizeof yymsgbuf;
1711                 yysyntax_error_status = 2;
1712               }
1713             else
1714               {
1715                 yysyntax_error_status = YYSYNTAX_ERROR;
1716                 yymsgp = yymsg;
1717               }
1718           }
1719         yyerror (yymsgp);
1720         if (yysyntax_error_status == 2)
1721           goto yyexhaustedlab;
1722       }
1723 # undef YYSYNTAX_ERROR
1724 #endif
1725     }
1726
1727
1728
1729   if (yyerrstatus == 3)
1730     {
1731       /* If just tried and failed to reuse lookahead token after an
1732          error, discard it.  */
1733
1734       if (yychar <= YYEOF)
1735         {
1736           /* Return failure if at end of input.  */
1737           if (yychar == YYEOF)
1738             YYABORT;
1739         }
1740       else
1741         {
1742           yydestruct ("Error: discarding",
1743                       yytoken, &yylval);
1744           yychar = YYEMPTY;
1745         }
1746     }
1747
1748   /* Else will try to reuse lookahead token after shifting the error
1749      token.  */
1750   goto yyerrlab1;
1751
1752
1753 /*---------------------------------------------------.
1754 | yyerrorlab -- error raised explicitly by YYERROR.  |
1755 `---------------------------------------------------*/
1756 yyerrorlab:
1757
1758   /* Pacify compilers like GCC when the user code never invokes
1759      YYERROR and the label yyerrorlab therefore never appears in user
1760      code.  */
1761   if (/*CONSTCOND*/ 0)
1762      goto yyerrorlab;
1763
1764   /* Do not reclaim the symbols of the rule whose action triggered
1765      this YYERROR.  */
1766   YYPOPSTACK (yylen);
1767   yylen = 0;
1768   YY_STACK_PRINT (yyss, yyssp);
1769   yystate = *yyssp;
1770   goto yyerrlab1;
1771
1772
1773 /*-------------------------------------------------------------.
1774 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1775 `-------------------------------------------------------------*/
1776 yyerrlab1:
1777   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1778
1779   for (;;)
1780     {
1781       yyn = yypact[yystate];
1782       if (!yypact_value_is_default (yyn))
1783         {
1784           yyn += YYTERROR;
1785           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1786             {
1787               yyn = yytable[yyn];
1788               if (0 < yyn)
1789                 break;
1790             }
1791         }
1792
1793       /* Pop the current state because it cannot handle the error token.  */
1794       if (yyssp == yyss)
1795         YYABORT;
1796
1797
1798       yydestruct ("Error: popping",
1799                   yystos[yystate], yyvsp);
1800       YYPOPSTACK (1);
1801       yystate = *yyssp;
1802       YY_STACK_PRINT (yyss, yyssp);
1803     }
1804
1805   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1806   *++yyvsp = yylval;
1807   YY_IGNORE_MAYBE_UNINITIALIZED_END
1808
1809
1810   /* Shift the error token.  */
1811   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1812
1813   yystate = yyn;
1814   goto yynewstate;
1815
1816
1817 /*-------------------------------------.
1818 | yyacceptlab -- YYACCEPT comes here.  |
1819 `-------------------------------------*/
1820 yyacceptlab:
1821   yyresult = 0;
1822   goto yyreturn;
1823
1824 /*-----------------------------------.
1825 | yyabortlab -- YYABORT comes here.  |
1826 `-----------------------------------*/
1827 yyabortlab:
1828   yyresult = 1;
1829   goto yyreturn;
1830
1831 #if !defined yyoverflow || YYERROR_VERBOSE
1832 /*-------------------------------------------------.
1833 | yyexhaustedlab -- memory exhaustion comes here.  |
1834 `-------------------------------------------------*/
1835 yyexhaustedlab:
1836   yyerror (YY_("memory exhausted"));
1837   yyresult = 2;
1838   /* Fall through.  */
1839 #endif
1840
1841 yyreturn:
1842   if (yychar != YYEMPTY)
1843     {
1844       /* Make sure we have latest lookahead translation.  See comments at
1845          user semantic actions for why this is necessary.  */
1846       yytoken = YYTRANSLATE (yychar);
1847       yydestruct ("Cleanup: discarding lookahead",
1848                   yytoken, &yylval);
1849     }
1850   /* Do not reclaim the symbols of the rule whose action triggered
1851      this YYABORT or YYACCEPT.  */
1852   YYPOPSTACK (yylen);
1853   YY_STACK_PRINT (yyss, yyssp);
1854   while (yyssp != yyss)
1855     {
1856       yydestruct ("Cleanup: popping",
1857                   yystos[*yyssp], yyvsp);
1858       YYPOPSTACK (1);
1859     }
1860 #ifndef yyoverflow
1861   if (yyss != yyssa)
1862     YYSTACK_FREE (yyss);
1863 #endif
1864 #if YYERROR_VERBOSE
1865   if (yymsg != yymsgbuf)
1866     YYSTACK_FREE (yymsg);
1867 #endif
1868   return yyresult;
1869 }
1870 #line 300 "parsedate.y" /* yacc.c:1906  */
1871
1872
1873 /* Month and day table. */
1874 static TABLE    MonthDayTable[] = {
1875     { "january",        tMONTH,  1 },
1876     { "february",       tMONTH,  2 },
1877     { "march",          tMONTH,  3 },
1878     { "april",          tMONTH,  4 },
1879     { "may",            tMONTH,  5 },
1880     { "june",           tMONTH,  6 },
1881     { "july",           tMONTH,  7 },
1882     { "august",         tMONTH,  8 },
1883     { "september",      tMONTH,  9 },
1884     { "october",        tMONTH, 10 },
1885     { "november",       tMONTH, 11 },
1886     { "december",       tMONTH, 12 },
1887         /* The value of the day isn't used... */
1888     { "sunday",         tDAY, 0 },
1889     { "monday",         tDAY, 0 },
1890     { "tuesday",        tDAY, 0 },
1891     { "wednesday",      tDAY, 0 },
1892     { "thursday",       tDAY, 0 },
1893     { "friday",         tDAY, 0 },
1894     { "saturday",       tDAY, 0 },
1895 };
1896
1897 /* Time units table. */
1898 static TABLE    UnitsTable[] = {
1899     { "year",           tMONTH_UNIT,    12 },
1900     { "month",          tMONTH_UNIT,    1 },
1901     { "week",           tSEC_UNIT,      7L * 24 * 60 * 60 },
1902     { "day",            tSEC_UNIT,      1L * 24 * 60 * 60 },
1903     { "hour",           tSEC_UNIT,      60 * 60 },
1904     { "minute",         tSEC_UNIT,      60 },
1905     { "min",            tSEC_UNIT,      60 },
1906     { "second",         tSEC_UNIT,      1 },
1907     { "sec",            tSEC_UNIT,      1 },
1908 };
1909
1910 /* Timezone table. */
1911 static TABLE    TimezoneTable[] = {
1912     { "gmt",    tZONE,     HOUR( 0) },  /* Greenwich Mean */
1913     { "ut",     tZONE,     HOUR( 0) },  /* Universal */
1914     { "utc",    tZONE,     HOUR( 0) },  /* Universal Coordinated */
1915     { "cut",    tZONE,     HOUR( 0) },  /* Coordinated Universal */
1916     { "z",      tZONE,     HOUR( 0) },  /* Greenwich Mean */
1917     { "wet",    tZONE,     HOUR( 0) },  /* Western European */
1918     { "bst",    tDAYZONE,  HOUR( 0) },  /* British Summer */
1919     { "nst",    tZONE,     HOUR(3)+30 }, /* Newfoundland Standard */
1920     { "ndt",    tDAYZONE,  HOUR(3)+30 }, /* Newfoundland Daylight */
1921     { "ast",    tZONE,     HOUR( 4) },  /* Atlantic Standard */
1922     { "adt",    tDAYZONE,  HOUR( 4) },  /* Atlantic Daylight */
1923     { "est",    tZONE,     HOUR( 5) },  /* Eastern Standard */
1924     { "edt",    tDAYZONE,  HOUR( 5) },  /* Eastern Daylight */
1925     { "cst",    tZONE,     HOUR( 6) },  /* Central Standard */
1926     { "cdt",    tDAYZONE,  HOUR( 6) },  /* Central Daylight */
1927     { "mst",    tZONE,     HOUR( 7) },  /* Mountain Standard */
1928     { "mdt",    tDAYZONE,  HOUR( 7) },  /* Mountain Daylight */
1929     { "pst",    tZONE,     HOUR( 8) },  /* Pacific Standard */
1930     { "pdt",    tDAYZONE,  HOUR( 8) },  /* Pacific Daylight */
1931     { "yst",    tZONE,     HOUR( 9) },  /* Yukon Standard */
1932     { "ydt",    tDAYZONE,  HOUR( 9) },  /* Yukon Daylight */
1933     { "akst",   tZONE,     HOUR( 9) },  /* Alaska Standard */
1934     { "akdt",   tDAYZONE,  HOUR( 9) },  /* Alaska Daylight */
1935     { "hst",    tZONE,     HOUR(10) },  /* Hawaii Standard */
1936     { "hast",   tZONE,     HOUR(10) },  /* Hawaii-Aleutian Standard */
1937     { "hadt",   tDAYZONE,  HOUR(10) },  /* Hawaii-Aleutian Daylight */
1938     { "ces",    tDAYZONE,  -HOUR(1) },  /* Central European Summer */
1939     { "cest",   tDAYZONE,  -HOUR(1) },  /* Central European Summer */
1940     { "mez",    tZONE,     -HOUR(1) },  /* Middle European */
1941     { "mezt",   tDAYZONE,  -HOUR(1) },  /* Middle European Summer */
1942     { "cet",    tZONE,     -HOUR(1) },  /* Central European */
1943     { "met",    tZONE,     -HOUR(1) },  /* Middle European */
1944     { "eet",    tZONE,     -HOUR(2) },  /* Eastern Europe */
1945     { "msk",    tZONE,     -HOUR(3) },  /* Moscow Winter */
1946     { "msd",    tDAYZONE,  -HOUR(3) },  /* Moscow Summer */
1947     { "wast",   tZONE,     -HOUR(8) },  /* West Australian Standard */
1948     { "wadt",   tDAYZONE,  -HOUR(8) },  /* West Australian Daylight */
1949     { "hkt",    tZONE,     -HOUR(8) },  /* Hong Kong */
1950     { "cct",    tZONE,     -HOUR(8) },  /* China Coast */
1951     { "jst",    tZONE,     -HOUR(9) },  /* Japan Standard */
1952     { "kst",    tZONE,     -HOUR(9) },  /* Korean Standard */
1953     { "kdt",    tZONE,     -HOUR(9) },  /* Korean Daylight */
1954     { "cast",   tZONE,     -(HOUR(9)+30) }, /* Central Australian Standard */
1955     { "cadt",   tDAYZONE,  -(HOUR(9)+30) }, /* Central Australian Daylight */
1956     { "east",   tZONE,     -HOUR(10) }, /* Eastern Australian Standard */
1957     { "eadt",   tDAYZONE,  -HOUR(10) }, /* Eastern Australian Daylight */
1958     { "nzst",   tZONE,     -HOUR(12) }, /* New Zealand Standard */
1959     { "nzdt",   tDAYZONE,  -HOUR(12) }, /* New Zealand Daylight */
1960
1961     /* For completeness we include the following entries. */
1962 #if 0
1963
1964     /* Duplicate names.  Either they conflict with a zone listed above
1965      * (which is either more likely to be seen or just been in circulation
1966      * longer), or they conflict with another zone in this section and
1967      * we could not reasonably choose one over the other. */
1968     { "fst",    tZONE,     HOUR( 2) },  /* Fernando De Noronha Standard */
1969     { "fdt",    tDAYZONE,  HOUR( 2) },  /* Fernando De Noronha Daylight */
1970     { "bst",    tZONE,     HOUR( 3) },  /* Brazil Standard */
1971     { "est",    tZONE,     HOUR( 3) },  /* Eastern Standard (Brazil) */
1972     { "edt",    tDAYZONE,  HOUR( 3) },  /* Eastern Daylight (Brazil) */
1973     { "wst",    tZONE,     HOUR( 4) },  /* Western Standard (Brazil) */
1974     { "wdt",    tDAYZONE,  HOUR( 4) },  /* Western Daylight (Brazil) */
1975     { "cst",    tZONE,     HOUR( 5) },  /* Chile Standard */
1976     { "cdt",    tDAYZONE,  HOUR( 5) },  /* Chile Daylight */
1977     { "ast",    tZONE,     HOUR( 5) },  /* Acre Standard */
1978     { "adt",    tDAYZONE,  HOUR( 5) },  /* Acre Daylight */
1979     { "cst",    tZONE,     HOUR( 5) },  /* Cuba Standard */
1980     { "cdt",    tDAYZONE,  HOUR( 5) },  /* Cuba Daylight */
1981     { "est",    tZONE,     HOUR( 6) },  /* Easter Island Standard */
1982     { "edt",    tDAYZONE,  HOUR( 6) },  /* Easter Island Daylight */
1983     { "sst",    tZONE,     HOUR(11) },  /* Samoa Standard */
1984     { "ist",    tZONE,     -HOUR(2) },  /* Israel Standard */
1985     { "idt",    tDAYZONE,  -HOUR(2) },  /* Israel Daylight */
1986     { "idt",    tDAYZONE,  -(HOUR(3)+30) }, /* Iran Daylight */
1987     { "ist",    tZONE,     -(HOUR(3)+30) }, /* Iran Standard */
1988     { "cst",     tZONE,     -HOUR(8) }, /* China Standard */
1989     { "cdt",     tDAYZONE,  -HOUR(8) }, /* China Daylight */
1990     { "sst",     tZONE,     -HOUR(8) }, /* Singapore Standard */
1991
1992     /* Dubious (e.g., not in Olson's TIMEZONE package) or obsolete. */
1993     { "gst",    tZONE,     HOUR( 3) },  /* Greenland Standard */
1994     { "wat",    tZONE,     -HOUR(1) },  /* West Africa */
1995     { "at",     tZONE,     HOUR( 2) },  /* Azores */
1996     { "gst",    tZONE,     -HOUR(10) }, /* Guam Standard */
1997     { "nft",    tZONE,     HOUR(3)+30 }, /* Newfoundland */
1998     { "idlw",   tZONE,     HOUR(12) },  /* International Date Line West */
1999     { "mewt",   tZONE,     -HOUR(1) },  /* Middle European Winter */
2000     { "mest",   tDAYZONE,  -HOUR(1) },  /* Middle European Summer */
2001     { "swt",    tZONE,     -HOUR(1) },  /* Swedish Winter */
2002     { "sst",    tDAYZONE,  -HOUR(1) },  /* Swedish Summer */
2003     { "fwt",    tZONE,     -HOUR(1) },  /* French Winter */
2004     { "fst",    tDAYZONE,  -HOUR(1) },  /* French Summer */
2005     { "bt",     tZONE,     -HOUR(3) },  /* Baghdad */
2006     { "it",     tZONE,     -(HOUR(3)+30) }, /* Iran */
2007     { "zp4",    tZONE,     -HOUR(4) },  /* USSR Zone 3 */
2008     { "zp5",    tZONE,     -HOUR(5) },  /* USSR Zone 4 */
2009     { "ist",    tZONE,     -(HOUR(5)+30) }, /* Indian Standard */
2010     { "zp6",    tZONE,     -HOUR(6) },  /* USSR Zone 5 */
2011     { "nst",    tZONE,     -HOUR(7) },  /* North Sumatra */
2012     { "sst",    tZONE,     -HOUR(7) },  /* South Sumatra */
2013     { "jt",     tZONE,     -(HOUR(7)+30) }, /* Java (3pm in Cronusland!) */
2014     { "nzt",    tZONE,     -HOUR(12) }, /* New Zealand */
2015     { "idle",   tZONE,     -HOUR(12) }, /* International Date Line East */
2016     { "cat",    tZONE,     HOUR(10) },  /* -- expired 1967 */
2017     { "nt",     tZONE,     HOUR(11) },  /* -- expired 1967 */
2018     { "ahst",   tZONE,     HOUR(10) },  /* -- expired 1983 */
2019     { "hdt",    tDAYZONE,  HOUR(10) },  /* -- expired 1986 */
2020 #endif /* 0 */
2021 };
2022
2023
2024 /* ARGSUSED */
2025 static void
2026 date_error(char *s)
2027 {
2028     /* NOTREACHED */
2029 }
2030
2031
2032 static time_t
2033 ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian)
2034 {
2035     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 61)
2036         return -1;
2037     if (Meridian == MER24) {
2038         if (Hours < 0 || Hours > 23)
2039             return -1;
2040     }
2041     else {
2042         if (Hours < 1 || Hours > 12)
2043             return -1;
2044         if (Hours == 12)
2045             Hours = 0;
2046         if (Meridian == MERpm)
2047             Hours += 12;
2048     }
2049     return (Hours * 60L + Minutes) * 60L + Seconds;
2050 }
2051
2052
2053 static time_t
2054 Convert(time_t Month, time_t Day, time_t Year,
2055         time_t Hours, time_t Minutes, time_t Seconds,
2056         MERIDIAN Meridian, DSTMODE dst)
2057 {
2058     static int  DaysNormal[13] = {
2059         0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
2060     };
2061     static int  DaysLeap[13] = {
2062         0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
2063     };
2064     static int  LeapYears[] = {
2065         1972, 1976, 1980, 1984, 1988, 1992, 1996,
2066         2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036
2067     };
2068     register int        *yp;
2069     register int        *mp;
2070     register time_t     Julian;
2071     register int        i;
2072     time_t              tod;
2073
2074     if (Year < 0)
2075         Year = -Year;
2076     if (Year < 100)
2077         Year += 1900;
2078     if (Year < EPOCH)
2079         Year += 100;
2080     for (mp = DaysNormal, yp = LeapYears; yp < ENDOF(LeapYears); yp++)
2081         if (Year == *yp) {
2082             mp = DaysLeap;
2083             break;
2084         }
2085     if (Year < EPOCH || Year > END_OF_TIME
2086      || Month < 1 || Month > 12
2087      /* NOSTRICT *//* conversion from long may lose accuracy */
2088      || Day < 1 || Day > mp[(int)Month])
2089         return -1;
2090
2091     Julian = Day - 1 + (Year - EPOCH) * 365;
2092     for (yp = LeapYears; yp < ENDOF(LeapYears); yp++, Julian++)
2093         if (Year <= *yp)
2094             break;
2095     for (i = 1; i < Month; i++)
2096         Julian += *++mp;
2097     Julian *= SECSPERDAY;
2098     Julian += yyTimezone * 60L;
2099     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
2100         return -1;
2101     Julian += tod;
2102     tod = Julian;
2103     if (dst == DSTon || (dst == DSTmaybe && localtime(&tod)->tm_isdst))
2104         Julian -= DST_OFFSET * 60L * 60L;
2105     return Julian;
2106 }
2107
2108
2109 static time_t
2110 DSTcorrect(time_t Start, time_t Future)
2111 {
2112     time_t      StartDay;
2113     time_t      FutureDay;
2114
2115     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
2116     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
2117     return (Future - Start) + (StartDay - FutureDay) * DST_OFFSET * 60L * 60L;
2118 }
2119
2120
2121 static time_t
2122 RelativeMonth(time_t Start, time_t RelMonth)
2123 {
2124     struct tm   *tm;
2125     time_t      Month;
2126     time_t      Year;
2127
2128     tm = localtime(&Start);
2129     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
2130     Year = Month / 12;
2131     Month = Month % 12 + 1;
2132     return DSTcorrect(Start,
2133             Convert(Month, (time_t)tm->tm_mday, Year,
2134                 (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
2135                 MER24, DSTmaybe));
2136 }
2137
2138
2139 static int
2140 LookupWord(char *buff, register int length)
2141 {
2142     register char       *p;
2143     register char       *q;
2144     register TABLE      *tp;
2145     register int        c;
2146
2147     p = buff;
2148     c = p[0];
2149
2150     /* See if we have an abbreviation for a month. */
2151     if (length == 3 || (length == 4 && p[3] == '.'))
2152         for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) {
2153             q = tp->name;
2154             if (c == q[0] && p[1] == q[1] && p[2] == q[2]) {
2155                 yylval.Number = tp->value;
2156                 return tp->type;
2157             }
2158         }
2159     else
2160         for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++)
2161             if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
2162                 yylval.Number = tp->value;
2163                 return tp->type;
2164             }
2165
2166     /* Try for a timezone. */
2167     for (tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
2168         if (c == tp->name[0] && p[1] == tp->name[1]
2169          && strcmp(p, tp->name) == 0) {
2170             yylval.Number = tp->value;
2171             return tp->type;
2172         }
2173
2174     /* Try the units table. */
2175     for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
2176         if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
2177             yylval.Number = tp->value;
2178             return tp->type;
2179         }
2180
2181     /* Strip off any plural and try the units table again. */
2182     if (--length > 0 && p[length] == 's') {
2183         p[length] = '\0';
2184         for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++)
2185             if (c == tp->name[0] && strcmp(p, tp->name) == 0) {
2186                 p[length] = 's';
2187                 yylval.Number = tp->value;
2188                 return tp->type;
2189             }
2190         p[length] = 's';
2191     }
2192     length++;
2193
2194     /* Drop out any periods. */
2195     for (p = buff, q = (char*)buff; *q; q++)
2196         if (*q != '.')
2197             *p++ = *q;
2198     *p = '\0';
2199
2200     /* Try the meridians. */
2201     if (buff[1] == 'm' && buff[2] == '\0') {
2202         if (buff[0] == 'a') {
2203             yylval.Meridian = MERam;
2204             return tMERIDIAN;
2205         }
2206         if (buff[0] == 'p') {
2207             yylval.Meridian = MERpm;
2208             return tMERIDIAN;
2209         }
2210     }
2211
2212     /* If we saw any periods, try the timezones again. */
2213     if (p - buff != length) {
2214         c = buff[0];
2215         for (p = buff, tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++)
2216             if (c == tp->name[0] && p[1] == tp->name[1]
2217             && strcmp(p, tp->name) == 0) {
2218                 yylval.Number = tp->value;
2219                 return tp->type;
2220             }
2221     }
2222
2223     /* Unknown word -- assume GMT timezone. */
2224     yylval.Number = 0;
2225     return tZONE;
2226 }
2227
2228
2229 int
2230 date_lex(void)
2231 {
2232     register char       c;
2233     register char       *p;
2234     char                buff[20];
2235     register int        sign;
2236     register int        i;
2237     register int        nesting;
2238
2239     for ( ; ; ) {
2240         /* Get first character after the whitespace. */
2241         for ( ; ; ) {
2242             while (isspace(*yyInput))
2243                 yyInput++;
2244             c = *yyInput;
2245
2246             /* Ignore RFC 822 comments, typically time zone names. */
2247             if (c != LPAREN)
2248                 break;
2249             for (nesting = 1; (c = *++yyInput) != RPAREN || --nesting; )
2250                 if (c == LPAREN)
2251                     nesting++;
2252                 else if (!IS7BIT(c) || c == '\0' || c == '\r'
2253                      || (c == '\\' && ((c = *++yyInput) == '\0' || !IS7BIT(c))))
2254                     /* Lexical error: bad comment. */
2255                     return '?';
2256             yyInput++;
2257         }
2258
2259         /* A number? */
2260         if (isdigit(c) || c == '-' || c == '+') {
2261             if (c == '-' || c == '+') {
2262                 sign = c == '-' ? -1 : 1;
2263                 yyInput++;
2264                 if (!isdigit(*yyInput))
2265                     /* Skip the plus or minus sign. */
2266                     continue;
2267             }
2268             else
2269                 sign = 0;
2270             for (i = 0; (c = *yyInput++) != '\0' && isdigit(c); )
2271                 i = 10 * i + c - '0';
2272             yyInput--;
2273             yylval.Number = sign < 0 ? -i : i;
2274             return sign ? tSNUMBER : tUNUMBER;
2275         }
2276
2277         /* A word? */
2278         if (isalpha(c)) {
2279             for (p = buff; (c = *yyInput++) == '.' || isalpha(c); )
2280                 if (p < &buff[sizeof buff - 1])
2281                     *p++ = isupper(c) ? tolower(c) : c;
2282             *p = '\0';
2283             yyInput--;
2284             return LookupWord(buff, p - buff);
2285         }
2286
2287         return *yyInput++;
2288     }
2289 }
2290
2291
2292 time_t
2293 parsedate(const char *p)
2294 {
2295     extern int          date_parse(void);
2296     time_t              Start;
2297
2298     yyInput = p; /* well, its supposed to be const... */
2299
2300     yyYear = 0;
2301     yyMonth = 0;
2302     yyDay = 0;
2303     yyTimezone = 0;
2304     yyDSTmode = DSTmaybe;
2305     yyHour = 0;
2306     yyMinutes = 0;
2307     yySeconds = 0;
2308     yyMeridian = MER24;
2309     yyRelSeconds = 0;
2310     yyRelMonth = 0;
2311     yyHaveDate = 0;
2312     yyHaveRel = 0;
2313     yyHaveTime = 0;
2314
2315     if (date_parse() || yyHaveTime > 1 || yyHaveDate > 1)
2316         return -1;
2317
2318     if (yyHaveDate || yyHaveTime) {
2319         Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
2320                     yyMeridian, yyDSTmode);
2321         if (Start < 0)
2322             return -1;
2323     }
2324     else
2325         return -1;
2326
2327     Start += yyRelSeconds;
2328     if (yyRelMonth)
2329         Start += RelativeMonth(Start, yyRelMonth);
2330
2331     /* Have to do *something* with a legitimate -1 so it's distinguishable
2332      * from the error return value.  (Alternately could set errno on error.) */
2333     return Start == -1 ? 0 : Start;
2334 }
2335
2336
2337 #ifdef TEST
2338
2339 #if YYDEBUG
2340 extern int      yydebug;
2341 #endif /* YYDEBUG */
2342
2343 /* ARGSUSED */
2344 int
2345 main(int ac, char *av[])
2346 {
2347     char        buff[128];
2348     time_t      d;
2349
2350 #if YYDEBUG
2351     yydebug = 1;
2352 #endif /* YYDEBUG */
2353
2354     (void)printf("Enter date, or blank line to exit.\n\t> ");
2355     for ( ; ; ) {
2356         (void)printf("\t> ");
2357         (void)fflush(stdout);
2358         if (fgets(buff, sizeof buff, stdin) == NULL || buff[0] == '\n')
2359             break;
2360 #if YYDEBUG
2361         if (strcmp(buff, "yydebug") == 0) {
2362             yydebug = !yydebug;
2363             printf("yydebug = %s\n", yydebug ? "on" : "off");
2364             continue;
2365         }
2366 #endif /* YYDEBUG */
2367         d = parsedate(buff, (TIMEINFO *)NULL);
2368         if (d == -1)
2369             (void)printf("Bad format - couldn't convert.\n");
2370         else
2371             (void)printf("%s", ctime(&d));
2372     }
2373
2374     exit(0);
2375     /* NOTREACHED */
2376 }
2377 #endif /* TEST */