X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=dc6c1f6d38f4e727be22d572e78703093dc69a0c;hp=58d0bc2a217118aaeb174974af72fc4a13dfd02c;hb=c263c1e02119917a9d63ab14db9711c7d1cb4d9d;hpb=7fbee73b4dd985cb5b217ed297710c00fd9d7004 diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index 58d0bc2..dc6c1f6 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -134,7 +134,7 @@ public abstract class Parser { Walk.Follow wf = new Walk.Follow(top.empty(), p.owner(), all_elements, cache); Reduction red = new Reduction(p); state.reductions.put(wf.walk(p.owner()), red); - if (wf.includesEof()) state.eofReductions.add(red, true); + if (wf.includesEof()) state.eofReductions.add(red); } // if the element following this position is an atom, copy the corresponding @@ -168,14 +168,14 @@ public abstract class Parser { } */ - public final int idx = master_state_idx++; + public final int idx = master_state_idx++; private final HashSet hs; private transient HashMap gotoSetNonTerminals = new HashMap(); private transient TopologicalBag gotoSetTerminals = new TopologicalBag(); private TopologicalBag reductions = new TopologicalBag(); - private FastSet eofReductions = new FastSet(); + private HashSet eofReductions = new HashSet(); private TopologicalBag shifts = new TopologicalBag(); private boolean accept = false; @@ -310,12 +310,10 @@ public abstract class Parser { this.holder = new Forest[numPop]; } public String toString() { return "[reduce " + position + "]"; } - public Forest reduce(Forest f, GSS.Phase.Node parent, GSS.Phase.Node onlychild, GSS.Phase target, Forest rex) { - holder[numPop-1] = f; - return reduce(parent, numPop-2, rex, onlychild, target); - } - public Forest reduce(GSS.Phase.Node parent, GSS.Phase.Node onlychild, GSS.Phase target, Forest rex) { - return reduce(parent, numPop-1, rex, onlychild, target); + + public Forest reduce(GSS.Phase.Node parent, GSS.Phase.Node onlychild, Forest rex) { + Forest ret = reduce(parent, numPop-1, rex, onlychild, parent.phase()); + return ret; } private Forest zero = null; @@ -328,11 +326,17 @@ public abstract class Parser { // FIXME: this could be more elegant and/or cleaner and/or somewhere else private Forest reduce(GSS.Phase.Node parent, int pos, Forest rex, GSS.Phase.Node onlychild, GSS.Phase target) { if (pos>=0) holder[pos] = parent.pending(); - if (pos<=0 && rex==null) { - System.arraycopy(holder, 0, position.holder, 0, holder.length); - rex = position.rewrite(target.getLocation()); - } - if (pos >=0) { + if (pos==0) { + if (rex==null) { + System.arraycopy(holder, 0, position.holder, 0, holder.length); + rex = position.rewrite(target.getLocation()); + } + if (onlychild != null) + reduce(onlychild, pos-1, rex, null, target); + else + for(GSS.Phase.Node child : parent.parents()) + reduce(child, pos-1, rex, null, target); + } else if (pos>0) { if (onlychild != null) reduce(onlychild, pos-1, rex, null, target); else @@ -341,7 +345,7 @@ public abstract class Parser { } else { State state = parent.state.gotoSetNonTerminals.get(position.owner()); if (state!=null) - target.newNode(parent, rex, state, numPop<=0, parent.phase); + target.newNode(parent, rex, state, numPop<=0, parent.phase()); } return rex; }