117
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
1 |
def der (r: Rexp, c: Char) : Rexp = r match {
|
7
|
2 |
case NULL => NULL
|
|
3 |
case EMPTY => NULL
|
|
4 |
case CHAR(d) => if (c == d) EMPTY else NULL
|
117
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
5 |
case ALT(r1, r2) => ALT(der(r1, c), der(r2, c))
|
7
|
6 |
case SEQ(r1, r2) =>
|
117
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
7 |
if (nullable(r1)) ALT(SEQ(der(r1, c), r2), der(r2, c))
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
8 |
else SEQ(der(r1, c), r2)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
9 |
case STAR(r) => SEQ(der(r, c), STAR(r))
|
7
|
10 |
}
|
|
11 |
|
117
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
12 |
def ders (s: List[Char], r: Rexp) : Rexp = s match {
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
13 |
case Nil => r
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
14 |
case c::s => ders(s, der(c, r))
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
15 |
}
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
16 |
|