[antlr-interest] Flattening lists?

Gary R. Van Sickle g.r.vansickle at att.net
Mon Dec 15 06:44:57 PST 2008


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
varC))

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
me.

Thanks,

-- 
Gary R. Van Sickle



More information about the antlr-interest mailing list