[antlr-interest] Problem using predicates in V3

Dr. Hartmut Kocher hwk.cortex-brainware at t-online.de
Sun Feb 11 03:14:24 PST 2007


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.

 

When I change ID to use a predicate, the predicate is called but the lexer
still emits an ID token


 

ID   :    ('srg' DIGIT) => 'srg' | ('a'..'z'|'A'..'Z')
('a'..'z'|'A'..'Z'|'_'|'0'..'9')+ ;

 

What is the best approach to parse this? (I have more such combinations such
as “abd” or “add” 
).

 

Any ideas?

 

Thanks

 

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/> 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 

 

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


More information about the antlr-interest mailing list