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

Bryan Ewbank ewbank at gmail.com
Thu Jul 14 09:48:31 PDT 2005


It's difficult with your current tree-shape.  I'd add another level and replace
   #( 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" statement
> if the condition is false?


More information about the antlr-interest mailing list