[antlr-interest] Tokens and literals: how to avoid conflics?

Jim Idle jimi at temporal-wave.com
Tue Jul 15 12:31:49 PDT 2008


On Tue, 2008-07-15 at 18:36 +0200, Gioele Barabucci wrote:

> Johannes Luber wrote:
> >> Is there a way to tell ANTLR "look for the characters 'id' only when in
> >> the ID token, in all the other cases classify it as NAME (or whatever
> >> fits it)"?
> >> 
> >> This happens quite often in my grammar (obviously this is just a simple
> >> test-case for my problems): I have many keywords that lose their special
> >> meaning once they are not in a certain position.
> >> 
> > 
> > It is not possible (yet?) to do context-dependent lexing. The solution
> > is to add ID as possible alternative in those special positions.
> 
> That is a quite cumbersome workaround. What about comments? Suppose that I
> add something like
> 
> comment: '/*' comment_text '*/' //I want to get the text inside the comment


COMMENT: '/*' ( options {greedy=false; } : . )* '*/' ;

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080715/34a64f6c/attachment.html 


More information about the antlr-interest mailing list