aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front/lexer.rs
diff options
context:
space:
mode:
authorTim Chevalier <[email protected]>2011-03-21 17:12:05 -0700
committerGraydon Hoare <[email protected]>2011-03-21 18:10:34 -0700
commitcaa22c93415bb106bced82bbabc3d9ffbef7e69c (patch)
tree2a77dc7cfb33c82dcdc83a69a423ebc4340e576e /src/comp/front/lexer.rs
parentSupport CFG_LLVM_ROOT since CMake-built LLVM has no llvm-config (diff)
downloadrust-caa22c93415bb106bced82bbabc3d9ffbef7e69c.tar.xz
rust-caa22c93415bb106bced82bbabc3d9ffbef7e69c.zip
Started adding support for floating-point type, floating-point literals, and logging of floats. Other operations on float probably don't work yet.
Diffstat (limited to 'src/comp/front/lexer.rs')
-rw-r--r--src/comp/front/lexer.rs48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/comp/front/lexer.rs b/src/comp/front/lexer.rs
index 403558e2..d4948503 100644
--- a/src/comp/front/lexer.rs
+++ b/src/comp/front/lexer.rs
@@ -1,5 +1,6 @@
import std.io;
import std._str;
+import std._int;
import std.map;
import std.map.hashmap;
import util.common;
@@ -314,6 +315,24 @@ impure fn consume_block_comment(reader rdr) {
be consume_any_whitespace(rdr);
}
+impure fn scan_dec_digits(reader rdr) -> int {
+
+ auto c = rdr.curr();
+
+ let int accum_int = 0;
+
+ while (is_dec_digit(c) || c == '_') {
+ if (c != '_') {
+ accum_int *= 10;
+ accum_int += dec_digit_val(c);
+ }
+ rdr.bump();
+ c = rdr.curr();
+ }
+
+ ret accum_int;
+}
+
impure fn scan_number(mutable char c, reader rdr) -> token.token {
auto accum_int = 0;
auto n = rdr.next();
@@ -330,9 +349,7 @@ impure fn scan_number(mutable char c, reader rdr) -> token.token {
rdr.bump();
c = rdr.curr();
}
- }
-
- if (c == '0' && n == 'b') {
+ } else if (c == '0' && n == 'b') {
rdr.bump();
rdr.bump();
c = rdr.curr();
@@ -344,16 +361,12 @@ impure fn scan_number(mutable char c, reader rdr) -> token.token {
rdr.bump();
c = rdr.curr();
}
+ } else {
+ accum_int = scan_dec_digits(rdr);
}
- while (is_dec_digit(c) || c == '_') {
- if (c != '_') {
- accum_int *= 10;
- accum_int += dec_digit_val(c);
- }
- rdr.bump();
- c = rdr.curr();
- }
+ c = rdr.curr();
+ n = rdr.next();
if (c == 'u' || c == 'i') {
let bool signed = (c == 'i');
@@ -405,7 +418,18 @@ impure fn scan_number(mutable char c, reader rdr) -> token.token {
ret token.LIT_UINT(accum_int as uint);
}
}
- ret token.LIT_INT(accum_int);
+ n = rdr.curr();
+ if(n == '.') {
+ // Parse a floating-point number.
+ rdr.bump();
+ auto accum_int1 = scan_dec_digits(rdr);
+ ret token.LIT_FLOAT(_int.to_str(accum_int, 10u) + "."
+ + _int.to_str(accum_int1, 10u));
+ // FIXME: Parse exponent.
+ }
+ else {
+ ret token.LIT_INT(accum_int);
+ }
}
impure fn next_token(reader rdr) -> token.token {