[antlr-interest] Problem using predicates in V3

Terence Parr parrt at cs.usfca.edu
Sun Feb 11 13:24:10 PST 2007


On Feb 11, 2007, at 1:15 PM, Dr. Hartmut Kocher wrote:

> The language is fixed :-( And no, I didn't invent it.

;)

> Your second solution is also not possible because then "t123a"  
> would parse
> OK, but "t 123 a" too, which is not allowed. (Of course there's a  
> whitespace
> rule)...

actually, it would only match "t 123" as part of tha rule, but no  
biggie.

> In ANTLR2 I did the following:
>
> tokens {
> "abc";
> }
>
> IDENT
>    options {
>      testLiterals=true;
>    }
>   :
>     ("abc" DIGIT) => "abc"
>   | ('a'..'z') (LD | '_')*;  // LD is letter or digit
>
> This worked quite well. Now I'm trying to accomplish the same with  
> ANTLR 3.
> No such luck so far.

OHhhhhh....ok, abc is a keyword and for some reason it's not taken as  
a special case; oh, because antlr matches longest it can.

IDENT : ("abc" DIGIT)=> "abc" | ('a'..'z') (LD | '_')* ;

should work.  It doesn't?

Ter


More information about the antlr-interest mailing list