equal
deleted
inserted
replaced
2 import scala.util.Try |
2 import scala.util.Try |
3 |
3 |
4 // type abbreviation for partial functions |
4 // type abbreviation for partial functions |
5 type :=>[A, B] = PartialFunction[A, B] |
5 type :=>[A, B] = PartialFunction[A, B] |
6 |
6 |
7 case class DFA[A, C](start: A, // starting state |
7 case class DFA[A, C](start: A, // starting state |
8 delta: (A, C) :=> A, // transition partial fun |
8 delta: (A, C) :=> A, // transition (partial fun) |
9 fins: A => Boolean) { // final states |
9 fins: A => Boolean) { // final states |
10 |
10 |
11 def deltas(q: A, s: List[C]) : A = s match { |
11 def deltas(q: A, s: List[C]) : A = s match { |
12 case Nil => q |
12 case Nil => q |
13 case c::cs => deltas(delta(q, c), cs) |
13 case c::cs => deltas(delta(q, c), cs) |
14 } |
14 } |