[antlr-interest] Lexical rules

Matt Benson gudnabrsam at yahoo.com
Tue Feb 18 06:55:08 PST 2003


It appears to my inexperienced eye that as long as a
NAME can be a single ALPHA, it will conflict with
ALPHA; likewise if NUMERIC can be a single DIGIT it
will conflict with DIGIT.  Do you plan to use an Antlr
parser with this lexer?  Maybe you could change the
definitions so that NUMERIC has either two or more
digits or a dot followed by one or more digits, and
NAME has one ALPHA followed by at least one ALPHA,
NUMERIC, or UNDERSCORE.  Then your parser could allow
the alternative that a single digit could be used as a
numeric:

class SharonLiParser extends Parser;
name	:	ALPHA | NAME ;
numeric	:	DIGIT | NUMERIC ;
class SharonLiLexer extends Lexer;
options { k = 2; } // two token lookahead
ALPHA  : ( 'a'..'z' | 'A'..'Z' ); 
DIGIT : ('0'..'9');
NUMERIC : DIGIT ((DIGIT)+ | ((DOT) (d:DIGIT)+)) ;
NAME : (ALPHA) (ALPHA|DIGIT|UNDERSCORE)+ ;
UNDERSCORE : '_' ;
DOT : '.' ;


--- Sharon Li <hushlee83 at yahoo.com.sg> wrote:
> 
> Hello,
> 
> got a problem with non-determinism. how should i
> define my lexer rules so that I can have:
> 
> ALPHA  : ( 'a'..'z' | 'A'..'Z' ); 
> 
> DIGIT : ('0'..'9');
> 
> NUMERIC : (DIGIT)+ ((DOT) (d:DIGIT)*)* ;
> 
> NAME : (ALPHA) (ALPHA|DIGIT|UNDERSCORE)* ;
> 
> 
> all in my lexer without getting a non-determinism
> error? Coz I need a rule that finds a single digit
> as well as a rule that finds a numeric (i.e with
> decimal places), and a rule for a single letter as
> well as word.
> 
> Thanks in advance for any help rendered! 
> 
> 
>  Yahoo! Biztools
> - Promote your business from just $5 a month!


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list