[antlr-interest] Jumping around in (my|a?) tree :-)

Craig Main craig at palantir.co.za
Thu Jul 14 23:49:31 PDT 2005


Thanks for the reply.
What is the best way to get the BLOCK tokens into the tree at this point?
I don't currently have BLOCK statement, and I do find these insertions


-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bryan Ewbank
Sent: 14 July 2005 06:49 PM
To: ANTLR Interest
Subject: Re: [antlr-interest] Jumping around in (my|a?) tree :-)

It's difficult with your current tree-shape.  I'd add another level and
   #( TOK_IF expr ( statement )* ( TOK_ELSE ( statement )* )? )
With this:
   #( TOK_IF expr #(BLOCK (statement)* ) ( #(BLOCK (statement)* ) ) )? )

The problem is that it's strange/hard to eat until just before
TOK_ELSE; therefore, make the tree regular...

If you assume #( TOK_IF expr block block ), then this works to drill
into the right component of the if-statement:

   #( TOK_IF expr
      ( {expr_true}? block | . )
      ( {expr_true}? . | block )?

The syntactic predicates "{expr_true}?" is used to control which leg
is evaluated (via "block" subrule) versus ignored (via "." wildcard).

There are other ways to write the rule, but the key is using "." to
bypass the code that you don't want to evaluate.

On 7/14/05, Craig Main <craig at palantir.co.za> wrote:
> Is there a way of making the tree only match the (statement*) in the
> affirmative portion of the tree if the "if" condition is true, and only
> match the (statement)* portion in the negative section of the "if"
> if the condition is false?

More information about the antlr-interest mailing list