solutions/cw3/parser.sc
changeset 905 15973df32613
parent 894 02ef5c3abc51
child 919 53f08d873e09
--- a/solutions/cw3/parser.sc	Fri Dec 09 13:18:10 2022 +0000
+++ b/solutions/cw3/parser.sc	Wed Dec 21 14:33:05 2022 +0000
@@ -159,14 +159,14 @@
 
 // Testing with programs 2 & 3
 
-println("Fibonacci")
-println(Stmts.parse_all(tokenise(os.read(os.pwd / "fib.while"))))
+//println("Fibonacci")
+//println(Stmts.parse_all(tokenise(os.read(os.pwd / "fib.while"))))
 
-println("Loops")
-println(Stmts.parse_all(tokenise(os.read(os.pwd / "loops.while"))))
+//println("Loops")
+//println(Stmts.parse_all(tokenise(os.read(os.pwd / "loops.while"))))
 
-println("Collatz")
-println(Stmts.parse_all(tokenise(os.read(os.pwd / "collatz2.while"))))
+//println("Collatz")
+//println(Stmts.parse_all(tokenise(os.read(os.pwd / "collatz2.while"))))
 
 
 // Interpreter
@@ -226,15 +226,16 @@
 
 def eval(bl: Block) : Env = eval_bl(bl, Map())
 
-println("Primes eval")
-println(tokenise(os.read(os.pwd / "primes.while")))
-println(eval(Stmts.parse_all(tokenise(os.read(os.pwd / "primes.while"))).head))
-
-println("Factors eval")
-println(eval(Stmts.parse_all(tokenise(os.read(os.pwd / "factors.while"))).head))
-
-println("Collatz2 eval")
-println(eval(Stmts.parse_all(tokenise(os.read(os.pwd / "collatz2.while"))).head))
+@main
+def main(file: String) = {
+  val contents = os.read(os.pwd / file)
+  println(s"Lex $file: ")
+  println(tokenise(contents))
+  println(s"Parse $file: ")
+  println(Stmts.parse_all(tokenise(contents)).head)
+  println(s"Eval $file: ")
+  println(eval(Stmts.parse_all(tokenise(contents)).head))
+}
 
 /*
 println("Loops eval")