2 * dates.lex: An example of using start states to
3 * distinguish between different date formats.
9 char month[20],dow[20],day[20],year[20];
23 day_of_the_week ({mon}|{tue}|{wed}|{thu}|{fri}|{sat}|{sun})
38 first_half ({jan}|{feb}|{mar}|{apr}|{may}|{jun})
39 second_half ({jul}|{aug}|{sep}|{oct}|{nov}|{dec})
40 month {first_half}|{second_half}
42 nday [1-9]|[1-2][0-9]|3[0-1]
46 year_ext (ad|AD|bc|BC)?
47 day_ext (st|nd|rd|th)?
50 %s DAY DAY_FIRST YEAR_FIRST YEAR_LAST YFMONTH YLMONTH
54 /* the default is month-day-year */
56 <LONG>{day_of_the_week} strcpy(dow,yytext);
57 <LONG>{month} strcpy(month,yytext); BEGIN(DAY);
59 /* handle the form: day-month-year */
61 <LONG>{nday}{day_ext} strcpy(day,yytext); BEGIN(DAY_FIRST);
62 <DAY_FIRST>{month} strcpy(month,yytext); BEGIN(LONG);
63 <DAY>{nday}{day_ext} strcpy(day,yytext); BEGIN(LONG);
65 <LONG>{nyear}{year_ext} {
67 printf(" DOW : %s \n",dow);
68 printf(" Day : %s \n",day);
69 printf(" Month : %s \n",month);
70 printf(" Year : %s \n",yytext);
76 /* handle dates of the form: day-month-year */
78 <SHORT>{nday} strcpy(day,yytext); BEGIN(YEAR_LAST);
79 <YEAR_LAST>{nmonth} strcpy(month,yytext);BEGIN(YLMONTH);
80 <YLMONTH>{nyear} strcpy(year,yytext); BEGIN(SHORT);
82 /* handle dates of the form: year-month-day */
84 <SHORT>{nyear} strcpy(year,yytext); BEGIN(YEAR_FIRST);
85 <YEAR_FIRST>{nmonth} strcpy(month,yytext);BEGIN(YFMONTH);
86 <YFMONTH>{nday} strcpy(day,yytext); BEGIN(SHORT);
91 printf(" Day : %s \n",day);
92 printf(" Month : %s \n",month);
93 printf(" Year : %s \n",year);
100 short\n BEGIN(SHORT);