--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fib.while Fri Nov 23 19:28:10 2012 +0000
@@ -0,0 +1,12 @@
+{ n := 9;
+ minus1 := 0;
+ minus2 := 1;
+ temp := 0;
+ while n > 0 do {
+ temp := minus2;
+ minus2 := minus1 + minus2;
+ minus1 := temp;
+ n := n - 1
+ };
+ fib_res := minus2
+}
--- a/while.scala Fri Nov 23 15:17:17 2012 +0000
+++ b/while.scala Fri Nov 23 19:28:10 2012 +0000
@@ -173,23 +173,21 @@
val p4_ast = Block.parse_all(p4_toks)
println(p4_ast)
-// fibonacci numbers
-val p5 =
-"""{ n := 9;
- minus1 := 0;
- minus2 := 1;
- temp := 0;
- while n > 0 do {
- temp := minus2;
- minus2 := minus1 + minus2;
- minus1 := temp;
- n := n - 1
- };
- fib_res := minus2
- }
+val p5 = """
+ n := 9;
+ minus1 := 0;
+ minus2 := 1;
+ temp := 0;
+ while n > 0 do {
+ temp := minus2;
+ minus2 := minus1 + minus2;
+ minus1 := temp;
+ n := n - 1
+ };
+ fib_res := minus2
"""
val p5_toks = Tok.fromString(p5)
-val p5_ast = Block.parse_all(p5_toks)
+val p5_ast = Stmts.parse_all(p5_toks)
// interpreter
type Env = Map[String, Int]