[antlr-interest] Incremental Parsing?

Loring Craymer lgcraymer at yahoo.com
Mon Jul 16 19:45:03 PDT 2007


Why not just implement the parser as a coroutine? 
That is, spawn a parser thread that relinquishes
control after a record is parsed (the callback you
mention could just relinquish control).  You could
"easily" implement a read_record that does the right
thing--transfer control to the parser and read from a
shared record buffer when control is returned.

IIRC, there is a discussion of coroutines in Vol. 1 (I
think) of Knuth.

BTW, this approach should be implementable with your
javaCC parser.

--Loring

--- Benji Smith <benji at benjismith.net> wrote:

> I got this message directly from Waldemar Sauer (I
> accidentally sent
> my first draft of the message directly to Waldemar.
> oops.)
> 
> Based on his suggestion below, I thought of an
> interesting way to
> handle the situation, if necessary.
> 
> On 7/16/07, Waldemar Sauer
> <waldemarsauer at hotmail.com> wrote:
> > No probs.  To my knowledge, due to the fact that
> antlr is an LL(*) parser,
> > it is already incremental in nature.  As long as
> you do not build an AST
> > (I'm not sure what the default setting (build vs.
> do not build) is in this
> > case), the memory imprint should be minimal.  That
> is: if you have a grammar
> > rule such as the following:
> >
> > rule1: (rule2 { javaFunctionHere(); })*;
> >
> > javaFunctionHere() will be executing each time
> rule2 is matched.
> >
> > Hope this helps
> >  - Waldemar
> 
> Based on Waldemar's feedback, it occurs to me that I
> could pass some
> sort of callback (an anonymous inner class, in Java,
> or a delegate in
> C#) into the parser's constructor, and then invoke
> the callback as a
> semantic action whenever the CsvRecord production
> matches.
> 
> Of course, a legitimate incremental parser (where
> the lexer pauses
> after returning a record) would be preferable. But
> at least the
> callback mechanism would prevent me from passing a
> hundred million
> Record objects back up to the calling code.
> 
> --benji smith
> 



       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  


More information about the antlr-interest mailing list