[antlr-interest] Antlr 3 doesn't like '%' operator in actions?
Wincent Colaiuta
win at wincent.com
Thu Jun 21 10:43:04 PDT 2007
El 21/6/2007, a las 19:18, Bernardo Elayda escribió:
> invalid StringTemplate % shorthand syntax '%'
You're getting this error because % has special meaning for
StringTemplate, and ANTLR uses StringTemplate under the covers.
In most cases you can escape the special character, so in your
example you would need to change:
> prog : lhs=MYINT (MYCOMMA MYINT)*
> {
> Integer temp = new Integer($lhs.text);
> int i = temp.intValue();
> int j = i % 16;
> }
> ;
To:
> prog : lhs=MYINT (MYCOMMA MYINT)*
> {
> Integer temp = new Integer($lhs.text);
> int i = temp.intValue();
> int j = i \% 16;
> }
> ;
I think it would be nice if ANTLR shielded grammar authors from that
particular implementation detail, but it's the way things are for now.
Be aware that there are some lexer-related cases in which even
escaping the special characters doesn't work (see <http://
www.antlr.org/pipermail/antlr-interest/2007-June/021212.html>).
Cheers,
Wincent
More information about the antlr-interest
mailing list