[antlr-interest] [newbie] Lexer Confusion

Johannes Luber jaluber at gmx.de
Sat Jul 5 04:45:06 PDT 2008


UW Student schrieb:
>  >  >2) Can you please confirm my understanding of your use of a
>  >  >syntactic predicate?  On a single DOT, the lexer will return
>  >  >a TERM1 token.  On a double DOT, the lexer will return a TERM2
>  >  >token.  If this is the case, won't a triple DOT be lexed as
>  >  >TERM2 TERM1 (rather than the reverse)?
>  >
>  > That's correct.  But isn't that what you want anyway?  (One thing that
>  > is different between the two: your original rule would turn '....' into
>  > a single TERM2 token, while Johannes' version would turn it into two
>  > TERM2 tokens.)
> 
> I would really prefer to have a single token.  Is it possible to modify 
> Johannes' version to handle that?
> 
> Thanks,
> Andrew
> 

Try this:

TERM1: '.' ( ('.')=> '.' {$type = TERM2;} )* ;

Johannes

P.S. to Gavin: I've seen that a book of an author named Gavin Lambert is 
turned into a movie. Any chance that you lead a double life? ;)


More information about the antlr-interest mailing list