[antlr-interest] [C] Skip sub-tree nodes from AST?

Gonzague Reydet gonzague.reydet at gmail.com
Tue Jan 3 13:01:55 PST 2012


Hi Jim,

I suppose by "RELEASE" macro you mean "REWIND"?

Yes I tried to use these macros as following :
 ^(IF expression { thenIdx = MARK(); } ^(THEN .*) { elseIdx = MARK(); }
^(ELSE .*) ENDIF)

But the same problem occurs as described in my previous message, the
generated tree parser does not handle properly the UP and DOWN tokens for
the " .* " pattern.
I don't see how to use the MARK macro without the " .* " pattern.


2012/1/3 Jim Idle <jimi at temporal-wave.com>

> Did you look at the MARK and RELEASE macros?
>
> Jim
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Gonzague Reydet
> > Sent: Tuesday, January 03, 2012 9:32 AM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] [C] Skip sub-tree nodes from AST?
> >
> > Hi all!
> >
> > It's been two days I am investigating on how to skip a subtree with the
> > C target of ANTLR v3.4. I found many discussions on this subject on
> > markmail (notably the following one:
> > http://markmail.org/message/f5op6tdn4vfpw57v).
> > Exactly like this discussion, my original purpose is to implement an
> > if/then/else interpreter.
> > But I can't find a valid solution to parse only either the "then" or
> > the "else" statement skipping the other one and going to the end of the
> > if statement after having handled it.
> >
> > The "if" rule of my parser grammar constructs the AST as following:*
> > ^(IF expression ^(THEN statement) ^(ELSE statement?) ENDIF);  *
> >
> > I have tried two different ways:
> > - First using the method proposed in the discussion :
> > ^(IF expression {
> >     pANTLR3_BASE_TREE n = $IF.getChild($IF, 3);
> >     SEEK(n->savedIndex);
> >     ...
> > } )
> > The problem here is the 'savedIndex' field is never set. Is their a way
> > for this field to be set before parsing the tree?
> >
> > - Second using a "wildcard pattern" as following : ^(IF expression
> > ^(THEN
> > .*) ^(ELSE .*) ENDIF)
> > The problem here is the generated tree parser does not handle DOWN
> > tokens, so it results in parsing errors when trying to match the
> > "wildcarded"
> > subtree.
> >
> >
> > I have found the Pie example
> > (http://www.antlr.org/wiki/display/ANTLR3/Pie)
> > that passes a "defer" parameter to disable execution in all subrules.
> > Is this really the only solution for this issue with the C target?
> > I would really prefer to use the approach proposed by Terrence for the
> > Java target (http://markmail.org/message/7thj4um2bzhuvqpy) but this
> > will lead to the same issue of my second solution.
> >
> > Is there any other solution for this?
> >
> > Regards,
> > Gonzague
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> > email-address
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>



-- 
Tél : +33 (0)6 21 02 90 48


More information about the antlr-interest mailing list