progs/app52.scala
author Christian Urban <urbanc@in.tum.de>
Thu, 14 Nov 2019 13:17:02 +0000
changeset 687 8865f4f2be59
parent 436 9213b8298ca9
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
415
4ae59fd3b174 updated
Christian Urban <urbanc@in.tum.de>
parents: 399
diff changeset
     1
def ders2(s: List[Char], r: Rexp) : Rexp = (s, r) match {
4ae59fd3b174 updated
Christian Urban <urbanc@in.tum.de>
parents: 399
diff changeset
     2
  case (Nil, r) => r
4ae59fd3b174 updated
Christian Urban <urbanc@in.tum.de>
parents: 399
diff changeset
     3
  case (s, ZERO) => ZERO
4ae59fd3b174 updated
Christian Urban <urbanc@in.tum.de>
parents: 399
diff changeset
     4
  case (s, ONE) => if (s == Nil) ONE else ZERO
4ae59fd3b174 updated
Christian Urban <urbanc@in.tum.de>
parents: 399
diff changeset
     5
  case (s, CHAR(c)) => if (s == List(c)) ONE else 
4ae59fd3b174 updated
Christian Urban <urbanc@in.tum.de>
parents: 399
diff changeset
     6
                       if (s == Nil) CHAR(c) else ZERO
4ae59fd3b174 updated
Christian Urban <urbanc@in.tum.de>
parents: 399
diff changeset
     7
  case (s, ALT(r1, r2)) => ALT(ders2(s, r2), ders2(s, r2))
436
9213b8298ca9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 415
diff changeset
     8
  case (c::s, r) => ders2(s, simp(der(c, r)))
261
24531cfaa36a updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     9
}