author | Christian Urban <urbanc@in.tum.de> |
Tue, 26 Sep 2017 12:19:54 +0100 | |
changeset 500 | c502933be072 |
parent 435 | e08431a78f66 |
child 565 | 2be8c4c77418 |
permissions | -rw-r--r-- |
422 | 1 |
def simp(r: Rexp) : Rexp = r match { |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
2 |
case ALT(r1, r2) => { |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
262
diff
changeset
|
3 |
(simp(r1), simp(r2)) match { |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
343
diff
changeset
|
4 |
case (ZERO, r2s) => r2s |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
343
diff
changeset
|
5 |
case (r1s, ZERO) => r1s |
412 | 6 |
case (r1s, r2s) => |
7 |
if (r1s == r2s) r1s else ALT(r1s, r2s) |
|
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
8 |
} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
9 |
} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
10 |
case SEQ(r1, r2) => { |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
262
diff
changeset
|
11 |
(simp(r1), simp(r2)) match { |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
343
diff
changeset
|
12 |
case (ZERO, _) => ZERO |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
343
diff
changeset
|
13 |
case (_, ZERO) => ZERO |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
343
diff
changeset
|
14 |
case (ONE, r2s) => r2s |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
343
diff
changeset
|
15 |
case (r1s, ONE) => r1s |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
262
diff
changeset
|
16 |
case (r1s, r2s) => SEQ(r1s, r2s) |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
17 |
} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
18 |
} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
19 |
case NTIMES(r, n) => NTIMES(simp(r), n) |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
117
diff
changeset
|
20 |
case r => r |
7 | 21 |
} |
22 |
||
412 | 23 |
def ders(s: List[Char], r: Rexp) : Rexp = s match { |
117
25999de692b2
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
24 |
case Nil => r |
435
e08431a78f66
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
422
diff
changeset
|
25 |
case c::s => ders(s, simp(der(c, r))) /*@\label{simpline}@*/ |
117
25999de692b2
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
26 |
} |
25999de692b2
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
27 |