summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-11-16 08:21:46 +0000
committerburaq <buraq@epfl.ch>2004-11-16 08:21:46 +0000
commit622167df9a18e3d8a0f16276dfbe21d9e3a85b4e (patch)
tree5956e9d7612b8271f097d4fda7d10761d72ba38b
parent74a30a3f5259a05f4c4287fe8937015ade88e14e (diff)
downloadscala-622167df9a18e3d8a0f16276dfbe21d9e3a85b4e.tar.gz
scala-622167df9a18e3d8a0f16276dfbe21d9e3a85b4e.tar.bz2
scala-622167df9a18e3d8a0f16276dfbe21d9e3a85b4e.zip
more general type for finals map
-rw-r--r--sources/scala/util/automata/NondetWordAutom.scala25
1 files changed, 19 insertions, 6 deletions
diff --git a/sources/scala/util/automata/NondetWordAutom.scala b/sources/scala/util/automata/NondetWordAutom.scala
index 9023bbd7e2..5d6a47d7f8 100644
--- a/sources/scala/util/automata/NondetWordAutom.scala
+++ b/sources/scala/util/automata/NondetWordAutom.scala
@@ -1,20 +1,26 @@
package scala.util.automata ;
-import scala.collection.{ Set, Map, mutable };
+import scala.collection.{ Set, Map };
-/** 0 is always the only initial state */
+/** A nondeterministic automaton. States are integers, where
+ * 0 is always the only initial state. Transitions are represented
+ * in the delta function. Default transitions are transitions that
+ * are taken when no other transitions can be applied.
+ * All states are reachable. Accepting states are those for which
+ * the partial function 'finals' is defined.
+ */
abstract class NondetWordAutom {
type T_label;
val nstates: Int;
val labels: Set[T_label] ;
- val finals: Map[Int,Int] ;
+ val finals: PartialFunction[Int,Int] ;
val delta: Function1[Int,Map[T_label,List[Int]]];
val default: Array[List[Int]];
/** returns true if the state is final */
- final def isFinal(state: Int) = finals.contains( state );
+ final def isFinal(state: Int) = finals.isDefinedAt( state );
/** returns tag of final state */
final def finalTag(state: Int) = finals( state );
@@ -28,8 +34,15 @@ abstract class NondetWordAutom {
return false;
}
- /** returns true if there are no finite states */
- final def isEmpty = finals.isEmpty;
+ /** returns true if there are no accepting states */
+ final def isEmpty = {
+ var r = true;
+ var j = 0; while( r && ( j < nstates )) {
+ if(isFinal(j))
+ r = false;
+ }
+ r
+ }
override def toString() = {
val sb = new StringBuffer();