X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=08c49a9aeb34e6ff684dead960bd40e8afba51bc;hp=65f3dc3e9e3f17b80be3d03950ffc9d22ddc0901;hb=d5f34dfd50f82d7647d2ce2d014ae83e07d8280a;hpb=b0ec1efcb13eceb539f9cd033a0d2908fc2be27a diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index 65f3dc3..08c49a9 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,7 +343,8 @@ public abstract class Parser { rex = position.rewrite(target.getLocation()); } for(GSS.Phase.Node child : parent.parents()) - reduce(child, pos-1, rex, target); + if (pos==0) finish(child, rex, target); + else reduce(child, pos-1, rex, target); return rex; } private Forest finish(GSS.Phase.Node parent, Forest result, GSS.Phase target) {