--- a/progs/app6.scala Fri Sep 27 15:43:25 2013 +0100
+++ b/progs/app6.scala Mon Sep 30 13:18:16 2013 +0100
@@ -1,11 +1,16 @@
-def deriv (r: Rexp, c: Char) : Rexp = r match {
+def der (r: Rexp, c: Char) : Rexp = r match {
case NULL => NULL
case EMPTY => NULL
case CHAR(d) => if (c == d) EMPTY else NULL
- case ALT(r1, r2) => ALT(deriv(r1, c), deriv(r2, c))
+ case ALT(r1, r2) => ALT(der(r1, c), der(r2, c))
case SEQ(r1, r2) =>
- if (nullable(r1)) ALT(SEQ(deriv(r1, c), r2), deriv(r2, c))
- else SEQ(deriv(r1, c), r2)
- case STAR(r) => SEQ(deriv(r, c), STAR(r))
+ if (nullable(r1)) ALT(SEQ(der(r1, c), r2), der(r2, c))
+ else SEQ(der(r1, c), r2)
+ case STAR(r) => SEQ(der(r, c), STAR(r))
}
+def ders (s: List[Char], r: Rexp) : Rexp = s match {
+ case Nil => r
+ case c::s => ders(s, der(c, r))
+}
+