Re: help with parsing and dcg (swi-prolog in particular)




Brian Hulley wrote:
> blindsearch wrote:
> > For a recent project, I was reading in lisp like files,
> > (concept-name (concept-attribute (type stuff))
> > (...)
> > ...
> > ...)
> >
> > I converted the lisp lists to prolog lists wrapped in a predicate
and
> > wrote them to a temp file, then [consult]ed the temp file but
> > I had to make uppercase to lowercase, hypens to underscore, etc. I
> had
> > to keep track of tokens/words so i could place commas, also counted
> the
> > parens so when i got back to zero, I placed a period.
> > The parser read in the file char by char and wrote char by char.
> >
> > I was wondering about using DCG to parse the file. I've read that
> DCG's
> > are excellent for parsing (and written some small examples for
> > sentences) but it doesn't seem feasible to me.
> >
> > Is there a way to take a file and use dcg to parse it?
> > The only way I can think of is that I would have to convert the
file
> to
> > lists and pass the lists to the dcg predicates tokenising stuff in
> the
> > progress. But if I did that, I've done almost all the parser
without
> > dcg bymyself.
> >
> > Any help would be welcome.
>
> If you write one DCG that parses a whole file then all you need is a
> predicate that converts a file to one list of characters - perhaps
> something like:
>
> convert_file_to_list(File,[Char|L]) :-

Apologies for the error- should be:

convert_file_to_list(File,L) :-

.



Relevant Pages

  • Re: How to get the terms of a compund term (predicate: simplfy)?
    ... atom by atom and if it is a number put it ... The only DCG related chapter in my ... It seems to make the task of dividing lists to ... results of my categorization function". ...
    (comp.lang.prolog)
  • Re: Prolog newbie stuck at Monkey World (lists, adding, etc.)
    ... recommend to stick to conventional predicate notation until you have ... mastered the basics and understand difference lists. ... out DCG notation. ... why his predicate (where he inserted new moves at the beginning of the ...
    (comp.lang.prolog)
  • Re: help with parsing and dcg (swi-prolog in particular)
    ... > I converted the lisp lists to prolog lists wrapped in a predicate and ... > The parser read in the file char by char and wrote char by char. ... > I was wondering about using DCG to parse the file. ...
    (comp.lang.prolog)
  • Re: DCG Parser Help
    ... And here's a tutorial on using DCG: ... Im in need of some advice regarding DGC Parsers. ... > code the basic parser and test it by manually entering lists. ... > that keyword as a trigger. ...
    (comp.lang.prolog)
  • help with parsing and dcg (swi-prolog in particular)
    ... I converted the lisp lists to prolog lists wrapped in a predicate and ... The parser read in the file char by char and wrote char by char. ... I was wondering about using DCG to parse the file. ...
    (comp.lang.prolog)