checkpoint harmony
authoradam <adam@megacz.com>
Wed, 11 Jan 2006 07:42:42 +0000 (02:42 -0500)
committeradam <adam@megacz.com>
Wed, 11 Jan 2006 07:42:42 +0000 (02:42 -0500)
darcs-hash:20060111074242-5007d-8446781a5fe2ceb65e513e240b621603d229df17.gz

src/edu/berkeley/sbp/GSS.java
src/edu/berkeley/sbp/Parser.java

index 5feba84..1432402 100644 (file)
@@ -286,7 +286,7 @@ class GSS {
                     if (n==null) return;
                     Forest[] holder = new Forest[r.position.pos];
                     if (r.position.pos==0) n.finish(r, r.zero(), n.phase(), holder);
-                    else                   r.reduce(n, r.position.pos-1, n.phase(), holder);
+                    else                   n.reduce(r, r.position.pos-1, n.phase(), holder);
                 } else {
                     Forest[] holder = new Forest[r.position.pos];
                     if (r.position.pos<=0) throw new Error("called wrong form of reduce()");
@@ -298,12 +298,26 @@ class GSS {
                         Forest rex = r.position.rewrite(n.phase().getLocation());
                         n2.finish(r, rex, n.phase(), holder);
                     } else {
-                        r.reduce(n2, pos-1, n.phase(), holder);
+                        n2.reduce(r, pos-1, n.phase(), holder);
                     }
                     holder[pos] = old;
                 }
             }
 
+            public void reduce(Reduction r, int pos, GSS.Phase target, Forest[] holder) {
+                Forest old = holder[pos];
+                holder[pos] = this.pending();
+                if (pos==0) {
+                    System.arraycopy(holder, 0, r.position.holder, 0, holder.length);
+                    for(int i=0; i<r.position.pos; i++) if (r.position.holder[i]==null) throw new Error("realbad");
+                    Forest rex = r.position.rewrite(target.getLocation());
+                    for(GSS.Phase.Node child : this.parents()) child.finish(r, rex, target, holder);
+                } else {
+                    for(GSS.Phase.Node child : this.parents()) child.reduce(r, pos-1, target, holder);
+                }
+                holder[pos] = old;
+            }
+
             public void finish(Reduction r, Forest result, GSS.Phase target, Forest[] holder) {
                 State state0 = state.gotoSetNonTerminals.get(r.position.owner());
                 if (result==null) throw new Error();
index a156252..b4ac23a 100644 (file)
@@ -272,20 +272,6 @@ public abstract class Parser<T extends Token, R> {
                 return zero = position.rewrite(null);
             }
 
-            // FIXME: this could be more elegant and/or cleaner and/or somewhere else
-            public void reduce(GSS.Phase.Node parent, int pos, GSS.Phase target, Forest[] holder) {
-                Forest old = holder[pos];
-                holder[pos] = parent.pending();
-                if (pos==0) {
-                    System.arraycopy(holder, 0, position.holder, 0, holder.length);
-                    for(int i=0; i<position.pos; i++) if (position.holder[i]==null) throw new Error("realbad");
-                    Forest rex = position.rewrite(target.getLocation());
-                    for(GSS.Phase.Node child : parent.parents()) child.finish(this, rex, target, holder);
-                } else {
-                    for(GSS.Phase.Node child : parent.parents()) reduce(child, pos-1, target, holder);
-                }
-                holder[pos] = old;
-            }
         }
     }