2 /* A Bison parser, made from ./posixtm.y with Bison version GNU Bison version 1.22
5 #define YYBISON 1 /* Identify Bison output. */
16 /* The following block of alloca-related preprocessor directives is here
17 solely to allow compilation by non GNU-C compilers of the C parser
18 produced from this file by old versions of bison. Newer versions of
19 bison include a block similar to this one in bison.simple. */
22 #define alloca __builtin_alloca
36 #include <sys/types.h>
44 /* Some old versions of bison generate parsers that use bcopy.
45 That loses on systems that don't provide the function, so we have
46 to redefine it here. */
47 #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
48 #define bcopy(from, to, len) memcpy ((to), (from), (len))
53 /* Lexical analyzer's current scan position in the input string. */
56 /* The return value. */
61 #define zzparse posixtime_zzparse
63 static int zzerror ();
78 #define YYLTYPE zzltype
98 #define YYTRANSLATE(x) ((unsigned)(x) <= 258 ? zztranslate[x] : 9)
100 static const char zztranslate
[] = { 0,
101 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
102 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
103 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
104 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
105 2, 2, 2, 2, 2, 4, 2, 2, 2, 2,
106 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
107 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
108 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
109 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
110 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
111 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
112 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
113 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
114 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
115 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
116 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
117 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
118 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
119 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
120 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
121 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
122 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
123 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
124 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
125 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
126 2, 2, 2, 2, 2, 1, 2, 3
130 static const short zzprhs
[] = { 0,
131 0, 7, 9, 12, 13, 14, 17
134 static const short zzrhs
[] = { 8,
135 8, 8, 8, 6, 7, 0, 8, 0, 8, 8,
136 0, 0, 0, 4, 8, 0, 3, 3, 0
142 static const short zzrline
[] = { 0,
143 78, 107, 114, 121, 132, 135, 144
146 static const char * const zztname
[] = { "$","error","$illegal.","DIGIT","'.'",
147 "date","year","seconds","digitpair",""
151 static const short zzr1
[] = { 0,
155 static const short zzr2
[] = { 0,
159 static const short zzdefact
[] = { 0,
160 0, 0, 7, 0, 0, 4, 5, 2, 0, 1,
164 static const short zzdefgoto
[] = { 13,
168 static const short zzpact
[] = { 2,
169 5, 2,-32768, 2, 2, 2, -3, 2, 2,-32768,
170 -32768,-32768, 9, 10,-32768
173 static const short zzpgoto
[] = {-32768,
181 static const short zztable
[] = { 4,
182 9, 5, 6, 8, 1, 11, 12, 3, 14, 15
185 static const short zzcheck
[] = { 2,
186 4, 4, 5, 6, 3, 8, 9, 3, 0, 0
188 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
189 #line 3 "/usr/local/lib/bison.simple"
191 /* Skeleton output parser for bison,
192 Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
194 This program is free software; you can redistribute it and/or modify
195 it under the terms of the GNU General Public License as published by
196 the Free Software Foundation; either version 1, or (at your option)
199 This program is distributed in the hope that it will be useful,
200 but WITHOUT ANY WARRANTY; without even the implied warranty of
201 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
202 GNU General Public License for more details.
204 You should have received a copy of the GNU General Public License
205 along with this program; if not, write to the Free Software
206 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
211 #define alloca __builtin_alloca
212 #else /* not GNU C. */
213 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
215 #else /* not sparc */
216 #if defined (MSDOS) && !defined (__TURBOC__)
218 #else /* not MSDOS, or __TURBOC__ */
222 #else /* not MSDOS, __TURBOC__, or _AIX */
226 void *alloca (unsigned int);
228 #else /* not __cplusplus */
230 #endif /* not __cplusplus */
232 #endif /* not _AIX */
233 #endif /* not MSDOS, or __TURBOC__ */
234 #endif /* not sparc. */
235 #endif /* not GNU C. */
236 #endif /* alloca not defined. */
238 /* This is the parser code that is written into each bison parser
239 when the %semantic_parser declaration is not specified in the grammar.
240 It was written by Richard Stallman by simplifying the hairy parser
241 used when %semantic_parser is specified. */
243 /* Note: there must be only one dollar sign in this file.
244 It is replaced by the list of actions, each action
245 as one case of the switch. */
247 #define zzerrok (zzerrstatus = 0)
248 #define zzclearin (zzchar = YYEMPTY)
251 #define YYACCEPT return(0)
252 #define YYABORT return(1)
253 #define YYERROR goto zzerrlab1
254 /* Like YYERROR except do call zzerror.
255 This remains here temporarily to ease the
256 transition to the new meaning of YYERROR, for GCC.
257 Once GCC version 2 has supplanted version 1, this can go. */
258 #define YYFAIL goto zzerrlab
259 #define YYRECOVERING() (!!zzerrstatus)
260 #define YYBACKUP(token, value) \
262 if (zzchar == YYEMPTY && zzlen == 1) \
263 { zzchar = (token), zzlval = (value); \
264 zzchar1 = YYTRANSLATE (zzchar); \
269 { zzerror ("syntax error: cannot back up"); YYERROR; } \
273 #define YYERRCODE 256
276 #define YYLEX zzlex()
281 #define YYLEX zzlex(&zzlval, &zzlloc)
283 #define YYLEX zzlex(&zzlval)
287 /* If nonreentrant, generate the variables here */
291 int zzchar
; /* the lookahead symbol */
292 YYSTYPE zzlval
; /* the semantic value of the */
293 /* lookahead symbol */
296 YYLTYPE zzlloc
; /* location data for the lookahead */
300 int zznerrs
; /* number of parse errors so far */
301 #endif /* not YYPURE */
304 int zzdebug
; /* nonzero means print parse trace */
305 /* Since this is uninitialized, it does not stop multiple parsers
309 /* YYINITDEPTH indicates the initial size of the parser's stacks */
312 #define YYINITDEPTH 200
315 /* YYMAXDEPTH is the maximum size the stacks can grow to
316 (effective only if the built-in stack extension method is used). */
323 #define YYMAXDEPTH 10000
326 /* Prevent warning if -Wstrict-prototypes. */
331 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
332 #define __zz_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
333 #else /* not GNU C or C++ */
336 /* This is the most reliable way to avoid incompatibilities
337 in available built-in functions on various systems. */
339 __zz_bcopy (from
, to
, count
)
344 register char *f
= from
;
345 register char *t
= to
;
346 register int i
= count
;
352 #else /* __cplusplus */
354 /* This is the most reliable way to avoid incompatibilities
355 in available built-in functions on various systems. */
357 __zz_bcopy (char *from
, char *to
, int count
)
359 register char *f
= from
;
360 register char *t
= to
;
361 register int i
= count
;
370 #line 184 "/usr/local/lib/bison.simple"
374 register int zzstate
;
376 register short *zzssp
;
377 register YYSTYPE
*zzvsp
;
378 int zzerrstatus
; /* number of tokens to shift before error messages enabled */
379 int zzchar1
= 0; /* lookahead token as an internal (translated) token number */
381 short zzssa
[YYINITDEPTH
]; /* the state stack */
382 YYSTYPE zzvsa
[YYINITDEPTH
]; /* the semantic value stack */
384 short *zzss
= zzssa
; /* refer to the stacks thru separate pointers */
385 YYSTYPE
*zzvs
= zzvsa
; /* to allow zzoverflow to reallocate them elsewhere */
388 YYLTYPE zzlsa
[YYINITDEPTH
]; /* the location stack */
389 YYLTYPE
*zzls
= zzlsa
;
392 #define YYPOPSTACK (zzvsp--, zzssp--, zzlsp--)
394 #define YYPOPSTACK (zzvsp--, zzssp--)
397 int zzstacksize
= YYINITDEPTH
;
408 YYSTYPE zzval
; /* the variable used to return */
409 /* semantic values from the action */
416 fprintf(stderr
, "Starting parse\n");
422 zzchar
= YYEMPTY
; /* Cause a token to be read. */
424 /* Initialize stack pointers.
425 Waste one element of value and location stack
426 so that they stay on the same level as the state stack.
427 The wasted elements are never initialized. */
435 /* Push a new state, which is found in zzstate . */
436 /* In all cases, when you get here, the value and location stacks
437 have just been pushed. so pushing a state here evens the stacks. */
442 if (zzssp
>= zzss
+ zzstacksize
- 1)
444 /* Give user a chance to reallocate the stack */
445 /* Use copies of these so that the &'s don't force the real ones into memory. */
446 YYSTYPE
*zzvs1
= zzvs
;
449 YYLTYPE
*zzls1
= zzls
;
452 /* Get the current used size of the three stacks, in elements. */
453 int size
= zzssp
- zzss
+ 1;
456 /* Each stack pointer address is followed by the size of
457 the data in use in that stack, in bytes. */
459 /* This used to be a conditional around just the two extra args,
460 but that might be undefined if zzoverflow is a macro. */
461 zzoverflow("parser stack overflow",
462 &zzss1
, size
* sizeof (*zzssp
),
463 &zzvs1
, size
* sizeof (*zzvsp
),
464 &zzls1
, size
* sizeof (*zzlsp
),
467 zzoverflow("parser stack overflow",
468 &zzss1
, size
* sizeof (*zzssp
),
469 &zzvs1
, size
* sizeof (*zzvsp
),
473 zzss
= zzss1
; zzvs
= zzvs1
;
477 #else /* no zzoverflow */
478 /* Extend the stack our own way. */
479 if (zzstacksize
>= YYMAXDEPTH
)
481 zzerror("parser stack overflow");
485 if (zzstacksize
> YYMAXDEPTH
)
486 zzstacksize
= YYMAXDEPTH
;
487 zzss
= (short *) alloca (zzstacksize
* sizeof (*zzssp
));
488 __zz_bcopy ((char *)zzss1
, (char *)zzss
, size
* sizeof (*zzssp
));
489 zzvs
= (YYSTYPE
*) alloca (zzstacksize
* sizeof (*zzvsp
));
490 __zz_bcopy ((char *)zzvs1
, (char *)zzvs
, size
* sizeof (*zzvsp
));
492 zzls
= (YYLTYPE
*) alloca (zzstacksize
* sizeof (*zzlsp
));
493 __zz_bcopy ((char *)zzls1
, (char *)zzls
, size
* sizeof (*zzlsp
));
495 #endif /* no zzoverflow */
497 zzssp
= zzss
+ size
- 1;
498 zzvsp
= zzvs
+ size
- 1;
500 zzlsp
= zzls
+ size
- 1;
505 fprintf(stderr
, "Stack size increased to %d\n", zzstacksize
);
508 if (zzssp
>= zzss
+ zzstacksize
- 1)
514 fprintf(stderr
, "Entering state %d\n", zzstate
);
520 /* Do appropriate processing given the current state. */
521 /* Read a lookahead token if we need one and don't already have one. */
524 /* First try to decide what to do without reference to lookahead token. */
526 zzn
= zzpact
[zzstate
];
530 /* Not known => get a lookahead token if don't already have one. */
532 /* zzchar is either YYEMPTY or YYEOF
533 or a valid token in external form. */
535 if (zzchar
== YYEMPTY
)
539 fprintf(stderr
, "Reading a token: ");
544 /* Convert token to internal form (in zzchar1) for indexing tables with */
546 if (zzchar
<= 0) /* This means end of input. */
549 zzchar
= YYEOF
; /* Don't call YYLEX any more */
553 fprintf(stderr
, "Now at end of input.\n");
558 zzchar1
= YYTRANSLATE(zzchar
);
563 fprintf (stderr
, "Next token is %d (%s", zzchar
, zztname
[zzchar1
]);
564 /* Give the individual parser a way to print the precise meaning
565 of a token, for further debugging info. */
567 YYPRINT (stderr
, zzchar
, zzlval
);
569 fprintf (stderr
, ")\n");
575 if (zzn
< 0 || zzn
> YYLAST
|| zzcheck
[zzn
] != zzchar1
)
580 /* zzn is what to do for this token type in this state.
581 Negative => reduce, -zzn is rule number.
582 Positive => shift, zzn is new state.
583 New state is final state => don't bother to shift,
585 0, or most negative number => error. */
600 /* Shift the lookahead token. */
604 fprintf(stderr
, "Shifting token %d (%s), ", zzchar
, zztname
[zzchar1
]);
607 /* Discard the token being shifted unless it is eof. */
616 /* count tokens shifted since error; after three, turn off error status. */
617 if (zzerrstatus
) zzerrstatus
--;
622 /* Do the default action for the current state. */
625 zzn
= zzdefact
[zzstate
];
629 /* Do a reduction. zzn is the number of a rule to reduce with. */
633 zzval
= zzvsp
[1-zzlen
]; /* implement default value of the action */
640 fprintf (stderr
, "Reducing via rule %d (line %d), ",
643 /* Print the symbols being reduced, and their result. */
644 for (i
= zzprhs
[zzn
]; zzrhs
[i
] > 0; i
++)
645 fprintf (stderr
, "%s ", zztname
[zzrhs
[i
]]);
646 fprintf (stderr
, " -> %s\n", zztname
[zzr1
[zzn
]]);
654 #line 84 "./posixtm.y"
656 if (zzvsp
[-5] >= 1 && zzvsp
[-5] <= 12)
657 t
.tm_mon
= zzvsp
[-5] - 1;
661 if (zzvsp
[-4] >= 1 && zzvsp
[-4] <= 31)
662 t
.tm_mday
= zzvsp
[-4];
666 if (zzvsp
[-3] >= 0 && zzvsp
[-3] <= 23)
667 t
.tm_hour
= zzvsp
[-3];
671 if (zzvsp
[-2] >= 0 && zzvsp
[-2] <= 59)
672 t
.tm_min
= zzvsp
[-2];
679 #line 107 "./posixtm.y"
681 t
.tm_year
= zzvsp
[0];
682 /* Deduce the century based on the year.
683 See POSIX.2 section 4.63.3. */
689 #line 114 "./posixtm.y"
691 t
.tm_year
= zzvsp
[-1] * 100 + zzvsp
[0];
692 if (t
.tm_year
< 1900) {
699 #line 121 "./posixtm.y"
704 /* Use current year. */
706 tmp
= localtime (&now
);
707 t
.tm_year
= tmp
->tm_year
;
711 #line 132 "./posixtm.y"
717 #line 135 "./posixtm.y"
719 if (zzvsp
[0] >= 0 && zzvsp
[0] <= 61)
727 #line 144 "./posixtm.y"
729 zzval
= zzvsp
[-1] * 10 + zzvsp
[0];
733 /* the action file gets copied in in place of this dollarsign */
734 #line 465 "/usr/local/lib/bison.simple"
745 short *ssp1
= zzss
- 1;
746 fprintf (stderr
, "state stack now");
747 while (ssp1
!= zzssp
)
748 fprintf (stderr
, " %d", *++ssp1
);
749 fprintf (stderr
, "\n");
759 zzlsp
->first_line
= zzlloc
.first_line
;
760 zzlsp
->first_column
= zzlloc
.first_column
;
761 zzlsp
->last_line
= (zzlsp
-1)->last_line
;
762 zzlsp
->last_column
= (zzlsp
-1)->last_column
;
767 zzlsp
->last_line
= (zzlsp
+zzlen
-1)->last_line
;
768 zzlsp
->last_column
= (zzlsp
+zzlen
-1)->last_column
;
772 /* Now "shift" the result of the reduction.
773 Determine what state that goes to,
774 based on the state we popped back to
775 and the rule number reduced by. */
779 zzstate
= zzpgoto
[zzn
- YYNTBASE
] + *zzssp
;
780 if (zzstate
>= 0 && zzstate
<= YYLAST
&& zzcheck
[zzstate
] == *zzssp
)
781 zzstate
= zztable
[zzstate
];
783 zzstate
= zzdefgoto
[zzn
- YYNTBASE
];
787 zzerrlab
: /* here on detecting error */
790 /* If not already recovering from an error, report this error. */
794 #ifdef YYERROR_VERBOSE
795 zzn
= zzpact
[zzstate
];
797 if (zzn
> YYFLAG
&& zzn
< YYLAST
)
804 /* Start X at -zzn if nec to avoid negative indexes in zzcheck. */
805 for (x
= (zzn
< 0 ? -zzn
: 0);
806 x
< (sizeof(zztname
) / sizeof(char *)); x
++)
807 if (zzcheck
[x
+ zzn
] == x
)
808 size
+= strlen(zztname
[x
]) + 15, count
++;
809 msg
= (char *) malloc(size
+ 15);
812 strcpy(msg
, "parse error");
817 for (x
= (zzn
< 0 ? -zzn
: 0);
818 x
< (sizeof(zztname
) / sizeof(char *)); x
++)
819 if (zzcheck
[x
+ zzn
] == x
)
821 strcat(msg
, count
== 0 ? ", expecting `" : " or `");
822 strcat(msg
, zztname
[x
]);
831 zzerror ("parse error; also virtual memory exceeded");
834 #endif /* YYERROR_VERBOSE */
835 zzerror("parse error");
839 zzerrlab1
: /* here on error raised explicitly by an action */
841 if (zzerrstatus
== 3)
843 /* if just tried and failed to reuse lookahead token after an error, discard it. */
845 /* return failure if at end of input */
851 fprintf(stderr
, "Discarding token %d (%s).\n", zzchar
, zztname
[zzchar1
]);
857 /* Else will try to reuse lookahead token
858 after shifting the error token. */
860 zzerrstatus
= 3; /* Each real token shifted decrements this */
864 zzerrdefault
: /* current state does not do anything special for the error token. */
867 /* This is wrong; only states that explicitly want error tokens
868 should shift them. */
869 zzn
= zzdefact
[zzstate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
870 if (zzn
) goto zzdefault
;
873 zzerrpop
: /* pop the current state because it cannot handle the error token */
875 if (zzssp
== zzss
) YYABORT
;
885 short *ssp1
= zzss
- 1;
886 fprintf (stderr
, "Error: state stack now");
887 while (ssp1
!= zzssp
)
888 fprintf (stderr
, " %d", *++ssp1
);
889 fprintf (stderr
, "\n");
895 zzn
= zzpact
[zzstate
];
900 if (zzn
< 0 || zzn
> YYLAST
|| zzcheck
[zzn
] != YYTERROR
)
919 fprintf(stderr
, "Shifting error token, ");
930 #line 148 "./posixtm.y"
937 if (ch
>= '0' && ch
<= '9')
942 else if (ch
== '.' || ch
== 0)
945 return '?'; /* Cause an error. */
954 /* Parse a POSIX-style date and return it, or (time_t)-1 for an error. */
961 /* Let mktime decide whether it is daylight savings time. */
969 /* Parse a POSIX-style date and return it, or NULL for an error. */
975 if (posixtime (s
) == -1)