progs/dfa.scala
changeset 487 a697421eaa04
parent 485 bd6d999ab7b6
child 576 550186034b6e
--- a/progs/dfa.scala	Tue Apr 25 12:33:16 2017 +0100
+++ b/progs/dfa.scala	Fri Apr 28 11:01:25 2017 +0100
@@ -17,7 +17,7 @@
     Try(fins(deltas(start, s))) getOrElse false
 }
 
-// the example shown earlier in the handout 
+// the example shown in the handout 
 abstract class State
 case object Q0 extends State
 case object Q1 extends State
@@ -41,3 +41,25 @@
 
 dfa.accepts("bbabaab".toList)   // true
 dfa.accepts("baba".toList)      // false
+
+
+// another DFA test with a Sink state
+abstract class S
+case object S0 extends S
+case object S1 extends S
+case object S2 extends S
+case object Sink extends S
+
+// transition function with a sink state
+val sigma : (S, Char) :=> S = 
+  { case (S0, 'a') => S1
+    case (S1, 'a') => S2
+    case _ => Sink
+  }
+
+val dfa1a = DFA(S0, sigma, Set[S](S2))
+
+dfa1a.accepts("aa".toList)        // true
+dfa1a.accepts("".toList)          // false
+dfa1a.accepts("ab".toList)        // false
+