equal
deleted
inserted
replaced
12 |
12 |
13 |
13 |
14 // some students eliminated "..." therefore a specific comparison function |
14 // some students eliminated "..." therefore a specific comparison function |
15 def lsteq(xs: List[Token], ys: List[Token]): Boolean = (xs, ys) match { |
15 def lsteq(xs: List[Token], ys: List[Token]): Boolean = (xs, ys) match { |
16 case (Nil, Nil) => true |
16 case (Nil, Nil) => true |
|
17 //case (T_STRING("\n")::xs, T_STRING("""\n""")::ys) => lsteq(xs, ys) |
17 case (T_STRING(s1)::xs, T_STRING(s2)::ys) => |
18 case (T_STRING(s1)::xs, T_STRING(s2)::ys) => |
18 (s1 == s2 || s2.drop(1).dropRight(1) == s1) && lsteq(xs, ys) |
19 (s1 == s2 || s2.drop(1).dropRight(1) == s1) && lsteq(xs, ys) |
19 case (x::xs, y::ys) => x == y && lsteq(xs, ys) |
20 case (x::xs, y::ys) => x == y && lsteq(xs, ys) |
20 case _ => false |
21 case _ => false |
21 } |
22 } |
115 val str = os.read(os.pwd / "collatz2.while") |
116 val str = os.read(os.pwd / "collatz2.while") |
116 |
117 |
117 Try(test_string(str)) match { |
118 Try(test_string(str)) match { |
118 case Success(v) if lsteq(v, tks) |
119 case Success(v) if lsteq(v, tks) |
119 => println(s" Generated the correct token sequence.") |
120 => println(s" Generated the correct token sequence.") |
120 case Success(v) => println(s" Generated $v\n instead of\n $tks\n\n${listcmp(v, tks)}).") ; throw new Exception("Different") |
121 case Success(v) => println(s" Generated\n $v\n\n instead of\n $tks\n\n).") ; throw new Exception("Different") |
121 case Failure(e) => println(s" Exception raised.") ; throw(e) |
122 case Failure(e) => println(s" Exception raised.") ; throw(e) |
122 } |
123 } |
123 |
124 |