--- a/progs/scala/re-ext.scala Sat Mar 11 12:50:01 2017 +0000
+++ b/progs/scala/re-ext.scala Sat Mar 11 19:33:38 2017 +0000
@@ -2,6 +2,7 @@
import scala.language.reflectiveCalls
import scala.annotation.tailrec
import scala.io.Source
+import scala.util._
abstract class Rexp
case object ZERO extends Rexp
@@ -157,7 +158,8 @@
case c::cs => inj(r, c, lex(der(c, r), cs))
}
-import scala.util._
+
+
def lexing(r: Rexp, s: String) : Try[Val] = Try(lex(r, s.toList))
@@ -218,7 +220,7 @@
}
}
-def lexing_simp(r: Rexp, s: String) : Val = lex_simp(r, s.toList)
+def lexing_simp(r: Rexp, s: String) : Try[Val] = Try(lex_simp(r, s.toList))
// Some Tests
@@ -249,10 +251,11 @@
val ALL = CHARS((c) => true)
val reg = ALL.% ~ "a" ~ NTIMES(ALL, 3) ~ "bc"
-println(lexing(reg, "axaybzbc")) // true
-println(lexing(reg, "aaaaxaybzbc")) // true
-println(nullable(ders("axaybzbd".toList, reg))) // false
-println(lexing(reg, "axaybzbd")) // false
+println(lexing(reg, "axaybzbc")) // true
+println(lexing(reg, "aaaaxaybzbc")) // true
+
+println(nullable(ders("axaybzbd".toList, reg))) // false
+println(lexing(reg, "axaybzbd")) // false
@@ -302,12 +305,12 @@
println("prog0 test")
val prog0 = """read n"""
-println(env(lexing_simp(WHILE_REGS, prog0)))
+println(env(lexing_simp(WHILE_REGS, prog0).get))
println("prog1 test")
val prog1 = """read n; write (n)"""
-println(env(lexing_simp(WHILE_REGS, prog1)))
+println(env(lexing_simp(WHILE_REGS, prog1).get))
// Bigger Test
@@ -327,7 +330,15 @@
}"""
println("prog2 test - tokens")
-println(env(lexing_simp(WHILE_REGS, prog2)))
+println(env(lexing_simp(WHILE_REGS, prog2).get))
+
+
+// replicate prog2
+
+println("prog2 replicated test")
+for (i <- 1 to 88 by 5) {
+ println(i + ": " + "%.5f".format(time_needed(2, lexing_simp(WHILE_REGS, prog2 * i))))
+}
val prog3 = """
@@ -346,13 +357,9 @@
"""
println("prog3 test - tokens")
-println(env(lexing_simp(WHILE_REGS, prog3)))
-
-println("prog2 replicated test")
+println(env(lexing_simp(WHILE_REGS, prog3).get))
-for (i <- 1 to 88) {
- println(i + ": " + "%.5f".format(time_needed(2, lexing_simp(WHILE_REGS, prog2 * i))))
-}
+
// Sulzmann's tests
@@ -377,7 +384,7 @@
val reWord = CHARS("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" contains _)
val reWordStar = STAR(reWord)
-val reWordPlus = reWord ~ reWordStar
+val reWordPlus = PLUS(reWord)
val optionSet1 = "-" | "+" | "."
val optionSet2 = "-" | "."
val atTheRate = "@"