cw5_marking/c1.sc
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 03 Feb 2025 12:34:38 +0000
changeset 978 8778d23fef92
permissions -rw-r--r--
updated marking scripts

// for testing tokenisation

import scala.util.{Try, Success, Failure}
import $file.cw05_add
import cw05_add._

// programs to tokenise (and how many tokens) 
val uprogs = List(("fact.fun",  113), 
                  ("hanoi.fun", 92),
		  ("mand.fun",  226),
		  ("mand2.fun", 245),
		  ("sqr.fun",   78))

for ((file, no) <- uprogs) {

  print(s"Testing tokenisation of $file ")
  val str = os.read(os.pwd / file)

  Try(test_string(str)) match {
    case Success(v) => println(s"--> Success. Lexed tokens.")
    //case Success(v) => println(s"--> Success? Lexed ${v.length} tokens (should be $no).\n $v") ; throw new Exception("Different")
    case Failure(e) => println(s"--> FAIL. Exception raised.") ; throw(e)
  }
}