Mercurial > projects > dil
comparison trunk/src/Lexer.d @ 57:c0f1c8be3a47
- Added code for converting hex characters to binary numbers.
author | aziz |
---|---|
date | Thu, 28 Jun 2007 12:47:05 +0000 |
parents | 63af7ddf52e1 |
children | 50bb7fc9db44 |
comparison
equal
deleted
inserted
replaced
56:63af7ddf52e1 | 57:c0f1c8be3a47 |
---|---|
909 Long = 1<<1 | 909 Long = 1<<1 |
910 } | 910 } |
911 | 911 |
912 ulong ulong_; | 912 ulong ulong_; |
913 bool overflow; | 913 bool overflow; |
914 size_t digits; | |
914 | 915 |
915 if (*p != '0') | 916 if (*p != '0') |
916 goto LscanInteger; | 917 goto LscanInteger; |
917 ++p; // skip zero | 918 ++p; // skip zero |
918 // check for xX bB ... | 919 // check for xX bB ... |
972 // ulong_ = toInt(t.span); | 973 // ulong_ = toInt(t.span); |
973 assert((isdigit(p[-1]) || p[-1] == '_') && !isdigit(*p) && *p != '_'); | 974 assert((isdigit(p[-1]) || p[-1] == '_') && !isdigit(*p) && *p != '_'); |
974 goto Lfinalize; | 975 goto Lfinalize; |
975 | 976 |
976 LscanHex: | 977 LscanHex: |
978 digits = 16; | |
977 while (ishexad(*++p)) | 979 while (ishexad(*++p)) |
978 { | 980 { |
979 if (*p == '_') | 981 if (*p == '_') |
980 continue; | 982 continue; |
981 // todo | 983 |
982 } | 984 if (--digits == 0) |
985 { | |
986 // Overflow: skip following digits. | |
987 overflow = true; | |
988 while (ishexad(*++p)) {} | |
989 break; | |
990 } | |
991 | |
992 ulong_ *= 16; | |
993 if (*p <= '9') | |
994 ulong_ += *p - '0'; | |
995 else if (*p <= 'F') | |
996 ulong_ += *p - 'A' + 10; | |
997 else | |
998 ulong_ += *p - 'a' + 10; | |
999 } | |
1000 | |
983 switch (*p) | 1001 switch (*p) |
984 { | 1002 { |
985 case '.': | 1003 case '.': |
986 if (p[1] != '.') | 1004 if (p[1] != '.') |
987 goto LscanReal; | 1005 goto LscanReal; |
993 goto LscanReal; | 1011 goto LscanReal; |
994 } | 1012 } |
995 goto Lfinalize; | 1013 goto Lfinalize; |
996 | 1014 |
997 LscanBin: | 1015 LscanBin: |
998 size_t digits; | 1016 assert(digits == 0); |
999 while (1) | 1017 while (1) |
1000 { | 1018 { |
1001 if (*++p == '0') | 1019 if (*++p == '0') |
1002 { | 1020 { |
1003 ++digits; | 1021 ++digits; |