diff -r 940b6c68102a -r 72688efdf17c testing4/re.scala --- a/testing4/re.scala Thu Oct 31 11:33:02 2019 +0000 +++ b/testing4/re.scala Thu Oct 31 12:01:56 2019 +0000 @@ -1,7 +1,7 @@ -// Part 1 about Regular Expression Matching -//========================================== +// Core Part about Regular Expression Matching +//============================================= -//object CW9a { +object CW9c { // Regular Expressions abstract class Rexp @@ -125,23 +125,23 @@ // some testing data -/* -matcher(("a" ~ "b") ~ "c", "abc") // => true -matcher(("a" ~ "b") ~ "c", "ab") // => false + +//matcher(("a" ~ "b") ~ "c", "abc") // => true +//matcher(("a" ~ "b") ~ "c", "ab") // => false // the supposedly 'evil' regular expression (a*)* b val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b')) -matcher(EVIL, "a" * 1000 ++ "b") // => true -matcher(EVIL, "a" * 1000) // => false +//matcher(EVIL, "a" * 1000 ++ "b") // => true +//matcher(EVIL, "a" * 1000) // => false // size without simplifications -size(der('a', der('a', EVIL))) // => 28 -size(der('a', der('a', der('a', EVIL)))) // => 58 +//size(der('a', der('a', EVIL))) // => 28 +//size(der('a', der('a', der('a', EVIL)))) // => 58 // size with simplification -size(simp(der('a', der('a', EVIL)))) // => 8 -size(simp(der('a', der('a', der('a', EVIL))))) // => 8 +//size(simp(der('a', der('a', EVIL)))) // => 8 +//size(simp(der('a', der('a', der('a', EVIL))))) // => 8 // Python needs around 30 seconds for matching 28 a's with EVIL. // Java 9 and later increase this to an "astonishing" 40000 a's in @@ -158,12 +158,12 @@ (end - start)/(i * 1.0e9) } -for (i <- 0 to 5000000 by 500000) { - println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL, "a" * i)))) -} +//for (i <- 0 to 5000000 by 500000) { +// println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL, "a" * i))) + " secs.") +//} // another "power" test case -simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(100).next) == ONE +//simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(100).next) == ONE // the Iterator produces the rexp // @@ -171,6 +171,6 @@ // // where SEQ is nested 100 times. -*/ + -//} +}