updated
authorChristian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 04 Oct 2016 12:00:23 +0100
changeset 440 e14cd32ad497
parent 439 7611ace6a93b
child 441 028816884f70
updated
progs/re1.scala
progs/re2.scala
progs/re3.scala
--- a/progs/re1.scala	Mon Oct 03 20:35:25 2016 +0100
+++ b/progs/re1.scala	Tue Oct 04 12:00:23 2016 +0100
@@ -26,7 +26,7 @@
   case SEQ(r1, r2) => 
     if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
     else SEQ(der(c, r1), r2)
-  case STAR(r) => SEQ(der(c, r), STAR(r))
+  case STAR(r1) => SEQ(der(c, r1), STAR(r1))
 }
 
 // derivative w.r.t. a string (iterates der)
@@ -58,7 +58,7 @@
 def EVIL1(n: Int) = SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))
 
 // the evil regular expression (a*)*b
-val EVIL2 = SEQ(STAR(CHAR('a')), CHAR('b'))
+val EVIL2 = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
 
 //for measuring time
 def time_needed[T](i: Int, code: => T) = {
@@ -78,11 +78,11 @@
 }
 
 //test: (a*)* b
-for (i <- 1 to 6502 by 500) {
+for (i <- 1 to 20) {
   println(i + " " + "%.5f".format(time_needed(2, matches(EVIL2, "a" * i))))
 }
 
-for (i <- 1 to 6502 by 500) {
+for (i <- 1 to 20) {
   println(i + " " + "%.5f".format(time_needed(2, matches(EVIL2, "a" * i))))
 }
 
--- a/progs/re2.scala	Mon Oct 03 20:35:25 2016 +0100
+++ b/progs/re2.scala	Tue Oct 04 12:00:23 2016 +0100
@@ -27,9 +27,9 @@
   case SEQ(r1, r2) => 
     if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
     else SEQ(der(c, r1), r2)
-  case STAR(r) => SEQ(der(c, r), STAR(r))
-  case NTIMES(r, i) => 
-    if (i == 0) ZERO else SEQ(der(c, r), NTIMES(r, i - 1))
+  case STAR(r1) => SEQ(der(c, r1), STAR(r1))
+  case NTIMES(r1, i) => 
+    if (i == 0) ZERO else SEQ(der(c, r1), NTIMES(r1, i - 1))
 }
 
 def ders (s: List[Char], r: Rexp) : Rexp = s match {
@@ -45,7 +45,7 @@
 
 //evil regular expressions
 def EVIL1(n: Int) = SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))
-val EVIL2 = SEQ(STAR(CHAR('a')), CHAR('b'))
+val EVIL2 = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
 
 def time_needed[T](i: Int, code: => T) = {
   val start = System.nanoTime()
@@ -65,11 +65,11 @@
 }
 
 //test: (a*)* b
-for (i <- 1 to 4501 by 500) {
+for (i <- 1 to 20) {
   println(i + " " + "%.5f".format(time_needed(2, matches(EVIL2, "a" * i))))
 }
 
-for (i <- 1 to 4501 by 500) {
+for (i <- 1 to 20) {
   println(i + " " + "%.5f".format(time_needed(2, matches(EVIL2, "a" * i))))
 }
 
--- a/progs/re3.scala	Mon Oct 03 20:35:25 2016 +0100
+++ b/progs/re3.scala	Tue Oct 04 12:00:23 2016 +0100
@@ -29,7 +29,7 @@
   case SEQ(r1, r2) => 
     if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
     else SEQ(der(c, r1), r2)
-  case STAR(r) => SEQ(der(c, r), STAR(r))
+  case STAR(r1) => SEQ(der(c, r1), STAR(r1))
   case NTIMES(r, i) => 
     if (i == 0) ZERO else SEQ(der(c, r), NTIMES(r, i - 1))
 }
@@ -68,7 +68,7 @@
 
 //evil regular expressions
 def EVIL1(n: Int) = SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))
-val EVIL2 = SEQ(STAR(CHAR('a')), CHAR('b'))
+val EVIL2 = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
 
 
 def time_needed[T](i: Int, code: => T) = {