author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 26 Sep 2014 14:06:55 +0100 | |
changeset 258 | 1e4da6d2490c |
parent 117 | 25999de692b2 |
child 262 | ee4304bc6350 |
permissions | -rw-r--r-- |
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(der(r1, c), der(r2, c)) case SEQ(r1, r2) => 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)) }