[antlr-interest] nested parsing (BSDL)

David Piepgrass qwertie256 at gmail.com
Tue Jan 22 20:06:11 PST 2008


> > (but I  would definitely keep the multiple grammars apart).
>
> I really do not want to keep the grammars separate.

It's rather late for me to join the discussion, but here's a thought.
It sounds like you don't want to use two nested grammars because the
outer and inner grammar are so similar.

In that case, maybe you could still nest the grammars, but use the
*same* parser for the outer and inner code. The outer lexer would
tokenize the BSDL strings without parsing them, then the outer parser
would concatenate the strings. Then it would create a 'string stream'
(though I'm not sure what you can use as a string stream in C/C++)
from the concatenated string, and send it to an inner lexer and
parser. The trick is simply that the outer and inner parsers are just
different instances of the same class. The parser and lexer classes
could have a flag in it like

bool isInnerParser;

So that the outer and inner parsers can act slightly differently
depending on this flag. Once the inner parser is done, the outer
parser can append the AST from the inner parser to the outer AST.

Am I making sense?

-- 
- David
http://qism.blogspot.com


More information about the antlr-interest mailing list