[antlr-interest] Problem using predicates in V3
Dr. Hartmut Kocher
hwk.cortex-brainware at t-online.de
Sun Feb 11 12:26:46 PST 2007
I know that this is ambiguous. That's why I tried to solve it with a
predicate. I need both definitions. In other places in the grammar I have
identifiers like "t123a". Still 'abc' must always be parsed as 'abc' never
as identifier. That means 'abc2' must be parsed as 'abc' INT even though it
matches the definition of the ID token.
So I need to force the lexer to never parse 'abc' as ID.
Any ideas?
Dr. Hartmut Kocher
Cortex Brainware Consulting & Training GmbH
Kirchplatz 5
D-82049 Pullach
Tel: +49 (89) 744 850 0
Fax: +49 (89) 744 850 11
http://www.cortex-brainware.de
E-Mail: hwk at cortex-brainware.de
Handelsregister:
Registergericht: Amtsgericht München
HRB-Nr. 120614
Vertretungsberechtigte Geschäftsführer:
Dipl.-Inform. Dorothea Burger, Dr.-Ing. Hartmut Kocher, Dr.-Ing. Martin
Lang, Dr. rer. nat. Rolf Peter Wehrum
-----Ursprüngliche Nachricht-----
Von: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] Im Auftrag von Terence Parr
Gesendet: Sonntag, 11. Februar 2007 20:34
An: ANTLR Interest
Betreff: Re: [antlr-interest] Problem using predicates in V3
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 thats 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, Im 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