diff -r 9b1c15c3eb6f -r f618dd4de24a progs/re3.scala --- a/progs/re3.scala Wed Sep 25 11:24:34 2019 +0100 +++ b/progs/re3.scala Wed Sep 25 23:56:36 2019 +0100 @@ -63,21 +63,10 @@ case c::s => ders(s, simp(der(c, r))) } -// the derivative w.r.t. a string (iterates der) -def dersp(s: List[Char], r: Rexp) : Rexp = s match { - case Nil => r - case c::s => dersp(s, der(c, r)) -} - // the main matcher function def matcher(r: Rexp, s: String) : Boolean = nullable(ders(s.toList, r)) -// tests -val q = SEQ(SEQ(CHAR('x'), CHAR('y')), CHAR('z')) -dersp("x".toList, q) -dersp("xy".toList, q) -dersp("xyz".toList, q) // one or zero def OPT(r: Rexp) = ALT(r, ONE) @@ -99,21 +88,13 @@ //test: (a?{n}) (a{n}) -for (i <- 1 to 7001 by 1000) { - println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL1(i), "a" * i)))) -} - -for (i <- 1 to 7001 by 1000) { - println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL1(i), "a" * i)))) +for (i <- 0 to 7000 by 1000) { + println(f"$i: ${time_needed(2, matcher(EVIL1(i), "a" * i))}%.5f") } //test: (a*)* b -for (i <- 1 to 6000001 by 500000) { - println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL2, "a" * i)))) -} - -for (i <- 1 to 6000001 by 500000) { - println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL2, "a" * i)))) +for (i <- 0 to 6000000 by 500000) { + println(f"$i: ${time_needed(2, matcher(EVIL2, "a" * i))}%.5f") }