--- a/progs/scala/re-basic.scala Wed Sep 18 16:35:57 2019 +0100
+++ b/progs/scala/re-basic.scala Sat Oct 24 12:13:39 2020 +0100
@@ -92,6 +92,31 @@
case c::s => ders(s, der(c, r))
}
+
+def closed_seq_ders()
+
+def ders2(s: List[Char], r: Rexp) : Rexp = (s, r) match {
+ case (Nil, r) => r
+ case (s, ZERO) => ZERO
+ case (s, ONE) => if (s == Nil) ONE else ZERO
+ case (s, CHAR(c)) => if (s == List(c)) ONE else
+ if (s == Nil) CHAR(c) else ZERO
+ case (s, ALT(r1, r2)) => ALT(ders2(s, r1), ders2(s, r2))
+ case (c::s, r) => ders2(s, simp(der(c, r)))
+}
+
+// derivative w.r.t. a string (iterates der)
+def cders (s: List[Char], r: Rexp) : Rexp = s match {
+ case ZERO => ZERO
+ case ONE => ZERO
+ case CHAR(d) => if (s == List(d)) ONE else ZERO
+ case ALT(r1, r2) => ALT(cders(s, r1), cders(s, r2))
+ case SEQ(r1, r2) => closed_seq_ders(r1, r2, s) ???
+ case STAR(r) => SEQ(cders(s, r), STAR(r)) ???
+ case RECD(_, r1) => cders(s, r1)
+}
+
+
// extracts a string from value
def flatten(v: Val) : String = v match {
case Empty => ""