[antlr-interest] How can I create a tree node if a rule is notmatched

Chris Snyder snyder at t-vec.com
Fri Apr 4 13:08:42 PDT 2008


Much easier then I though

 

ifStatement

      : IF expression (SEMI|COMMA)? (statement+ (COMMA)?)?
(elseIfStatement)* 

        (

        (elseStatement END SEMI?) -> ^(NODE_IF expression statement*
elseIfStatement* elseStatement)

        | (END SEMI?) -> ^(NODE_IF expression statement* elseIfStatement*
^(NODE_ELSE ))

        )

      ;

 

 

  _____  

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Chris Snyder
Sent: Friday, April 04, 2008 3:55 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] How can I create a tree node if a rule is
notmatched

 

Hello,

 

I have the rules below. When an "ifStatement" is found I want to create an
empty "NODE_ELSE" node when there are no "elseStatement" rule matches. I was
looking to do this so that in my tree walker I will always process a
NODE_ELSE assuming a NODE_IF was found. I can think of a couple of things to
try but I'm guessing there is probably a simple shortcut someone has already
run into.

 

Thanks,

Chris

 

//rule excerpt

ifStatement

      : IF expression (SEMI|COMMA)? (statement+ (COMMA)?)?
(elseIfStatement)* elseStatement? END SEMI? -> ^(NODE_IF expression
statement* elseIfStatement* elseStatement?)

      ;

 

elseIfStatement

      : ELSEIF expression (SEMI|COMMA)? (statement+ (COMMA)?)? ->
^(NODE_ELSE_IF expression statement*)

      ;

 

elseStatement

      : ELSE (SEMI|COMMA)? statement* -> ^(NODE_ELSE statement*)

      ;

 

 

 

 

T-VEC Technologies, Inc.

P.O. Box 8572

Delray Beach, FL 33482

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080404/6a5ff633/attachment.html 


More information about the antlr-interest mailing list