--- a/progs/re3.scala Sat Dec 29 10:30:27 2018 +0000
+++ b/progs/re3.scala Tue Feb 12 21:23:00 2019 +0000
@@ -58,15 +58,26 @@
// derivative w.r.t. a string (iterates der)
-def ders (s: List[Char], r: Rexp) : Rexp = s match {
+def ders(s: List[Char], r: Rexp) : Rexp = s match {
case Nil => r
case c::s => ders(s, simp(der(c, r)))
}
+// 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))
+}
+
// 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)