| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Fri, 10 Oct 2025 10:18:05 +0100 | |
| changeset 1004 | 04353d465dfb | 
| parent 977 | 7a02c5b9e0df | 
| permissions | -rw-r--r-- | 
| 977 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 1 | // for testing tokenisation | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 2 | |
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 3 | import scala.util.{Try, Success, Failure}
 | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 4 | import $file.cw023_add | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 5 | import cw023_add._ | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 6 | |
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 7 | // programs to test (and number of toplevel definitions) | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 8 | val uprogs = List("collatz.while", 
 | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 9 | "collatz2.while", | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 10 | "factors.while", | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 11 | "fib.while", | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 12 | "loops.while", | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 13 | "primes.while") | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 14 | |
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 15 | for (file <- uprogs) {
 | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 16 | |
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 17 |   print(s"  Testing lexing with ${file.padTo(16, ' ')} ")
 | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 18 | val str = os.read(os.pwd / file) | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 19 | |
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 20 |   Try(test_string(str)) match {
 | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 21 |     case Success(v) => println(s"--> Success. Generated ${v.toString.take(30)}...")
 | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 22 | case Failure(e) => println(s"--> FAIL. Exception raised.") ; throw(e) | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 23 | } | 
| 
7a02c5b9e0df
updated marking scripts
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 24 | } |