[antlr-interest] Lists of one & rewrite rules

Jim Idle jimi at intersystems.com
Thu Mar 1 09:00:51 PST 2007


This will probably do what you want (assuming that op returns OR_OP):

 

orExpr: andExpr (or^ andExpr)* ;

 

or just 

 

orExpr: andExpr (OR_OP^ andExpr)*;

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Alex Milowski
Sent: Thursday, March 01, 2007 8:50 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Lists of one & rewrite rules

 

I currently have a rule like:

   orExpr : andExpr ( or andExpr )* ->
         ^(OR_OP andExpr*);

That means I always get a tree like:

(OR_OP expr ...)

but for a singleton I'd like just the expression 
instead of:

(OR_OP expr)

How do I do that in the re-write rule?  Can I test for
just one item in the list ?

--Alex Milowski

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070301/633e0f59/attachment.html 


More information about the antlr-interest mailing list