diff -r d97283992d4f -r 15973df32613 solutions/cw3/parser.sc --- 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")