# HG changeset patch # User Anders Johnsen # Date 1209492922 -7200 # Node ID 3fdf20b08a81154ad918f28ad58042a112659cb0 # Parent c62c32e92fde91a921540af49589d277f89c84b8 Been working on the floating point parsing. Still a bit of work to do here. diff -r c62c32e92fde -r 3fdf20b08a81 ast/Exp.d --- 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 diff -r c62c32e92fde -r 3fdf20b08a81 gen/CodeGen.d --- 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; diff -r c62c32e92fde -r 3fdf20b08a81 lexer/Lexer.d --- 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;