[antlr-interest] Incremental Parsing, AST Generation

Christian Schladetsch christian.schladetsch at gmail.com
Sat Jan 16 00:17:53 PST 2010


Hello,

I am writing a network protocol using ANTLR. My idea is to use ANTLR to
parse incoming packets formed as possibly nested edicts.

Example full transcript of input is:

foo(a=1,b="baz")
{
  bar();
  spam(c=10)
  {
      grok(@b);
   }
}

Now, the key issue I have is to avoid reparsing the entire file when new
input arrives. For example:

foo()
{
   bar();

This is valid input for my grammar. When new input arrives, such as:

  spam()
  {

I want to re-use the previously parsed items (and AST, and code generated by
the AST via StringTemplate), while just adding the new tokens to the parser,
and new nodes to the tree, and new code to my VM.

Basically, I'd like to know if it is possible to generate an AST from a
parser, then add more input to that parser (and have it possibly fail
parsing), then add more to the AST.

It is impractical to have to re-parse the entire input (and re-create the
entire AST) when new input arrives. Full transcripts can be thousands of
lines long.

There is a way to do this, but I would like to see if I can first leverage
ANTLR. I've used ANTLR with great success (and a lot of bleary eyes), but
this is a new application of it for me and I am unsure of the feasibility.

Thanks in advance,
Christian.

PS. Apologies if this is a dupe.


More information about the antlr-interest mailing list