Date Parser 
Author Message
 Date Parser

Hi everyone,

I have to write a parser that can parse phrases representing a date and
time.

 If the input phrase can be correctly parsed (by this I mean it is a legal
sentence in the date-time grammar) a structure that contains a standardised
format for the date and time should be generated.

This standard format is:

datetime(Day,Month,Year,Hours,Minutes,Seconds).

An example is 10:42:32 PM July 10 2001 which would be represented as:

datetime(10,7,2001,22,42,32)

Date components can be seperated by the '/' atom for numeric dates (eg
10/7/2001), and the ',' atom can be used to seperate the year from the day
and month information (see examples below).

The time can take the following forms:

10:42:32 PM
22:42:32                                                    (Times with no
AM/PM indicator are assumed 24hour)

Times that do not include the number of seconds must also be accepted - in
this case the output for the seconds will be 0.

Time variables are seperated only by the ':' atom.

I think i know what to do, I just don't know how to do it! I want to write a
predicate that will take the input string and change it into a list of
tokens. I was going to use name/2 to turn the initial list into ascii codes.
After that, use recursion to pick the head off the list, check if it is a
delimiter character (like ',' or space) then put the ascii codes into lists
for each token inside a larger list. After that I have no clue! Do you think
I have the right idea??

Any help would be much appreciated,

thanks!

Rachel Wilson



Sat, 22 May 2004 08:28:03 GMT  
 Date Parser

Quote:

> I have to write a parser that can parse phrases representing a date and
> time. [...]
> datetime(Day,Month,Year,Hours,Minutes,Seconds).

> An example is 10:42:32 PM July 10 2001 which would be represented as:
> datetime(10,7,2001,22,42,32)
> [...]
> I think i know what to do, I just don't know how to do it! I want to write a
> predicate that will take the input string and change it into a list of
> tokens. I was going to use name/2 to turn the initial list into ascii codes.
> After that, use recursion to pick the head off the list, check if it is a
> delimiter character (like ',' or space) then put the ascii codes into lists
> for each token inside a larger list. After that I have no clue! Do you think
> I have the right idea??

Sounds good. What you have started to describe is the
tokenizer. That's step one and should return something like (for you
example):

[num(10),colon,num(42),colon,num(32),str("PM"),str("July"),num(10),num(2001)]

Then you need a little DCG:

| dt(DT) -->
|   time(Hrs,Min,Sec),
|   date(Day,Month,Year),
|   { DT = datetime(Day,Month,Year,Hrs,Min,Sec) }.
|
| time(Hrs,Min,Sec) -->
|   [num(Hrs),colon,num(Min),colon,num(Sec)].
|
| date(Day,Month,Year) -->
|   [str(Month),num(Day),num(Year)].

Plus you have to convert to 24 hour format etc.

/Tomas



Sat, 22 May 2004 11:38:33 GMT  
 Date Parser
Hey thanks a lot! I havent had time to work on it just yet but im gonna take
a look tonite. im still trying to do the tokeniser....

Quote:


> > I have to write a parser that can parse phrases representing a date and
> > time. [...]
> > datetime(Day,Month,Year,Hours,Minutes,Seconds).

> > An example is 10:42:32 PM July 10 2001 which would be represented as:
> > datetime(10,7,2001,22,42,32)
> > [...]
> > I think i know what to do, I just don't know how to do it! I want to
write a
> > predicate that will take the input string and change it into a list of
> > tokens. I was going to use name/2 to turn the initial list into ascii
codes.
> > After that, use recursion to pick the head off the list, check if it is
a
> > delimiter character (like ',' or space) then put the ascii codes into
lists
> > for each token inside a larger list. After that I have no clue! Do you
think
> > I have the right idea??

> Sounds good. What you have started to describe is the
> tokenizer. That's step one and should return something like (for you
> example):

[num(10),colon,num(42),colon,num(32),str("PM"),str("July"),num(10),num(2001)
]

- Show quoted text -

Quote:

> Then you need a little DCG:

> | dt(DT) -->
> |   time(Hrs,Min,Sec),
> |   date(Day,Month,Year),
> |   { DT = datetime(Day,Month,Year,Hrs,Min,Sec) }.
> |
> | time(Hrs,Min,Sec) -->
> |   [num(Hrs),colon,num(Min),colon,num(Sec)].
> |
> | date(Day,Month,Year) -->
> |   [str(Month),num(Day),num(Year)].

> Plus you have to convert to 24 hour format etc.

> /Tomas



Sat, 22 May 2004 23:45:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Date Parser - Again!

2. Date Parser Tokeniser

3. date parser

4. New SIOD update, with -*-parser:fasl-*- and -*-parser:read-*-

5. New SIOD update, with -*-parser:fasl-*- and -*-parser:read-*-

6. Invalid dates - 215 using Btrieve/Clipper DATE format

7. how to convert clarion date to sql date

8. Create Time / date or Modified Time / date of a txt file

9. Clarion date to MS SQL date.

10. Dataflex dates to Clarion dates

11. CW2.003 File copy changes the date.....need a way to copy w/o date change

 

 
Powered by phpBB® Forum Software