author | cu |
Tue, 03 Oct 2017 23:35:16 +0100 | |
changeset 513 | 676e6484f29b |
parent 493 | 4e97783862ff |
child 547 | 81eb43c41416 |
permissions | -rw-r--r-- |
492 | 1 |
// CW 1 |
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
import scala.language.implicitConversions |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
import scala.language.reflectiveCalls |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
492 | 5 |
abstract class Rexp |
6 |
case object ZERO extends Rexp // matches nothing |
|
7 |
case object ONE extends Rexp // matches the empty string |
|
8 |
case class CHAR(c: Char) extends Rexp // matches a character c |
|
9 |
case class ALT(r1: Rexp, r2: Rexp) extends Rexp // alternative |
|
10 |
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp // sequence |
|
11 |
case class STAR(r: Rexp) extends Rexp // star |
|
12 |
case class RANGE(cs: Set[Char]) extends Rexp // set of characters |
|
13 |
case class PLUS(r: Rexp) extends Rexp // plus |
|
14 |
case class OPT(r: Rexp) extends Rexp // optional |
|
15 |
case class NTIMES(r: Rexp, n: Int) extends Rexp // n-times |
|
16 |
case class UPNTIMES(r: Rexp, n: Int) extends Rexp // up n-times |
|
17 |
case class FROMNTIMES(r: Rexp, n: Int) extends Rexp // from n-times |
|
18 |
case class NMTIMES(r: Rexp, n: Int, m: Int) extends Rexp // between nm-times |
|
19 |
case class NOT(r: Rexp) extends Rexp // not |
|
20 |
case class CFUN(f: Char => Boolean) extends Rexp // subsuming CHAR and RANGE |
|
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
// nullable function: tests whether the regular |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
// expression can recognise the empty string |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
def nullable (r: Rexp) : Boolean = r match { |
492 | 26 |
case ZERO => false |
27 |
case ONE => true |
|
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
case CHAR(_) => false |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
case ALT(r1, r2) => nullable(r1) || nullable(r2) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
case SEQ(r1, r2) => nullable(r1) && nullable(r2) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
case STAR(_) => true |
492 | 32 |
case RANGE(_) => false |
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
case PLUS(r) => nullable(r) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
case OPT(_) => true |
492 | 35 |
case NTIMES(r, n) => if (n == 0) true else nullable(r) |
36 |
case UPNTIMES(_, _) => true |
|
37 |
case FROMNTIMES(r, n) => if (n == 0) true else nullable(r) |
|
38 |
case NMTIMES(r, n, m) => if (n == 0) true else nullable(r) |
|
39 |
case NOT(r) => !(nullable(r)) |
|
40 |
case CFUN(_) => false |
|
208
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
41 |
} |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
42 |
|
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
// derivative of a regular expression w.r.t. a character |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
def der (c: Char, r: Rexp) : Rexp = r match { |
492 | 45 |
case ZERO => ZERO |
46 |
case ONE => ZERO |
|
47 |
case CHAR(d) => if (c == d) ONE else ZERO |
|
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
case ALT(r1, r2) => ALT(der(c, r1), der(c, r2)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
case SEQ(r1, r2) => |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
else SEQ(der(c, r1), r2) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
case STAR(r) => SEQ(der(c, r), STAR(r)) |
492 | 53 |
case RANGE(cs) => if (cs contains c) ONE else ZERO |
190
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
54 |
case PLUS(r) => SEQ(der(c, r), STAR(r)) |
492 | 55 |
case OPT(r) => der(c, r) |
56 |
case NTIMES(r, n) => |
|
57 |
if (n == 0) ZERO else SEQ(der(c, r), NTIMES(r, n - 1)) |
|
58 |
case UPNTIMES(r, n) => |
|
59 |
if (n == 0) ZERO else SEQ(der(c, r), UPNTIMES(r, n - 1)) |
|
60 |
case FROMNTIMES(r, n) => |
|
61 |
if (n == 0) ZERO else SEQ(der(c, r), FROMNTIMES(r, n - 1)) |
|
62 |
case NMTIMES(r, n, m) => |
|
63 |
if (m < n) ZERO else |
|
64 |
if (n == 0 && m == 0) ZERO else |
|
65 |
if (n == 0) SEQ(der(c, r), UPNTIMES(r, m - 1)) |
|
66 |
else SEQ(der(c, r), NMTIMES(r, n - 1, m - 1)) |
|
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
case NOT(r) => NOT(der (c, r)) |
492 | 68 |
case CFUN(f) => if (f(c)) ONE else ZERO |
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
} |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
|
492 | 71 |
def simp(r: Rexp) : Rexp = r match { |
72 |
case ALT(r1, r2) => (simp(r1), simp(r2)) match { |
|
73 |
case (ZERO, r2s) => r2s |
|
74 |
case (r1s, ZERO) => r1s |
|
75 |
case (r1s, r2s) => if (r1s == r2s) r1s else ALT (r1s, r2s) |
|
76 |
} |
|
77 |
case SEQ(r1, r2) => (simp(r1), simp(r2)) match { |
|
78 |
case (ZERO, _) => ZERO |
|
79 |
case (_, ZERO) => ZERO |
|
80 |
case (ONE, r2s) => r2s |
|
81 |
case (r1s, ONE) => r1s |
|
82 |
case (r1s, r2s) => SEQ(r1s, r2s) |
|
83 |
} |
|
84 |
case r => r |
|
85 |
} |
|
86 |
||
87 |
||
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
// derivative w.r.t. a string (iterates der) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
def ders (s: List[Char], r: Rexp) : Rexp = s match { |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
case Nil => r |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
case c::s => ders(s, der(c, r)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
} |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
def ders_simp (s: List[Char], r: Rexp) : Rexp = s match { |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
case Nil => r |
492 | 96 |
case c::s => ders_simp(s, simp(der(c, r))) |
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
} |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
|
492 | 99 |
// main matcher function including simplification |
100 |
def matcher(r: Rexp, s: String) : Boolean = |
|
101 |
nullable(ders_simp(s.toList, r)) |
|
102 |
||
103 |
||
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
// some convenience for typing in regular expressions |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
def charlist2rexp(s : List[Char]) : Rexp = s match { |
492 | 107 |
case Nil => ONE |
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
case c::Nil => CHAR(c) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
case c::s => SEQ(CHAR(c), charlist2rexp(s)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
} |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
implicit def string2rexp(s : String) : Rexp = charlist2rexp(s.toList) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
implicit def RexpOps (r: Rexp) = new { |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
def | (s: Rexp) = ALT(r, s) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
def % = STAR(r) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
def ~ (s: Rexp) = SEQ(r, s) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
} |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
implicit def stringOps (s: String) = new { |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
def | (r: Rexp) = ALT(s, r) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
def | (r: String) = ALT(s, r) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
def % = STAR(s) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
def ~ (r: Rexp) = SEQ(s, r) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
def ~ (r: String) = SEQ(s, r) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
} |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
|
492 | 127 |
val r1 = NTIMES("a", 3) |
128 |
val r2 = NTIMES(OPT("a"), 3) |
|
129 |
val r3 = UPNTIMES("a", 3) |
|
130 |
val r4 = UPNTIMES(OPT("a"), 3) |
|
131 |
val r5 = NMTIMES("a", 3, 5) |
|
132 |
val r6 = NMTIMES(OPT("a"), 3, 5) |
|
133 |
||
134 |
val rs = List(r1, r2, r3, r4, r5, r6) |
|
135 |
||
136 |
rs.map(matcher(_, "")) |
|
137 |
rs.map(matcher(_, "a")) |
|
138 |
rs.map(matcher(_, "aa")) |
|
139 |
rs.map(matcher(_, "aaa")) |
|
140 |
rs.map(matcher(_, "aaaa")) |
|
141 |
rs.map(matcher(_, "aaaaa")) |
|
142 |
rs.map(matcher(_, "aaaaaa")) |
|
143 |
||
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
println("EMAIL:") |
492 | 145 |
val LOWERCASE = ('a' to 'z').toSet |
146 |
val DIGITS = ('0' to '9').toSet |
|
147 |
val EMAIL = { PLUS(CFUN(LOWERCASE | DIGITS | ("_.-").toSet)) ~ "@" ~ |
|
148 |
PLUS(CFUN(LOWERCASE | DIGITS | (".-").toSet)) ~ "." ~ |
|
149 |
NMTIMES(CFUN(LOWERCASE | Set('.')), 2, 6) } |
|
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
150 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
val my_email = "christian.urban@kcl.ac.uk" |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
152 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
153 |
println(EMAIL); |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
println(matcher(EMAIL, my_email)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
155 |
println(ders_simp(my_email.toList, EMAIL)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
156 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
157 |
println("COMMENTS:") |
492 | 158 |
val ALL = CFUN((c:Char) => true) |
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
val COMMENT = "/*" ~ (NOT(ALL.% ~ "*/" ~ ALL.%)) ~ "*/" |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
println(matcher(COMMENT, "/**/")) |
493 | 162 |
println(matcher(COMMENT, "/*foobar*/")) |
189
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
println(matcher(COMMENT, "/*test*/test*/")) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
println(matcher(COMMENT, "/*test/*test*/")) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
165 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
println("EVILS:") |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
167 |
val EVIL1 = PLUS(PLUS("a" ~ "a" ~ "a")) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
168 |
val EVIL2 = PLUS(PLUS("aaaaaaaaaaaaaaaaaaa" ~ OPT("a"))) // 19 as ~ a? |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
170 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
171 |
//40 * aaa matches |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
172 |
//43 * aaa + aa does not |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
173 |
//45 * aaa + a |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
|
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
println("EVIL1:") |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
176 |
println(matcher(EVIL1, "aaa" * 40)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
println(matcher(EVIL1, "aaa" * 43 + "aa")) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
println(matcher(EVIL1, "aaa" * 45 + "a")) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
179 |
println("EVIL2:") |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
180 |
println(matcher(EVIL2, "aaa" * 40)) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
println(matcher(EVIL2, "aaa" * 43 + "aa")) |
04346d82fe01
added cw1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
182 |
println(matcher(EVIL2, "aaa" * 45 + "a")) |
190
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
183 |
|
192
9f0631804555
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
184 |
println("TEST for bug pointed out by Filips Ivanovs") |
493 | 185 |
val test = NMTIMES(CFUN(LOWERCASE | Set('.')), 2, 6) |
190
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
186 |
|
192
9f0631804555
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
187 |
println(matcher(test,"a")) |
190
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
188 |
println(matcher(test,"ab")) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
189 |
println(matcher(test,"abcdef")) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
190 |
println(matcher(test,"abc")) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
191 |
println(matcher(test,"....")) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
192 |
println(matcher(test,"asdfg")) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
193 |
println(matcher(test,"abcdefg")) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
194 |
|
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
195 |
println(test) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
196 |
println(ders_simp("a".toList, test)) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
197 |
println(ders_simp("aa".toList, test)) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
198 |
println(ders_simp("aaa".toList, test)) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
199 |
println(ders_simp("aaaa".toList, test)) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
200 |
println(ders_simp("aaaaa".toList, test)) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
201 |
println(ders_simp("aaaaaa".toList, test)) |
0b63c0edfb09
added new version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
189
diff
changeset
|
202 |
println(ders_simp("aaaaaaa".toList, test)) |
208
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
203 |
|
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
204 |
def TEST(s: String, r: Rexp) = { |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
205 |
println("Rexp |" + s + "|") |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
206 |
println("Derivative:\n" + ders_simp(s.toList, r)) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
207 |
println("Is Nullable: " + nullable(ders_simp(s.toList, r))) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
208 |
Console.readLine |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
209 |
} |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
210 |
|
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
211 |
|
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
212 |
val ALL2 = "a" | "f" |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
213 |
val COMMENT2 = ("/*" ~ NOT(ALL2.% ~ "*/" ~ ALL2.%) ~ "*/") |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
214 |
|
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
215 |
println("1) TEST TEST") |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
216 |
TEST("", COMMENT2) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
217 |
TEST("/", COMMENT2) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
218 |
TEST("/*", COMMENT2) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
219 |
TEST("/*f", COMMENT2) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
220 |
TEST("/*f*", COMMENT2) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
221 |
TEST("/*f*/", COMMENT2) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
222 |
TEST("/*f*/ ", COMMENT2) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
223 |
|
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
224 |
val ALL3 = "a" | "f" |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
225 |
val COMMENT3 = ("/" ~ NOT(ALL3.% ~ "&" ~ ALL3.%) ~ "&") |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
226 |
|
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
227 |
println("2) TEST TEST") |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
228 |
TEST("", COMMENT3) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
229 |
TEST("/", COMMENT3) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
230 |
TEST("/", COMMENT3) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
231 |
TEST("/f", COMMENT3) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
232 |
TEST("/f&", COMMENT3) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
233 |
TEST("/f& ", COMMENT3) |
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
192
diff
changeset
|
234 |