changeset 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
files trunk/src/Lexer.d
diffstat 1 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Lexer.d	Thu Jun 28 12:31:00 2007 +0000
+++ b/trunk/src/Lexer.d	Thu Jun 28 12:47:05 2007 +0000
@@ -911,6 +911,7 @@
 
     ulong ulong_;
     bool overflow;
+    size_t digits;
 
     if (*p != '0')
       goto LscanInteger;
@@ -974,12 +975,29 @@
     goto Lfinalize;
 
   LscanHex:
+    digits = 16;
     while (ishexad(*++p))
     {
       if (*p == '_')
         continue;
-      // todo
+
+      if (--digits == 0)
+      {
+        // Overflow: skip following digits.
+        overflow = true;
+        while (ishexad(*++p)) {}
+        break;
+      }
+
+      ulong_ *= 16;
+      if (*p <= '9')
+        ulong_ += *p - '0';
+      else if (*p <= 'F')
+        ulong_ += *p - 'A' + 10;
+      else
+        ulong_ += *p - 'a' + 10;
     }
+
     switch (*p)
     {
     case '.':
@@ -995,7 +1013,7 @@
     goto Lfinalize;
 
   LscanBin:
-    size_t digits;
+    assert(digits == 0);
     while (1)
     {
       if (*++p == '0')