equal
deleted
inserted
replaced
18 case ZERO => ZERO |
18 case ZERO => ZERO |
19 case ONE => ZERO |
19 case ONE => ZERO |
20 case CHAR(d) => if (c == d) ONE else ZERO |
20 case CHAR(d) => if (c == d) ONE else ZERO |
21 case ALT(r1, r2) => ALT(der_urban(c, r1), der_urban(c, r2)) |
21 case ALT(r1, r2) => ALT(der_urban(c, r1), der_urban(c, r2)) |
22 case SEQ(r1, r2) => |
22 case SEQ(r1, r2) => |
23 if (nullable(r1)) ALT(SEQ(der_urban(c, r1), r2), der_urban(c, r2)) |
23 if (nullable_urban(r1)) ALT(SEQ(der_urban(c, r1), r2), der_urban(c, r2)) |
24 else SEQ(der_urban(c, r1), r2) |
24 else SEQ(der_urban(c, r1), r2) |
25 case STAR(r1) => SEQ(der_urban(c, r1), STAR(r1)) |
25 case STAR(r1) => SEQ(der_urban(c, r1), STAR(r1)) |
26 } |
26 } |
27 |
27 |
28 def simp_urban(r: Rexp) : Rexp = r match { |
28 def simp_urban(r: Rexp) : Rexp = r match { |
39 case (r1s, r2s) => SEQ(r1s, r2s) |
39 case (r1s, r2s) => SEQ(r1s, r2s) |
40 } |
40 } |
41 case r => r |
41 case r => r |
42 } |
42 } |
43 |
43 |
|
44 import scala.annotation.tailrec |
|
45 |
|
46 @tailrec |
|
47 def iterT_urban[A](n: Int, f: A => A, x: A): A = |
|
48 if (n == 0) x else iterT_urban(n - 1, f, f(x)) |
|
49 |
44 |
50 |
45 lazy val f = Future { |
51 lazy val f = Future { |
46 assert(size(iterT(20, (r: Rexp) => der_urban('a', r), EVIL_urban)) == 7340068) |
52 assert(size(iterT_urban(20, (r: Rexp) => der_urban('a', r), EVIL_urban)) == 7340068) |
47 assert(size(iterT(20, (r: Rexp) => simp_urban(der_urban('a', r)), EVIL_urban)) == 8) |
53 assert(size(iterT_urban(20, (r: Rexp) => simp_urban(der_urban('a', r)), EVIL_urban)) == 8) |
48 } |
54 } |
49 |
55 |
50 Await.result(f, 120 second) |
56 Await.result(f, 90 second) |