[antlr-interest] lexical question

Stephen Siegel siegel at udel.edu
Wed May 30 07:16:14 PDT 2012


Jim, thanks for the solution, and the pointers to the documentation, which is very helpful.
-Steve

On May 29, 2012, at 10:42 PM, Jim Idle wrote:

> See the FAQ in the Wiki on lexing . .. … 4.5 and so on.
> 
> 
> 
> Backtracking won’t help the lexer and you should not use backtracking
> unless forced to (there are some good reasons for it). Remember also that
> the parser does not influence the lexer.
> 
> 
> 
> If this is all you want though, then:
> 
> 
> 
> fragment ELLIPSIS :;
> 
> DOT : '.'
> 
>     (   ('..')=> '.. ' { $type  = ELLIPSIS; }
> 
>       |
> 
>     )
> 
> ;
> 
> 
> 
> Cheers,
> 
> 
> 
> Jim
> 
> 
> 
> 
> 
> 
> 
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:
> antlr-interest-bounces at antlr.org] On Behalf Of Stephen Siegel
> Sent: Wednesday, May 30, 2012 8:24 AM
> To: ANTLR Interest
> Subject: [antlr-interest] lexical question
> 
> 
> 
> Consider the following grammar:
> 
> 
> 
> --------------------------------------
> 
> grammar dots;
> 
> 
> 
> r              :               (DOT | ELLIPSIS)*;
> 
> 
> 
> DOT       :               '.';
> 
> ELLIPSIS:              '...';
> 
> --------------------------------------
> 
> 
> 
> When given input "..", ANTLR says "expecting '.' but saw 'EOF'".
> 
> What I would like it to see is two DOTs.
> 
> What would be the "right" way to fix the problem?  Backtrack=true?
> 
> Thanks,
> 
> Steve



More information about the antlr-interest mailing list