author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sat, 15 Jun 2013 09:23:18 -0400 | |
changeset 93 | 4794759139ea |
parent 92 | scala/app6.scala@e85600529ca5 |
child 117 | 25999de692b2 |
permissions | -rw-r--r-- |
def deriv (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 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)) }