--- a/progs/thompson.scala Sun May 07 00:20:58 2017 +0100
+++ b/progs/thompson.scala Sun May 07 03:01:29 2017 +0100
@@ -60,12 +60,12 @@
// alternative of two NFAs
def NFA_ALT(enfa1: NFAt, enfa2: NFAt) : NFAt = {
- val Q = TState()
- val new_delta : eNFAtrans =
- { case (Q, None) => enfa1.starts | enfa2.starts }
+ val new_delta : NFAtrans = {
+ case (q, c) => applyOrElse(enfa1.delta, (q, c)) |
+ applyOrElse(enfa2.delta, (q, c)) }
val new_fins = (q: TState) => enfa1.fins(q) || enfa2.fins(q)
- eNFA(Set(Q), new_delta +++ enfa1.delta +++ enfa2.delta, new_fins)
+ NFA(enfa1.starts | enfa2.starts, new_delta, new_fins)
}
// star of a NFA
@@ -124,10 +124,10 @@
// the evil regular expression a?{n} a{n}
-def EVIL1(n: Int) = SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))
+def EVIL1(n: Int) : Rexp = SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))
// the evil regular expression (a*)*b
-val EVIL2 = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
+val EVIL2 : Rexp = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
//for measuring time
def time_needed[T](i: Int, code: => T) = {
@@ -140,11 +140,11 @@
// the size of the NFA can be large,
// thus slowing down the breadth-first search
-for (i <- 1 to 10) {
+for (i <- 1 to 13) {
println(i + ": " + "%.5f".format(time_needed(2, tmatches(EVIL1(i), "a" * i))))
}
-for (i <- 1 to 10) {
+for (i <- 1 to 100 by 5) {
println(i + " " + "%.5f".format(time_needed(2, tmatches(EVIL2, "a" * i))))
}