changeset 67:3fdf20b08a81 new_gen

Been working on the floating point parsing. Still a bit of work to do here.
author Anders Johnsen <skabet@gmail.com>
date Tue, 29 Apr 2008 20:15:22 +0200
parents c62c32e92fde
children 381975d76baf
files ast/Exp.d gen/CodeGen.d lexer/Lexer.d
diffstat 3 files changed, 65 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ast/Exp.d	Tue Apr 29 18:30:14 2008 +0200
+++ b/ast/Exp.d	Tue Apr 29 20:15:22 2008 +0200
@@ -1,6 +1,6 @@
 module ast.Exp;
 
-import tango.text.Util : jhash;
+import tango.text.Util;
 import tango.io.Stdout;
 
 import ast.Decl,
@@ -211,6 +211,12 @@
     {
         super(ExpType.IntegerLit);
         this.token = t;
+        this.name = substitute(t.get,"_","");
+    }
+
+    char[] get()
+    {
+        return name;
     }
     Exp simplify()
     {
@@ -220,6 +226,7 @@
     override DType type() { return DType.Int; }
 
     Token token;
+    char[] name;
 }
 
 class MemberReference : Exp
--- a/gen/CodeGen.d	Tue Apr 29 18:30:14 2008 +0200
+++ b/gen/CodeGen.d	Tue Apr 29 20:15:22 2008 +0200
@@ -225,7 +225,7 @@
 
             case ExpType.IntegerLit:
                 auto integetLit = cast(IntegerLit)exp;
-                auto val = integetLit.token.get;
+                auto val = integetLit.get;
                 return ConstantInt.GetS(Type.Int32, Integer.parse(val));
             case ExpType.Negate:
                 auto negateExp = cast(NegateExp)exp;
--- a/lexer/Lexer.d	Tue Apr 29 18:30:14 2008 +0200
+++ b/lexer/Lexer.d	Tue Apr 29 20:15:22 2008 +0200
@@ -33,7 +33,7 @@
 
 
         charTable.length = 256;
-        foreach( char c ; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
+        foreach( char c ; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")
             charTable[c] = CharType.Letter;
 
         foreach( char c ; "0123456789")
@@ -157,6 +157,17 @@
     }
     Token dot() 
     {
+        int pos = 0;
+        while(getNextChar(0) == CharType.Number || 
+              this.source.data[position + pos + 1] == '_')
+        {
+            if(getNextChar(0) == CharType.Number)
+            {
+                position--;
+                return lexNumber();
+            }
+            pos++;
+        }
         return Token(Tok.Dot, Location(position - 1, this.source), 1);
     }
     Token comma() 
@@ -253,9 +264,51 @@
     
     Token lexNumber ()
     {
+        bool sign = false;
+        bool dot = false;
+        bool e = false;
+
         int i = 0;
-        while(getNextChar(++i) == CharType.Number)
-        {}
+
+        bool end = false;
+        while(!end)
+        {
+            switch(getNextChar(i))
+            {
+                case CharType.Number:
+                    break;
+                case CharType.Symbol:
+                    if(this.source.data[position+i] == '.')
+                    {
+                        if(dot)
+                            throw error(__LINE__,"Only one '.' is allowed in an floating number")
+                                .tok(Token(Tok.Float, Location(position + i, this.source), 1));
+                        dot = true;
+                        break;
+                    }
+                    end = true;
+                    continue;
+                case CharType.Letter:
+                    if(this.source.data[position+i] == '_')
+                        break;
+                    if (this.source.data[position+i] == 'e' || 
+                        this.source.data[position+i] == 'E')
+                    {
+                        if (e)
+                            throw error(__LINE__,"Only one '"~this.source.data[position+i]
+                                    ~"' is allowed in an floating number");
+                        e = true;
+                        break;
+                    }
+                    end = true;
+                    continue;
+
+                default:
+                    end = true;
+                    continue;
+            }
+            i++;
+        }
 
         position += i;