[antlr-interest] Antlr 3 doesn't like '%' operator in actions?

Jim Idle jimi at temporal-wave.com
Thu Jun 21 10:39:42 PDT 2007


ANTLR has to look through your action to see if you referenced variables
like your $lhs. It does not know what your action language is so when it
sees a % it thinks you are trying to reference a string template. All
you have to do is escape that % with:

 

I \% 16;

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bernardo Elayda
Sent: Thursday, June 21, 2007 10:18 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Antlr 3 doesn't like '%' operator in actions?

 

Hi,

 

I needed to create some actions and functions that you the Java modulus
operator.  I expected Antlr 3 to ignore it but I'm getting an error when
I compile my grammar that says:

 

invalid StringTemplate % shorthand syntax '%'

 

Why isn't Antlr just passing over the code in the action?  In  general,
I found that whenever '%' was used in code in an action or in the
@members section, I get the above error.  Am I missing something here? 

  

A simple example is below.

 

regards,

Bernardo

 

 

-------------------------------

grammar Mytest;

options{
output=AST;
}


prog : lhs=MYINT (MYCOMMA MYINT)*
     {
            Integer temp = new Integer($lhs.text);
            int i = temp.intValue();
            int j = i % 16;
     }
     ;

MYINT : ('0'..'9')+
      ;

MYCOMMA : ','
        ;

WS : ('\r'|'\n'|' '|'\t')+ {$channel=HIDDEN;}
   ;

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070621/4d4c1483/attachment.html 


More information about the antlr-interest mailing list