progs/lecture4.scala
changeset 242 e6b34f617915
parent 226 5e489c9fe47b
child 243 9bb36426c781
equal deleted inserted replaced
241:c650a91db720 242:e6b34f617915
   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   }