summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2005-04-24 18:43:37 +0000
committerburaq <buraq@epfl.ch>2005-04-24 18:43:37 +0000
commit041681054fca3a6b5893c95cfc4bbfc7a780993d (patch)
treecc4a941815daeda35a07a958e19bdaafa53d36fb /sources
parenta3fbf70b2a5fb5c068ff920dc4e887b12e3bed0e (diff)
downloadscala-041681054fca3a6b5893c95cfc4bbfc7a780993d.tar.gz
scala-041681054fca3a6b5893c95cfc4bbfc7a780993d.tar.bz2
scala-041681054fca3a6b5893c95cfc4bbfc7a780993d.zip
bugfix
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/util/automata/BaseBerrySethi.scala16
-rw-r--r--sources/scala/util/automata/WordBerrySethi.scala27
2 files changed, 28 insertions, 15 deletions
diff --git a/sources/scala/util/automata/BaseBerrySethi.scala b/sources/scala/util/automata/BaseBerrySethi.scala
index 864a0d479b..68e2cc476d 100644
--- a/sources/scala/util/automata/BaseBerrySethi.scala
+++ b/sources/scala/util/automata/BaseBerrySethi.scala
@@ -17,10 +17,6 @@ abstract class BaseBerrySethi {
protected var pos = 0;;
- // maps a letter to an Integer ( the position )
- // is not *really* needed (preorder determines position!)
- protected var posMap: mutable.HashMap[RegExp, Int] = _;
-
protected var globalFirst: immutable.Set[Int] = _;
// results which hold all info for the NondetWordAutomaton
@@ -85,6 +81,7 @@ abstract class BaseBerrySethi {
// precondition: pos is final
// pats are successor patterns of a Sequence node
protected def compFollow(r: Seq[RegExp]): immutable.Set[Int] = {
+ Console.println("compFollow( "+r.toList);
var first = emptySet;
var fol = emptySet;
if( r.length > 0 ) {//non-empty expr
@@ -94,15 +91,20 @@ abstract class BaseBerrySethi {
fol = fol + pos; // don't modify pos !
while( it.hasNext ) {
val p = it.next;
+ Console.println(" p now = "+p);
first = compFollow1( fol, p );
+ Console.println(" first = "+first);
+ Console.println(" fol before = "+fol);
fol = if( p.isNullable )
fol incl first
else
first;
+ Console.println(" fol after = "+fol);
}
}
- this.follow.update( 0, first );
- return first;
+ this.follow.update( 0, fol /*first*/ );
+ Console.println("follow(0) = "+fol);
+ return fol;
}
/** returns the first set of an expression, setting the follow set along
@@ -110,7 +112,7 @@ abstract class BaseBerrySethi {
*/
protected def compFollow1( fol1:immutable.Set[Int], r:RegExp): immutable.Set[Int] = {
var fol = fol1;
- //System.out.println("compFollow1("+fol+","+pat+")");
+ //System.out.println("compFollow1("+fol+","+r+")");
r match {
case x:Alt =>
diff --git a/sources/scala/util/automata/WordBerrySethi.scala b/sources/scala/util/automata/WordBerrySethi.scala
index bf3baa9372..f99a66b084 100644
--- a/sources/scala/util/automata/WordBerrySethi.scala
+++ b/sources/scala/util/automata/WordBerrySethi.scala
@@ -30,15 +30,19 @@ abstract class WordBerrySethi extends BaseBerrySethi {
protected var initials:immutable.Set[Int] = _ ;
//NondetWordAutom revNfa ;
+ // maps a letter to an Integer ( the position )
+ // is not *really* needed (preorder determines position!)
+ //protected var posMap: mutable.HashMap[RegExp, Int] = _;
+
/** computes first( r ) where the word regexp r */
protected override def compFirst(r: RegExp): immutable.Set[Int] = r match {
- case x:Letter => emptySet + posMap(x); // singleton set
+ case x:Letter => emptySet + x.pos ;//posMap(x); // singleton set
case _ => super.compFirst(r);
}
/** computes last( r ) where the word regexp r */
protected override def compLast(r: RegExp): immutable.Set[Int] = r match {
- case x:Letter => emptySet + posMap(x) // singleton set
+ case x:Letter => emptySet + x.pos; //posMap(x) // singleton set
case _ => super.compLast(r)
}
@@ -49,7 +53,8 @@ abstract class WordBerrySethi extends BaseBerrySethi {
r match {
case x:Letter =>
- val i = posMap( x );
+ //val i = posMap( x );
+ val i = x.pos;
this.follow.update( i, fol1 );
emptySet + i;
@@ -63,8 +68,9 @@ abstract class WordBerrySethi extends BaseBerrySethi {
/** called at the leaves of the regexp */
- protected def seenLabel( r:RegExp, i:Int, label: _labelT ): Unit = {
- this.posMap.update( r, i );
+ protected def seenLabel( r:RegExp, i:Int, label: _labelT ): Unit = {
+ Console.println("seenLabel (1)");
+ //this.posMap.update( r, i );
this.labelAt = this.labelAt.update( i, label );
//@ifdef if( label != Wildcard ) {
this.labels += label ;
@@ -72,15 +78,17 @@ abstract class WordBerrySethi extends BaseBerrySethi {
}
// overriden in BindingBerrySethi
- protected def seenLabel( r: RegExp, label: _labelT ): Unit = {
+ protected def seenLabel( r: RegExp, label: _labelT ): Int = {
+ //Console.println("seenLabel (2)");
pos = pos + 1;
seenLabel( r, pos, label );
+ pos
}
// todo: replace global variable pos with acc
override def traverse(r: RegExp): Unit = r match {
- case Letter( label ) => seenLabel( r, label ) ;
+ case a @ Letter( label ) => a.pos = seenLabel( r, label ) ;
case _ => super.traverse(r)
}
@@ -97,7 +105,7 @@ abstract class WordBerrySethi extends BaseBerrySethi {
}
protected def initialize(subexpr: Seq[RegExp]): Unit = {
- this.posMap = new mutable.HashMap[RegExp,Int]();
+ //this.posMap = new mutable.HashMap[RegExp,Int]();
this.labelAt = new immutable.TreeMap[Int,_labelT]();
this.follow = new mutable.HashMap[Int,immutable.Set[Int]]();
this.labels = new mutable.HashSet[_labelT]();
@@ -129,7 +137,10 @@ abstract class WordBerrySethi extends BaseBerrySethi {
}
protected def collectTransitions(): Unit = { // make transitions
+ Console.println("WBS.collectTrans, this.follow.keys = "+this.follow.keys);
+ Console.println("WBS.collectTrans, pos = "+this.follow.keys);
var j = 0; while( j < pos ) {
+ Console.println("WBS.collectTrans, j = "+j);
val fol = this.follow( j );
val it = fol.elements;
while( it.hasNext ) {