# HG changeset patch
# User aziz
# Date 1183096020 0
# Node ID 50bb7fc9db44b1f9ac6602489b28f11c6ab7c342
# Parent c0f1c8be3a471ef47bf0c48d73bab8da4279bd2a
- The types of integers are recognized now.
- Fix: continue statement missing in integer scanner.
diff -r c0f1c8be3a47 -r 50bb7fc9db44 trunk/src/Lexer.d
--- 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;
diff -r c0f1c8be3a47 -r 50bb7fc9db44 trunk/src/Messages.d
--- 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.",
diff -r c0f1c8be3a47 -r 50bb7fc9db44 trunk/src/Token.d
--- 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,
diff -r c0f1c8be3a47 -r 50bb7fc9db44 trunk/src/format.css
--- 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; }
diff -r c0f1c8be3a47 -r 50bb7fc9db44 trunk/src/main.d
--- 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(`!`);
break;
- case TOK.Number:
+ case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64:
writef("%s", span);
break;
case TOK.LParen, TOK.RParen, TOK.LBracket,