[antlr-interest] lexical nondeterminism question.

Sinan sinan.karasu at boeing.com
Wed Jun 26 14:31:39 PDT 2002


I need to be able to support the syntax.

 

&h<HEX DIGITS>

&h<HEX DIGITS>&

&o<OCTAL_DIGITS>

&o<OCTAL_DIGITS>&

 

The problem is that I also need to support the string concatenation
syntax

 

<STRING> & <STRING>

 

Notice that I need to be able to use the amperstand for hex numbers,
octal numbers and string concatenation.

So, I have tried the following lexer rules.  

predicates are position dependent.
Disambiguate first...

Sinan


NUM_INT

options {

   paraphrase = "number";

}

            {boolean isDecimal=false;}

            :           

      ( options { warnWhenFollowAmbig=false; greedy=true; } 

      :
		('&' 'h')=>'&' 'h' HEX_INT ('&')?   {_ttype = NUM_INT;}

	|	('&' 'o')=>'&' 'o' OCTAL_INT ('&')? {_ttype = NUM_INT;}
	|	'.' {_ttype = DOT;} (('0'..'9')+ (EXPONENT)? { _ttype = NUM_FLOAT;
})?
	|     ('0'..'9') ('0'..'9')*  {isDecimal=true; _ttype =
NUM_INT;}                   // non-zero decimal
                              ( // only check to see if it's a float if
looks like decimal so far

                                 {isDecimal}? ( '.' ('0'..'9')*
(EXPONENT)? { _ttype = NUM_FLOAT; }

                                              | EXPONENT { _ttype =
NUM_FLOAT; }

                            | '&'     // indicates that the number is of
type Long

                            | // Nothing.  This will be the else part.

                            )

                              )?


      )

            ;

 

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



More information about the antlr-interest mailing list