f_string.append( (char)next_char );
advance();
}
float f_val = ( new Float( f_string.toString() ) ).floatValue();
return new float_token( sym.FLOAT_NUMBER, f_val );
}
else
{
// See if hexadecimal value
if( next_char == 'x' || next_char == 'X' )
{
advance();
radix = 16;
}
StringBuffer val = new StringBuffer( "0" );
digit = Character.digit( (char)next_char, radix );
while( digit != -1 )
{
val.append( (char)next_char );
advance();
digit = Character.digit( (char)next_char, radix );
}
String str = val.toString();
try
{
return new int_token( sym.NUMBER,
Integer.parseInt( str, radix ) );
}
catch( NumberFormatException ex )
{
try
{
return new long_token( sym.LONG_NUMBER,
Long.parseLong( str, radix ) );
}
catch( NumberFormatException ex2 )
{
emit_error( "Invalid octal/hex value: " + str );
}
}
return null;
}
}
/* Try to scan integer, floating point or fixed point literals */
if (isDigit (((char)next_char)) ||
next_char == '.' ||
(next_char == '-' && isDigit (((char)next_char2))))
{
StringBuffer value = new StringBuffer();
StringBuffer fraction = null;
int exp = 0;
if ( next_char == '-' )
{
value.append( (char)next_char );
advance();
}
// Read integer part
while( next_char >= '0' && next_char <= '9' )
{
value.append( (char)next_char );
advance();
}
// Read fraction
if( next_char == '.' )
{
fraction = new StringBuffer();
advance();
while( next_char >= '0' && next_char <= '9' )
{
fraction.append( (char)next_char );
advance();
}
}
// Read exponent
if( next_char == 'e' || next_char == 'E' )
{
if( fraction == null )
fraction = new StringBuffer();
fraction.append( 'e' );
advance();
if( next_char == '-' || next_char == '+' )
{
fraction.append( (char)next_char );
advance();
}
while( next_char >= '0' && next_char <= '9' )
{
fraction.append( (char)next_char );
advance();
}
if( fraction.length() == 1 )
{
emit_error( "Empty exponent in float/double." );
continue;
}
return new float_token( sym.FLOAT_NUMBER,
Float.valueOf( value.toString() +
"." +
fraction.toString() ).floatValue() );
}
if( next_char == 'd' || next_char == 'D' )
{
advance();
if( fraction == null )
fraction = new StringBuffer();
java.math.BigDecimal bi =
new java.math.BigDecimal( value.toString() + "." +
fraction.toString() );
return new fixed_token( sym.FIXED_NUMBER, bi );
}
if( fraction == null )
{
/* integer or long */
token tok = null;
String str = value.toString();
try
{
tok = new int_token( sym.NUMBER, Integer.parseInt( str ) );
}
catch( NumberFormatException ex )
{
try
{
tok = new long_token
( sym.LONG_NUMBER, Long.parseLong( str ) );
}
catch( NumberFormatException ex2 )
{
try
{
// Not quite critical yet - lets try stuffing it into
// a bigdecimal for later checking.
tok = new fixed_token
(sym.FIXED_NUMBER, new java.math.BigDecimal (str));
}
catch (NumberFormatException ex3)
{
emit_error( "Invalid long value: " + str );
}
}
}
return tok;
}
else
{
try
{
float f =
Float.valueOf( value.toString() + "." +
fraction.toString() ).floatValue();
return new float_token( sym.FLOAT_NUMBER, f );
}
catch( NumberFormatException nf )
{
emit_error( "Unexpected symbol: " +
value.toString() + "." +