3131
3232#include " attr.h"
3333#include " getdate.h"
34- #include " string/strcmp/streq.h"
3534#include " string/strspn/stpspn.h"
3635
3736
@@ -123,11 +122,8 @@ static int yyYear;
123122 int Number;
124123}
125124
126- %token tID
127- %token tMONTH
128125%token tSNUMBER tUNUMBER
129126
130- %type <Number> tMONTH
131127%type <Number> tSNUMBER tUNUMBER
132128
133129%%
@@ -142,58 +138,12 @@ item : date {
142138 | number
143139 ;
144140
145- date : tUNUMBER ' /' tUNUMBER {
146- yyMonth = $1 ;
147- yyDay = $3 ;
148- }
149- | tUNUMBER ' /' tUNUMBER ' /' tUNUMBER {
150- /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
151- The goal in recognizing YYYY/MM/DD is solely to support legacy
152- machine-generated dates like those in an RCS log listing. If
153- you want portability, use the ISO 8601 format. */
154- if ($1 >= 1000 )
155- {
156- yyYear = $1 ;
157- yyMonth = $3 ;
158- yyDay = $5 ;
159- }
160- else
161- {
162- yyMonth = $1 ;
163- yyDay = $3 ;
164- yyYear = $5 ;
165- }
166- }
167- | tUNUMBER tSNUMBER tSNUMBER {
141+ date : tUNUMBER tSNUMBER tSNUMBER {
168142 /* ISO 8601 format. yyyy-mm-dd. */
169143 yyYear = $1 ;
170144 yyMonth = -$2 ;
171145 yyDay = -$3 ;
172146 }
173- | tUNUMBER tMONTH tSNUMBER {
174- /* e.g. 17-JUN-1992. */
175- yyDay = $1 ;
176- yyMonth = $2 ;
177- yyYear = -$3 ;
178- }
179- | tMONTH tUNUMBER {
180- yyMonth = $1 ;
181- yyDay = $2 ;
182- }
183- | tMONTH tUNUMBER ' ,' tUNUMBER {
184- yyMonth = $1 ;
185- yyDay = $2 ;
186- yyYear = $4 ;
187- }
188- | tUNUMBER tMONTH {
189- yyMonth = $2 ;
190- yyDay = $1 ;
191- }
192- | tUNUMBER tMONTH tUNUMBER {
193- yyMonth = $2 ;
194- yyDay = $1 ;
195- yyYear = $3 ;
196- }
197147 ;
198148
199149number : tUNUMBER
@@ -207,24 +157,6 @@ number : tUNUMBER
207157
208158%%
209159
210- /* Month table. */
211- static TABLE const MonthTable[] = {
212- { " january" , tMONTH, 1 },
213- { " february" , tMONTH, 2 },
214- { " march" , tMONTH, 3 },
215- { " april" , tMONTH, 4 },
216- { " may" , tMONTH, 5 },
217- { " june" , tMONTH, 6 },
218- { " july" , tMONTH, 7 },
219- { " august" , tMONTH, 8 },
220- { " september" , tMONTH, 9 },
221- { " sept" , tMONTH, 9 },
222- { " october" , tMONTH, 10 },
223- { " november" , tMONTH, 11 },
224- { " december" , tMONTH, 12 },
225- { NULL , 0 , 0 }
226- };
227-
228160
229161
230162
@@ -248,48 +180,6 @@ static int ToYear (int Year)
248180 return Year;
249181}
250182
251- static int LookupWord (char *buff)
252- {
253- register char *p;
254- register const TABLE *tp;
255- bool abbrev;
256-
257- /* Make it lowercase. */
258- for (p = buff; !streq (p, " " ); p++)
259- if (isupper (*p))
260- *p = tolower (*p);
261-
262- /* See if we have an abbreviation for a month. */
263- if (strlen (buff) == 3 )
264- abbrev = true ;
265- else if (strlen (buff) == 4 && buff[3 ] == ' .' )
266- {
267- abbrev = true ;
268- stpcpy (&buff[3 ], " " );
269- }
270- else
271- abbrev = false ;
272-
273- for (tp = MonthTable; tp->name ; tp++)
274- {
275- if (abbrev)
276- {
277- if (strncmp (buff, tp->name , 3 ) == 0 )
278- {
279- yylval.Number = tp->value ;
280- return tp->type ;
281- }
282- }
283- else if (streq (buff, tp->name ))
284- {
285- yylval.Number = tp->value ;
286- return tp->type ;
287- }
288- }
289-
290- return tID;
291- }
292-
293183static int
294184yylex (void )
295185{
@@ -321,15 +211,6 @@ yylex (void)
321211 yylval.Number = -yylval.Number ;
322212 return (0 != sign) ? tSNUMBER : tUNUMBER;
323213 }
324- if (isalpha (c))
325- {
326- for (p = buff; (c = *yyInput++, isalpha (c)) || c == ' .' ;)
327- if (p < &buff[sizeof buff - 1 ])
328- *p++ = c;
329- stpcpy (p, " " );
330- yyInput--;
331- return LookupWord (buff);
332- }
333214 if (c != ' (' )
334215 return *yyInput++;
335216 Count = 0 ;
0 commit comments