[antlr-interest] Example anyone?

Gavin Lambert antlr at mirality.co.nz
Tue Aug 21 13:13:10 PDT 2007


At 03:24 22/08/2007, Barnes, Jeff wrote:
 >I'm looking to implement a language that has the following 
features
 >(not complete):
[...]
 >I'm having a little trouble figuring out how to do the guardExpr 

 >because it can have SQBCLOSE in it (an array index for example). 


Depends on whether you want to validate the expression within the 
guard clause or whether you just want to pass it through verbatim 
and let the Java compiler deal with it.  If the former, you'll 
have to import some kind of expression rule from a Java grammar; 
if the latter, then you just need to maintain a count (or nesting 
structure) to make sure you don't exit the guardExpr until you've 
seen a balanced number of SQBCLOSEs.

I haven't tried this, but something along these lines ought to 
work for the latter case:

guardExpr
   :  ( ~(SQBOPEN | SQBCLOSE)
      | SQBOPEN guardExpr SQBCLOSE
      )*
   ;



More information about the antlr-interest mailing list