[antlr-interest] conditional processing

Gerald B. Rosenberg gbr at newtechlaw.com
Wed Nov 28 16:58:41 PST 2007


Explained well near the bottom of:
http://www.antlr.org/wiki/display/ANTLR3/6.+Advanced+processing

At 12:08 PM 11/28/2007, Mark Volkmann wrote:
>On 11/28/07, Gerald B. Rosenberg <gbr at newtechlaw.com> wrote:
> >
> >  Probably a bit of overkill in your given case, but to do it (using the
> > boolean return from condition):
> >
> >  statement
> >    : simpleStatement
> >    | ^('IF' b=condition { $b.result }? simpleStatement)
> >    ;
> >    catch[FailedPredicateException fpe] {System.err.println("Ignore");}
> >
> >  simpleStatement
> >          : ^('ADD' n=NUMBER) { value += toInt(n); }
> >          | ^( 'SUBTRACT' n=NUMBER) { value -= toInt(n); }
> >          | 'PRINT' { System.out.println(value); }
> >          ;
> >
> >  Appropriate where simpleStatement does not/should not be aware of
> > condition.
>
>I like your approach, but I can't get it to work. It seems that
>something is wrong with the catch of FailedPredicateException. When
>the first IF whose condition evaluates to false is encountered, it
>prints "Ignore", executes the simpleStatement after the semantic
>predicate anyway, and then stops processing, ignoring the rest of the
>AST.

----
Gerald B. Rosenberg
Certiv Analytics

www.certiv.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071128/3b93af06/attachment.html 


More information about the antlr-interest mailing list