Before this patch, we accepted . as a synonym for zero. This is
probably not a good idea, and we may have better uses for it later.
---
 src/compiler/scanner.re  |    3 +-
 src/compiler/test/number |   59 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletions(-)
 create mode 100755 src/compiler/test/number

diff --git a/src/compiler/scanner.re b/src/compiler/scanner.re
index 951668b..df59d3f 100644
--- a/src/compiler/scanner.re
+++ b/src/compiler/scanner.re
@@ -64,7 +64,8 @@ int scan(struct scanner *s)
                                        { goto std; }
 
                [0-9]+                  { return TOK_CONSTANT; }
-               [0-9]* "." [0-9]*       { return TOK_CONSTANT; }
+               [0-9]+ "." [0-9]*       { return TOK_CONSTANT; }
+               [0-9]* "." [0-9]+       { return TOK_CONSTANT; }
 
                "above"                 { return TOK_ABOVE; }
                "abs"                   { return TOK_ABS; }
diff --git a/src/compiler/test/number b/src/compiler/test/number
new file mode 100755
index 0000000..db7fb10
--- /dev/null
+++ b/src/compiler/test/number
@@ -0,0 +1,59 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+ptest "number: a = 1" <<EOF
+a = 1
+EOF
+expect <<EOF
+a = 1
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "number: b = 1.2" <<EOF
+b = 1.2
+EOF
+expect <<EOF
+b = 1.2
+EOF
+
+#------------------------------------------------------------------------------
+#------------------------------------------------------------------------------
+
+ptest "number: c = .3" <<EOF
+c = .3
+EOF
+expect <<EOF
+c = 0.3
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "number: d = 4." <<EOF
+d = 4.
+EOF
+expect <<EOF
+d = 4
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "number: e = 51.23" <<EOF
+e = 51.23
+EOF
+expect <<EOF
+e = 51.23
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest_fail "number: f = ." <<EOF
+f = .
+EOF
+expect <<EOF
+FPVM: scan error
+EOF
+
+###############################################################################
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to