checkpoint
authoradam <adam@megacz.com>
Wed, 4 Jan 2006 09:11:11 +0000 (04:11 -0500)
committeradam <adam@megacz.com>
Wed, 4 Jan 2006 09:11:11 +0000 (04:11 -0500)
darcs-hash:20060104091111-5007d-ccae0cc34703ba44d9c8f51dbd2e13ac99b7b715.gz

src/edu/berkeley/sbp/GSS.java

index 6d5f8ab..7dbb29c 100644 (file)
@@ -211,7 +211,35 @@ class GSS {
             public void queueReductions(Node n2) {
                 if (queued.contains(n2)) return;
                 queued.add(n2);
-                new Reduct(this, n2, null).go();
+                Node n = this;
+                for(Parser.Table.Reduction r : token==null ? n.state.getEofReductions() : n.state.getReductions(token)) {
+                    
+                    // UGLY HACK
+                    // The problem here is that a "reduction of length 1"
+                    // performed twice with different values of n2 needs
+                    // to only create a *single* new result, but must add
+                    // multiple parents to the node holding that result.
+                    // The current reducer doesn't differentiate between
+                    // the next node of an n-pop reduction and the
+                    // ultimate parent of the last pop, so we need to
+                    // cache instances here as a way of avoiding
+                    // recreating them.
+                    
+                    // currently we have this weird problem where we
+                    // have to do an individual reduct for each child
+                    // when the reduction length is one (ie the
+                    // children wind up being children of the newly
+                    // created node rather than part of the popped
+                    // sequence
+                    if (r.numPop <= 0) continue;
+                    if (r.numPop == 1) {
+                        Forest ret = n.cache().get(r);
+                        if (ret != null) r.reduce(n, n2, n.phase, ret);
+                        else n.cache().put(r, r.reduce(n, n2, n.phase, null));
+                    } else {
+                        r.reduce(n, n2, Phase.this, null);
+                    }
+                }
             }
 
 
@@ -260,9 +288,9 @@ class GSS {
                 this.n2 = n2;
                 this.r = r;
                 //if (reductions.contains(this)) { done = true; return; }
-                reductions.add(this);
-                pendingReduct.addFirst(this);
-                pendingReductions++;
+                //reductions.add(this);
+                //pendingReduct.addFirst(this);
+                //pendingReductions++;
                 go();
             }
 
@@ -270,8 +298,8 @@ class GSS {
             public void go() {
                 if (done) return;
                 done = true;
-                pendingReduct.remove(this);
-                pendingReductions--;
+                //pendingReduct.remove(this);
+                //pendingReductions--;
 
                 if (r==null) {
                     for(Parser.Table.Reduction r : token==null ? n.state.getEofReductions() : n.state.getReductions(token)) {