[antlr-interest] Flattening lists?
jimi at temporal-wave.com
Mon Dec 15 08:40:36 PST 2008
On Mon, 2008-12-15 at 08:44 -0600, Gary R. Van Sickle wrote:
> Hi all,
> Not sure if this is something that should be obvious or not, but is there a
> way, completely in ANTLR 3.x (C backend FWIW), to flatten a list of
> "things"? What I mean is, say I have a language I'm trying to parse with
> constructs something like this:
> // Declare a bunch of variables.
> int varA, varB, varC;
> Now, it's pretty straightforward to convert this via lexer->parser->tree
> parser into:
> (VAR_DECL int (INITIALIZER varA) (INITIALIZER varB) (INITIALIZER
> But is there a way to get this instead?:
> (VAR_DECL int varA) (VAR_DECL int varB) (VAR_DECL int varC)
> Of course once I have the AST I can traverse it with C &&/|| C++, but it
> would sure be nice if ANTLR was able to flatten these sort of constructs for
rule : INT i+=ID (COMMA i+=ID) ->^(VAR_DECL INT $i)+
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest