[antlr-interest] Recognizing C type numbers

Henry Butowsky henryb at ntlworld.com
Mon Oct 24 07:19:54 PDT 2005


Hi Guys,
	I want to recognize C type numbers with/without a suffix.
	ie 200b ,50B   type byte
	20L ,10l       type long
	111,212        type int
	1.2 12e10, .234E-3 , 1.2d, 200e+10D  type double
	1f ,1.2f, .234f 20e+10F              type float

So far I have in the lexer


	
protected DGT:     ('0'..'9');
protected LPH:     ( 'a'..'z' | 'A'..'Z' | '_' );
protected LPHDGT:  ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9');
protected XPN:     ( 'e' | 'E' ) ( '+' | '-' )? ('0'..'9')+ ;


NUMBER:
         ( (DGT)* ((  '.' (DGT)*(XPN)? ) | XPN ))=> ( (DGT)* 
(('.'(DGT)*(XPN)? ) | XPN ))
		{  $setType(DOUBLE);  }
             | ((DGT)+   { $setType(INT);}
             | ('L'|'l') { $setType(INT);}
             | ('S'|'s') { $setType(SHORT);}
             | ('B'|'b') { $setType(BYTE); printf("Lexing byte\n"); }
           )
         ;
VAR_ID: LPH (LPH|DGT)*;

The numbers sort of work -- but Im getting non-determinism between 
VAR_ID and NUMBER

Any ideas how to rewrite lexer ?
Many thx



More information about the antlr-interest mailing list