| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Sun, 19 Oct 2025 09:51:35 +0200 | |
| changeset 1011 | 047349fdf163 | 
| 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.cw05_add  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
5  | 
import cw05_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 tokenise (and how many tokens)  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
8  | 
val uprogs = List(("fact.fun",  113), 
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
9  | 
                  ("hanoi.fun", 92),
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
10  | 
		  ("mand.fun",  226),
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
11  | 
		  ("mand2.fun", 245),
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
12  | 
		  ("sqr.fun",   78))
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
13  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
14  | 
for ((file, no) <- uprogs) {
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
15  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
16  | 
print(s"Testing tokenisation of $file ")  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
17  | 
val str = os.read(os.pwd / file)  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
18  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
19  | 
  Try(test_string(str)) match {
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
20  | 
case Success(v) => println(s"--> Success. Lexed tokens.")  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
21  | 
    //case Success(v) => println(s"--> Success? Lexed ${v.length} tokens (should be $no).\n $v") ; throw new Exception("Different")
 | 
| 
 
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  | 
}  |