summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/list/library.lst1
-rw-r--r--sources/scala/util/automata/DetWordAutom.scala46
-rw-r--r--sources/scala/util/automata/NondetWordAutom.scala10
3 files changed, 53 insertions, 4 deletions
diff --git a/config/list/library.lst b/config/list/library.lst
index bb7f2a8277..04e69f5761 100644
--- a/config/list/library.lst
+++ b/config/list/library.lst
@@ -191,6 +191,7 @@ testing/SUnit.scala
testing/Benchmark.scala
util/automata/BaseBerrySethi.scala
+util/automata/DetWordAutom.scala
util/automata/NondetWordAutom.scala
util/automata/WordBerrySethi.scala
util/grammar/HedgeRHS.scala
diff --git a/sources/scala/util/automata/DetWordAutom.scala b/sources/scala/util/automata/DetWordAutom.scala
new file mode 100644
index 0000000000..ae52f0b2b5
--- /dev/null
+++ b/sources/scala/util/automata/DetWordAutom.scala
@@ -0,0 +1,46 @@
+package scala.util.automata ;
+
+import scala.collection.{ Set, Map };
+
+/** A deterministic automaton. States are integers, where
+ * 0 is always the only initial state. Transitions are represented
+ * in the delta function. A default transitions is one that
+ * is taken when no other transition can be taken.
+ * All states are reachable. Accepting states are those for which
+ * the partial function 'finals' is defined.
+ */
+abstract class DetWordAutom {
+
+ type T_label;
+
+ val nstates: Int;
+ val finals: PartialFunction[Int,Int] ;
+ val delta: Function1[Int,Map[T_label,Int]];
+ val default: PartialFunction[Int,Int] ;
+
+ override def toString() = {
+ val sb = new StringBuffer();
+ sb.append("[nfa nstates=");
+ sb.append(nstates);
+ sb.append(" finals=");
+ var map = new scala.collection.immutable.ListMap[Int,Int];
+ var j = 0; while( j < nstates ) {
+ if(finals.isDefinedAt(j))
+ map = map.update(j,finals(j))
+ }
+ sb.append(map.toString());
+ sb.append(" delta=\n");
+ for( val i <- Iterator.range(0,nstates)) {
+ sb.append( i );
+ sb.append("->");
+ sb.append(delta(i).toString());
+ sb.append('\n');
+ if(default.isDefinedAt(i)) {
+ sb.append("_>");
+ sb.append(default(i).toString());
+ sb.append('\n');
+ }
+ }
+ sb.toString();
+ }
+}
diff --git a/sources/scala/util/automata/NondetWordAutom.scala b/sources/scala/util/automata/NondetWordAutom.scala
index 5d6a47d7f8..e3f0704f5c 100644
--- a/sources/scala/util/automata/NondetWordAutom.scala
+++ b/sources/scala/util/automata/NondetWordAutom.scala
@@ -14,7 +14,6 @@ abstract class NondetWordAutom {
type T_label;
val nstates: Int;
- val labels: Set[T_label] ;
val finals: PartialFunction[Int,Int] ;
val delta: Function1[Int,Map[T_label,List[Int]]];
val default: Array[List[Int]];
@@ -48,10 +47,13 @@ abstract class NondetWordAutom {
val sb = new StringBuffer();
sb.append("[nfa nstates=");
sb.append(nstates);
- sb.append(" labels=");
- sb.append(labels.toString());
sb.append(" finals=");
- sb.append(finals.toString());
+ var map = new scala.collection.immutable.ListMap[Int,Int];
+ var j = 0; while( j < nstates ) {
+ if(finals.isDefinedAt(j))
+ map = map.update(j,finals(j))
+ }
+ sb.append(map.toString());
sb.append(" delta=\n");
for( val i <- Iterator.range(0,nstates)) {
sb.append( i );