@@ -874,14 +874,17 @@ Expression ParseIntegerLiteral()
874
874
NextToken ( ) ;
875
875
if ( ! string . IsNullOrEmpty ( qualifier ) )
876
876
{
877
- if ( qualifier == "U" ) return CreateLiteral ( ( uint ) value , text ) ;
878
- if ( qualifier == "L" ) return CreateLiteral ( ( long ) value , text ) ;
877
+ if ( qualifier == "U" || qualifier == "u" ) return CreateLiteral ( ( uint ) value , text ) ;
878
+ if ( qualifier == "L" || qualifier == "l" ) return CreateLiteral ( ( long ) value , text ) ;
879
879
880
+ // in case of UL, just return
880
881
return CreateLiteral ( value , text ) ;
881
882
}
883
+
882
884
if ( value <= int . MaxValue ) return CreateLiteral ( ( int ) value , text ) ;
883
885
if ( value <= uint . MaxValue ) return CreateLiteral ( ( uint ) value , text ) ;
884
886
if ( value <= long . MaxValue ) return CreateLiteral ( ( long ) value , text ) ;
887
+
885
888
return CreateLiteral ( value , text ) ;
886
889
}
887
890
else
@@ -893,9 +896,15 @@ Expression ParseIntegerLiteral()
893
896
NextToken ( ) ;
894
897
if ( ! string . IsNullOrEmpty ( qualifier ) )
895
898
{
896
- if ( qualifier == "L" )
899
+ if ( qualifier == "L" || qualifier == "l" )
897
900
return CreateLiteral ( value , text ) ;
898
901
902
+ if ( qualifier == "F" || qualifier == "f" )
903
+ return TryParseAsFloat ( text , qualifier [ 0 ] ) ;
904
+
905
+ if ( qualifier == "D" || qualifier == "d" )
906
+ return TryParseAsDouble ( text , qualifier [ 0 ] ) ;
907
+
899
908
throw ParseError ( Res . MinusCannotBeAppliedToUnsignedInteger ) ;
900
909
}
901
910
@@ -905,30 +914,75 @@ Expression ParseIntegerLiteral()
905
914
}
906
915
}
907
916
917
+ //Expression ParseRealLiteral()
918
+ //{
919
+ // ValidateToken(TokenId.RealLiteral);
920
+ // string text = _token.text;
921
+ // object value = null;
922
+ // char last = text[text.Length - 1];
923
+ // if (last == 'F' || last == 'f')
924
+ // {
925
+ // float f;
926
+ // if (float.TryParse(text.Substring(0, text.Length - 1), out f)) value = f;
927
+ // }
928
+ // else if (last == 'D' || last == 'd')
929
+ // {
930
+ // double d;
931
+ // if (double.TryParse(text.Substring(0, text.Length - 1), out d)) value = d;
932
+ // }
933
+ // else
934
+ // {
935
+ // double d;
936
+ // if (double.TryParse(text, out d)) value = d;
937
+ // }
938
+ // if (value == null) throw ParseError(Res.InvalidRealLiteral, text);
939
+ // NextToken();
940
+ // return CreateLiteral(value, text);
941
+ //}
942
+
908
943
Expression ParseRealLiteral ( )
909
944
{
910
945
ValidateToken ( TokenId . RealLiteral ) ;
946
+
911
947
string text = _token . text ;
912
- object value = null ;
913
- char last = text [ text . Length - 1 ] ;
914
- if ( last == 'F' || last == 'f' )
948
+ char qualifier = text [ text . Length - 1 ] ;
949
+
950
+ NextToken ( ) ;
951
+ return TryParseAsFloat ( text , qualifier ) ;
952
+ }
953
+
954
+ Expression TryParseAsFloat ( string text , char qualifier )
955
+ {
956
+ if ( qualifier == 'F' || qualifier == 'f' )
915
957
{
916
958
float f ;
917
- if ( float . TryParse ( text . Substring ( 0 , text . Length - 1 ) , out f ) ) value = f ;
959
+ if ( float . TryParse ( text . Substring ( 0 , text . Length - 1 ) , out f ) )
960
+ {
961
+ return CreateLiteral ( f , text ) ;
962
+ }
918
963
}
919
- else if ( last == 'D' || last == 'd' )
964
+
965
+ // not possible to find float qualifier, so try to parse as double
966
+ return TryParseAsDouble ( text , qualifier ) ;
967
+ }
968
+
969
+ Expression TryParseAsDouble ( string text , char qualifier )
970
+ {
971
+ double d ;
972
+ if ( qualifier == 'D' || qualifier == 'd' )
920
973
{
921
- double d ;
922
- if ( double . TryParse ( text . Substring ( 0 , text . Length - 1 ) , out d ) ) value = d ;
974
+ if ( double . TryParse ( text . Substring ( 0 , text . Length - 1 ) , out d ) )
975
+ {
976
+ return CreateLiteral ( d , text ) ;
977
+ }
923
978
}
924
- else
979
+
980
+ if ( double . TryParse ( text , out d ) )
925
981
{
926
- double d ;
927
- if ( double . TryParse ( text , out d ) ) value = d ;
982
+ return CreateLiteral ( d , text ) ;
928
983
}
929
- if ( value == null ) throw ParseError ( Res . InvalidRealLiteral , text ) ;
930
- NextToken ( ) ;
931
- return CreateLiteral ( value , text ) ;
984
+
985
+ throw ParseError ( Res . InvalidRealLiteral , text ) ;
932
986
}
933
987
934
988
Expression CreateLiteral ( object value , string text )
0 commit comments