[antlr-interest] lexical question

Jim Idle jimi at temporal-wave.com
Tue May 29 19:42:10 PDT 2012


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







List: http://www.antlr.org/mailman/listinfo/antlr-interest

Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list