[antlr-interest] Incremental Parsing?

Benji Smith benji at benjismith.net
Mon Jul 16 19:33:26 PDT 2007


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


More information about the antlr-interest mailing list