progs/app52.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Tue, 17 Nov 2020 00:36:16 +0000
changeset 806 0d3bc1d0d987
parent 436 9213b8298ca9
permissions -rw-r--r--
updated

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, r2), ders2(s, r2))
  case (c::s, r) => ders2(s, simp(der(c, r)))
}