--- a/progs/re4.scala Mon Feb 13 23:22:45 2017 +0000
+++ b/progs/re4.scala Wed Mar 15 01:24:39 2017 +0000
@@ -1,4 +1,6 @@
-
+// Version which attempts to move whole strings, not
+// just characters, under derivatives whenever possible
+
abstract class Rexp
case object ZERO extends Rexp
case object ONE extends Rexp
@@ -50,6 +52,7 @@
case r => r
}
+// *new*
// derivative w.r.t. a string (iterates der)
def ders2(s: List[Char], r: Rexp) : Rexp = (s, r) match {
case (Nil, r) => r
@@ -68,6 +71,9 @@
//one or zero
def OPT(r: Rexp) = ALT(r, ONE)
+
+// Test Cases
+
def EVIL1(n: Int) = SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))
val EVIL2 = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
@@ -79,7 +85,6 @@
(end - start)/(i * 1.0e9)
}
-// warmup
//test: (a?{n}) (a{n})
for (i <- 1 to 7000001 by 500000) {
println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL1(i), "a" * i))))