@@ -848,16 +848,38 @@ Expression ParseStringLiteral()
848
848
Expression ParseIntegerLiteral ( )
849
849
{
850
850
ValidateToken ( TokenId . IntegerLiteral ) ;
851
+
851
852
string text = _token . text ;
853
+ string qualifier = null ;
854
+ char last = text [ text . Length - 1 ] ;
855
+
856
+ if ( char . IsLetter ( last ) )
857
+ {
858
+ int pos = text . Length - 1 , count = 0 ;
859
+ while ( char . IsLetter ( text [ pos ] ) )
860
+ {
861
+ ++ count ;
862
+ -- pos ;
863
+ }
864
+ qualifier = text . Substring ( text . Length - count , count ) ;
865
+ text = text . Substring ( 0 , text . Length - count ) ;
866
+ }
867
+
852
868
if ( text [ 0 ] != '-' )
853
869
{
854
870
ulong value ;
855
871
if ( ! ulong . TryParse ( text , out value ) )
856
872
throw ParseError ( Res . InvalidIntegerLiteral , text ) ;
857
873
NextToken ( ) ;
858
- if ( value <= ( ulong ) int . MaxValue ) return CreateLiteral ( ( int ) value , text ) ;
859
- if ( value <= ( ulong ) uint . MaxValue ) return CreateLiteral ( ( uint ) value , text ) ;
860
- if ( value <= ( ulong ) long . MaxValue ) return CreateLiteral ( ( long ) value , text ) ;
874
+ if ( ! string . IsNullOrEmpty ( qualifier ) )
875
+ {
876
+ if ( qualifier == "U" ) return CreateLiteral ( ( uint ) value , text ) ;
877
+ if ( qualifier == "L" ) return CreateLiteral ( ( long ) value , text ) ;
878
+ else if ( qualifier == "UL" ) return CreateLiteral ( value , text ) ;
879
+ }
880
+ if ( value <= int . MaxValue ) return CreateLiteral ( ( int ) value , text ) ;
881
+ if ( value <= uint . MaxValue ) return CreateLiteral ( ( uint ) value , text ) ;
882
+ if ( value <= long . MaxValue ) return CreateLiteral ( ( long ) value , text ) ;
861
883
return CreateLiteral ( value , text ) ;
862
884
}
863
885
else
@@ -866,8 +888,16 @@ Expression ParseIntegerLiteral()
866
888
if ( ! long . TryParse ( text , out value ) )
867
889
throw ParseError ( Res . InvalidIntegerLiteral , text ) ;
868
890
NextToken ( ) ;
869
- if ( value >= int . MinValue && value <= int . MaxValue )
870
- return CreateLiteral ( ( int ) value , text ) ;
891
+ if ( ! string . IsNullOrEmpty ( qualifier ) )
892
+ {
893
+ if ( qualifier == "L" )
894
+ return CreateLiteral ( value , text ) ;
895
+ else
896
+ throw ParseError ( Res . InvalidIntegerLiteral , qualifier ) ;
897
+ }
898
+
899
+ if ( value <= int . MaxValue ) return CreateLiteral ( ( int ) value , text ) ;
900
+
871
901
return CreateLiteral ( value , text ) ;
872
902
}
873
903
}
@@ -883,6 +913,11 @@ Expression ParseRealLiteral()
883
913
float f ;
884
914
if ( float . TryParse ( text . Substring ( 0 , text . Length - 1 ) , out f ) ) value = f ;
885
915
}
916
+ else if ( last == 'D' || last == 'd' )
917
+ {
918
+ double d ;
919
+ if ( double . TryParse ( text . Substring ( 0 , text . Length - 1 ) , out d ) ) value = d ;
920
+ }
886
921
else
887
922
{
888
923
double d ;
@@ -2422,13 +2457,27 @@ void NextToken()
2422
2457
t = TokenId . Identifier ;
2423
2458
break ;
2424
2459
}
2460
+
2425
2461
if ( char . IsDigit ( _ch ) )
2426
2462
{
2427
2463
t = TokenId . IntegerLiteral ;
2428
2464
do
2429
2465
{
2430
2466
NextChar ( ) ;
2431
2467
} while ( char . IsDigit ( _ch ) ) ;
2468
+
2469
+ if ( _ch == 'U' || _ch == 'L' )
2470
+ {
2471
+ NextChar ( ) ;
2472
+ if ( _ch == 'L' )
2473
+ {
2474
+ if ( _text [ _textPos - 1 ] == 'U' ) NextChar ( ) ;
2475
+ else throw ParseError ( _textPos , Res . InvalidIntegerQualifier , _text . Substring ( _textPos - 1 , 2 ) ) ;
2476
+ }
2477
+ ValidateExpression ( ) ;
2478
+ break ;
2479
+ }
2480
+
2432
2481
if ( _ch == '.' )
2433
2482
{
2434
2483
t = TokenId . RealLiteral ;
@@ -2439,6 +2488,7 @@ void NextToken()
2439
2488
NextChar ( ) ;
2440
2489
} while ( char . IsDigit ( _ch ) ) ;
2441
2490
}
2491
+
2442
2492
if ( _ch == 'E' || _ch == 'e' )
2443
2493
{
2444
2494
t = TokenId . RealLiteral ;
@@ -2450,16 +2500,20 @@ void NextToken()
2450
2500
NextChar ( ) ;
2451
2501
} while ( char . IsDigit ( _ch ) ) ;
2452
2502
}
2503
+
2453
2504
if ( _ch == 'F' || _ch == 'f' ) NextChar ( ) ;
2505
+ if ( _ch == 'D' || _ch == 'd' ) NextChar ( ) ;
2454
2506
break ;
2455
2507
}
2508
+
2456
2509
if ( _textPos == _textLen )
2457
2510
{
2458
2511
t = TokenId . End ;
2459
2512
break ;
2460
2513
}
2461
2514
throw ParseError ( _textPos , Res . InvalidCharacter , _ch ) ;
2462
2515
}
2516
+
2463
2517
_token . pos = tokenPos ;
2464
2518
_token . text = _text . Substring ( tokenPos , _textPos - tokenPos ) ;
2465
2519
_token . id = GetAliasedTokenId ( t , _token . text ) ;
@@ -2478,6 +2532,11 @@ string GetIdentifier()
2478
2532
return id ;
2479
2533
}
2480
2534
2535
+ void ValidateExpression ( )
2536
+ {
2537
+ if ( char . IsLetterOrDigit ( _ch ) ) throw ParseError ( _textPos , Res . ExpressionExpected ) ;
2538
+ }
2539
+
2481
2540
void ValidateDigit ( )
2482
2541
{
2483
2542
if ( ! char . IsDigit ( _ch ) ) throw ParseError ( _textPos , Res . DigitExpected ) ;
0 commit comments