Subject: parsing a file ...

From: Daniel Gross <[email-masked]>
Date: Tue, 7 Mar 2000 09:59:48 -0800

Hi all,

The soution i've come up with in order to parse an atom made out of a comma 
list of items is the following:

It is assumed that after each comma there is a space. e.g. 'one, two, 
three, four''

parseAtoms(Atom,List) :-
        splitAtom(Atom,Atom1,Atom2),
        Atom2 \== '',
        parseAtoms(Atom2,List2),
        append([Atom1],List2,List).

parseAtoms(Atom,[Atom]).

splitAtom(Atom1,Atom2,Atom3) :-
        name(Atom1,List),
        nth1(P,List,44),
        P1 is P - 1,
        P2 is P + 2,
        string_length(List,Length),
        P3 is Length - P2 + 1,
        substring(List,1,P1,Atom2S),
        substring(List,P2,P3,Atom3S),
        string_to_atom(Atom2S,Atom2),
        string_to_atom(Atom3S,Atom3).

an interesting "feature" of the solution is that it produces a set of 
solutions:

parseAtoms('one, two, three', List).

List = [one, two, three] ;

List = [one, 'two, three'] ;

List = ['one, two', three] ;

List = ['one, two, three'] ;

Its quite a "brute force" way -- to convert the atom to a string and search 
for comma occurences, but i havent' seen a different approach to parse 
atoms. This parsing is used as the basis for parsing such comma lists in 
the text file of "frames" mentioned in the previous posting, into prolog 
facts.

commens are naturally appreciated

Daniel

ps. Is there a way to compose an input stream of characters into facts of 
words, phrases and sentences (i.e. a grammar represented as facts of list 
items ).