progs/lecture4.scala
changeset 242 3308eeb73d11
parent 226 6bb7810d2108
child 243 80102fba0a93
equal deleted inserted replaced
241:7c482f99c780 242:3308eeb73d11
   306   // given a state and a character, what is the set of 
   306   // given a state and a character, what is the set of 
   307   // next states? if there is none => empty set
   307   // next states? if there is none => empty set
   308   def next(q: A, c: C) : Set[A] = 
   308   def next(q: A, c: C) : Set[A] = 
   309     Try(delta(q, c)) getOrElse Set[A]() 
   309     Try(delta(q, c)) getOrElse Set[A]() 
   310 
   310 
       
   311   def nexts(qs: Set[A], c: C) : Set[A] =
       
   312     qs.flatMap(next(_, c))
       
   313 
   311   // depth-first version of accepts
   314   // depth-first version of accepts
   312   def search(q: A, s: List[C]) : Boolean = s match {
   315   def search(q: A, s: List[C]) : Boolean = s match {
   313     case Nil => fins(q)
   316     case Nil => fins(q)
   314     case c::cs => next(q, c).exists(search(_, cs))
   317     case c::cs => next(q, c).exists(search(_, cs))
   315   }
   318   }