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

Chris Snyder snyder at t-vec.com
Fri Apr 4 12:54:44 PDT 2008


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/e0bb6853/attachment.html 


More information about the antlr-interest mailing list