progs/nfa.scala
changeset 483 6f508bcdaa30
parent 482 0f6e3c5a1751
child 485 bd6d999ab7b6
equal deleted inserted replaced
482:0f6e3c5a1751 483:6f508bcdaa30
     8                      fins:  A => Boolean) {     // final states 
     8                      fins:  A => Boolean) {     // final states 
     9 
     9 
    10   // given a state and a character, what is the set of next states?
    10   // given a state and a character, what is the set of next states?
    11   // if there is none => empty set
    11   // if there is none => empty set
    12   def next(q: A, c: C) : Set[A] = 
    12   def next(q: A, c: C) : Set[A] = 
    13     delta.flatMap(_.lift.apply(q, c))
    13     delta.flatMap(d => Try(d(q, c)).toOption)
    14 
    14 
    15   def nexts(qs: Set[A], c: C) : Set[A] =
    15   def nexts(qs: Set[A], c: C) : Set[A] =
    16     qs.flatMap(next(_, c))
    16     qs.flatMap(next(_, c))
    17 
    17 
    18   def deltas(qs: Set[A], s: List[C]) : Set[A] = s match {
    18   def deltas(qs: Set[A], s: List[C]) : Set[A] = s match {