changeset 61:512cd2248dfc

- Fix: issueing error on hexadecimal number overflow.
author aziz
date Fri, 29 Jun 2007 07:52:05 +0000
parents 32cc23bd217b
children 96af5653acef
files trunk/src/Lexer.d
diffstat 1 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Lexer.d	Fri Jun 29 06:27:04 2007 +0000
+++ b/trunk/src/Lexer.d	Fri Jun 29 07:52:05 2007 +0000
@@ -891,7 +891,7 @@
     Suffix:= (L|[uU]|L[uU]|[uU]L)?
     HexDigits:= [0-9a-zA-Z_]+
 
-    FloatLiteral:= Float([fFL]|i|[fFL]i)?
+    FloatLiteral:= Float[fFL]?i?
     Float:= DecFloat | HexFloat
     DecFloat:= ([0-9][0-9_]*[.]([0-9_]*DecExponent?)?) | [.][0-9][0-9_]*DecExponent? | [0-9][0-9_]*DecExponent
     DecExponent:= [eE][+-]?[0-9_]+
@@ -955,6 +955,7 @@
       break;
     }
 
+    // The number could be a float, so check overflow below.
     switch (*p)
     {
     case '.':
@@ -976,20 +977,12 @@
     goto Lfinalize;
 
   LscanHex:
-    digits = 16;
+    assert(digits == 0);
     while (ishexad(*++p))
     {
       if (*p == '_')
         continue;
-
-      if (--digits == 0)
-      {
-        // Overflow: skip following digits.
-        overflow = true;
-        while (ishexad(*++p)) {}
-        break;
-      }
-
+      ++digits;
       ulong_ *= 16;
       if (*p <= '9')
         ulong_ += *p - '0';
@@ -999,9 +992,16 @@
         ulong_ += *p - 'a' + 10;
     }
 
-    if (digits == 16)
+    if (digits == 0)
       error(MID.NoDigitsInHexNumber);
 
+    if (digits > 16)
+    {
+      // Overflow: skip following digits.
+      error(MID.OverflowHexNumber);
+      while (ishexad(*++p)) {}
+    }
+
     switch (*p)
     {
     case '.':