X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=d258b7870675bbd35e722d42be0c4ef456e516f6;hp=65f3dc3e9e3f17b80be3d03950ffc9d22ddc0901;hb=f13be78d4291906d2f4c7588567cb114f0cc3b54;hpb=b0ec1efcb13eceb539f9cd033a0d2908fc2be27a diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index 65f3dc3..d258b78 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -311,6 +311,13 @@ public abstract class Parser { } public String toString() { return "[reduce " + position + "]"; } + private Forest zero = null; + public Forest zero() { + if (zero != null) return zero; + if (numPop > 0) throw new Error(); + return zero = position.rewrite(null); + } + public Forest reduce(GSS.Phase.Node parent) { if (numPop==0) return finish(parent, zero(), parent.phase()); return reduce(parent, numPop-1, null, parent.phase()); @@ -320,21 +327,11 @@ public abstract class Parser { if (numPop<=0) throw new Error("called wrong form of reduce()"); int pos = numPop-1; holder[pos] = parent.pending(); - Forest rex = null; if (pos==0) { - if (rex==null) { - System.arraycopy(holder, 0, position.holder, 0, holder.length); - rex = position.rewrite(parent.phase().getLocation()); - } + System.arraycopy(holder, 0, position.holder, 0, holder.length); + return finish(onlychild, position.rewrite(parent.phase().getLocation()), parent.phase()); } - return reduce(onlychild, pos-1, rex, parent.phase()); - } - - private Forest zero = null; - public Forest zero() { - if (zero != null) return zero; - if (numPop > 0) throw new Error(); - return zero = position.rewrite(null); + return reduce(onlychild, pos-1, null, parent.phase()); } // FIXME: this could be more elegant and/or cleaner and/or somewhere else @@ -346,6 +343,8 @@ public abstract class Parser { rex = position.rewrite(target.getLocation()); } for(GSS.Phase.Node child : parent.parents()) + //if (pos==0) finish(parent, rex, target); + //else reduce(child, pos-1, rex, target); return rex; }