[antlr-interest] passing parts of the parse around as parameters(newbie)
Gavin Lambert
antlr at mirality.co.nz
Mon Jan 26 23:17:39 PST 2009
At 15:48 27/01/2009, Carter Cheng wrote:
>Thanks. Is it possible to insert this tree back into the AST? I
>know there is sort of an example of this in the book but the C
>Runtime seems to use slightly different structures.
If you have a tree (eg. an ANTLR3_BASE_TREE) that you want to put
into the AST, just specify it in the rewrite rule in the
appropriate place.
eg:
var[ANTLR3_BASE_TREE* t]
: ID -> ^(ID $t);
You might need to use {$t} in the rewrite instead of just $t; I
forget the exact syntax. (Code blocks in a rewrite rule are
assumed to evaluate to a tree or node, though it's likely that
only one of the two is supported by the C runtime, as it doesn't
support overloading and can't rely on having a smart compiler like
gcc.)
More information about the antlr-interest
mailing list