changeset 58:50bb7fc9db44

- The types of integers are recognized now. - Fix: continue statement missing in integer scanner.
author aziz
date Fri, 29 Jun 2007 05:47:00 +0000
parents c0f1c8be3a47
children 3e594725899a
files trunk/src/Lexer.d trunk/src/Messages.d trunk/src/Token.d trunk/src/format.css trunk/src/main.d
diffstat 5 files changed, 72 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Lexer.d	Thu Jun 28 12:47:05 2007 +0000
+++ b/trunk/src/Lexer.d	Fri Jun 29 05:47:00 2007 +0000
@@ -902,15 +902,9 @@
   */
   void scanNumber(ref Token t)
   {
-    enum Suffix
-    {
-      None     = 0,
-      Unsigned = 1,
-      Long     = 1<<1
-    }
-
     ulong ulong_;
     bool overflow;
+    bool isDecimal;
     size_t digits;
 
     if (*p != '0')
@@ -929,7 +923,7 @@
     case '.':
       if (p[1] == '.')
         break;
-    case 'i','f','F': // Imaginary and float literal suffix
+    case 'i','f','F', 'e', 'E': // Imaginary and float literal suffix
       goto LscanReal;
     case '_':
       ++p;
@@ -939,7 +933,12 @@
         goto LscanOct;
     }
 
+    ulong_ = p[-1];
+    isDecimal = true;
+    goto Lfinalize;
+
   LscanInteger:
+    isDecimal = true;
     while (isdigit(*++p))
     {
       if (*p == '_')
@@ -948,6 +947,7 @@
       {
         ulong_ *= 10;
         ulong_ += *p - '0';
+        continue;
       }
       // Overflow: skip following digits.
       overflow = true;
@@ -966,11 +966,12 @@
         break;
     case 'i', 'f', 'F', 'e', 'E':
       goto LscanReal;
+    default:
     }
+
     if (overflow)
       error(MID.OverflowDecimalNumber);
-    t.type = TOK.Number;
-//     ulong_ = toInt(t.span);
+
     assert((isdigit(p[-1]) || p[-1] == '_') && !isdigit(*p) && *p != '_');
     goto Lfinalize;
 
@@ -1009,6 +1010,7 @@
         break;
     case 'i', 'p', 'P':
       goto LscanReal;
+    default:
     }
     goto Lfinalize;
 
@@ -1072,23 +1074,70 @@
 //     goto Lfinalize;
 
   Lfinalize:
-    Suffix s;
+    enum Suffix
+    {
+      None     = 0,
+      Unsigned = 1,
+      Long     = 1<<1
+    }
+    Suffix suffix;
     while (1)
     {
       switch (*p)
       {
       case 'L':
-        if (s & Suffix.Long)
+        if (suffix & Suffix.Long)
           break;
-        s = Suffix.Long;
+        suffix = Suffix.Long;
         continue;
       case 'u', 'U':
-        if (s & Suffix.Unsigned)
+        if (suffix & Suffix.Unsigned)
           break;
-        s = Suffix.Unsigned;
+        suffix = Suffix.Unsigned;
+      default:
+        break;
       }
       break;
     }
+
+    switch (suffix)
+    {
+    case Suffix.None:
+      if (ulong_ & 0x8000000000000000)
+      {
+        if (isDecimal)
+          error(MID.OverflowDecimalSign);
+        t.type = TOK.Uint64;
+      }
+      else if (ulong_ & 0xFFFFFFFF00000000)
+        t.type = TOK.Int64;
+      else if (ulong_ & 0x80000000)
+        t.type = isDecimal ? TOK.Int64 : TOK.Uint32;
+      else
+        t.type = TOK.Int32;
+      break;
+    case Suffix.Unsigned:
+      if (ulong_ & 0xFFFFFFFF00000000)
+        t.type = TOK.Uint64;
+      else
+        t.type = TOK.Uint32;
+      break;
+    case Suffix.Long:
+      if (ulong_ & 0x8000000000000000)
+      {
+        if (isDecimal)
+          error(MID.OverflowDecimalSign);
+        t.type = TOK.Uint64;
+      }
+      else
+        t.type = TOK.Int64;
+      break;
+    case Suffix.Unsigned | Suffix.Long:
+      t.type = TOK.Uint64;
+      break;
+    default:
+      assert(0);
+    }
     t.ulong_ = ulong_;
     t.end = p;
     return;
--- a/trunk/src/Messages.d	Thu Jun 28 12:47:05 2007 +0000
+++ b/trunk/src/Messages.d	Fri Jun 29 05:47:00 2007 +0000
@@ -37,6 +37,7 @@
   UnterminatedHTMLEntity,
   InvalidBeginHTMLEntity,
   // integer overflows
+  OverflowDecimalSign,
   OverflowDecimalNumber,
   OverflowHexNumber,
   OverflowBinaryNumber,
@@ -74,6 +75,7 @@
   "unterminated html entity.",
   "html entities must begin with a letter.",
   // integer overflows
+  "decimal number overflows sign bit.",
   "overflow in decimal number.",
   "overflow in hexadecimal number.",
   "overflow in binary number.",
--- a/trunk/src/Token.d	Thu Jun 28 12:47:05 2007 +0000
+++ b/trunk/src/Token.d	Fri Jun 29 05:47:00 2007 +0000
@@ -16,7 +16,11 @@
   Comment,
   String,
   Character,
+
+  // Numbers
   Number,
+  Int32, Int64, Uint32, Uint64,
+
 
   // Brackets
   LParen,
--- a/trunk/src/format.css	Thu Jun 28 12:47:05 2007 +0000
+++ b/trunk/src/format.css	Fri Jun 29 05:47:00 2007 +0000
@@ -12,6 +12,7 @@
   margin: 1em;
 }
 compilerinfo error { display: block; }
+n { color: teal; }
 k { color: darkblue; font-weight: bold; }
 c[c=lc], c[c=bc] { color: green; }
 c[c=nc] { color: darkgreen; }
--- a/trunk/src/main.d	Thu Jun 28 12:47:05 2007 +0000
+++ b/trunk/src/main.d	Fri Jun 29 05:47:00 2007 +0000
@@ -112,7 +112,7 @@
       case TOK.Not:
         writef(`<op c="n">!</op>`);
       break;
-      case TOK.Number:
+      case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64:
         writef("<n>%s</n>", span);
       break;
       case TOK.LParen, TOK.RParen, TOK.LBracket,