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

Nev antlr at zavalon.com
Fri Apr 4 13:05:04 PDT 2008


You could try,

1.	remove the "?" after elseStatement
2.	add empty alt in the elseStatement

 

elseStatement

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

      | -> ^(NODE_ELSE)

      ;

 

 

  _____  

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Chris Snyder
Sent: Saturday, 5 April 2008 6:55 AM
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/20080405/8d222175/attachment-0001.html 


More information about the antlr-interest mailing list