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



Brian Hulley wrote:
> blindsearch wrote:
> > I don't think a single list could handle it. The file I was reading
> in
> > was 2.5mb, there were 8199 frames.
>

You could also modify the convert_file_to_list predicate so that it
counted parentheses - when the opening bracket is closed, you stop
reading from the file and return the list which should contain the
chars for a single concept (assuming the original file is bracketed
correctly, which from your first post seemed to be the case)

Thus your main loop would be something like:

go :-
see(File),
get_byte(Char),
start_with(Char).

start_with(-1) :- seen. % end of file
start_with(Char) :-
get_next_concept_list(Char,List,NextChar),
phrase(concept(Concept), List, Remainder), % ignore remainder (?)
write(Concept),nl,
start_with(NextChar).

Garbage collection will ensure that you don't run out of space in this
kind of loop (using tail recursion).

Regards, Brian.

.



Relevant Pages

  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Problem with a script
    ... Okay, so variables have unique labels, that doesn't mean they still couldn't be handled in a loop. ... You still have them as uniquely named array indexes... ... I believe that for the new guy this code would be readable, and identifying problems should really not be any more difficult with this, plus I think that it actually might save some time to write the actual code from the beginnig, even though it's not at it's final stage, instead of first writing everything spread out, and then rewriting the same code again cleaned. ... If you expect a person to spend an hour reading your entire code and parsing it in their head, you wont get any help and have to solve the problem by yourself. ...
    (comp.lang.php)
  • Re: advice and/or help on glReadPixels
    ... I could not see any "BRGA" in the documentation. ... Is it possible that some cards are not ... >>> a) Try reading the entire RGB instead of just the red. ... a quick integer loop with a mask & shift is ...
    (comp.graphics.api.opengl)
  • Re: while (1) vs. for ( ;; )
    ... >to write to the next guy who will be reading the code. ... You are unfamiliar with the term "infinite loop"? ... Balmer Consulting ...
    (comp.lang.c)
  • Re: Reading from file up to arbitrary byte.
    ... > fact that you're reading all the data and throwing some away. ... I wanted to avoid keeping a remainder as I would have thought the ... underlying implementation would have to do this anyway when doing ... the Python 2.3 CSV module, and a C implementation of a CSV reader I ...
    (comp.lang.python)