[antlr-interest] Problem using predicates in V3
Terence Parr
parrt at cs.usfca.edu
Sun Feb 11 11:33:54 PST 2007
On Feb 11, 2007, at 3:14 AM, Dr. Hartmut Kocher wrote:
> I have a combined grammar that has the normal identifier definition
> in the lexer.
>
>
>
> fragment DIGIT : '0'..'9';
>
>
>
> fragment LETTER : ('a'..'z'|'A'..'Z');
>
>
>
> INT : DIGIT+;
>
>
>
> ID : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')+ ;
>
>
>
> Now I have a keyword ’abc’ that’s used in the parser grammar like so:
>
>
>
> test : ‘abc’ INT?;
>
>
>
> The rule “test” should match input “abc”, “abc 2”, and “abc2”.
>
>
>
> Unfortunately, the latter matches ID as well. Now, I’m trying to
> force ANTLR to parse “abc2” as two tokens “abc” and INT.
hi.
Then you have an ambiguity. abc2 matches ID. Take 0..9 out of ID.
Ter
More information about the antlr-interest
mailing list