X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FGSS.java;h=f222fe568d8e4914540399674279d6e1bd1ac144;hp=be4276fb0725d56393a7332b3dca6037d8c7f05a;hb=fc8cad4de7decd07e23f26ccfadb5e6d1ce291d5;hpb=e84029a8b861075d6d0ed5040f919b2e4da4c98f
diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java
index be4276f..f222fe5 100644
--- a/src/edu/berkeley/sbp/GSS.java
+++ b/src/edu/berkeley/sbp/GSS.java
@@ -25,7 +25,7 @@ class GSS {
/** corresponds to a positions between tokens the input stream; same as Tomita's U_i's */
class Phase implements Invokable, IntegerMappable, GraphViz.ToGraphViz, Iterable {
- public ArrayList reductionQueue = new ArrayList();
+ public PriorityQueue reductionQueue = new PriorityQueue();
public void invoke(State st, Result result, Object o) {
//shifts++;
@@ -38,7 +38,7 @@ class GSS {
public IntPairMap hash; /* ALLOC */
private boolean good;
- Phase next = null;
+ private Phase next = null;
private Phase prev;
private Input.Location location;
private Input.Location nextLocation;
@@ -61,7 +61,8 @@ class GSS {
finalResult = null;
if (prev != null) prev.shift(this, forest);
}
-
+
+ public boolean isFrontier() { return next==null; }
public boolean isDone() throws ParseFailed {
if (token != null) return false;
if (token==null && finalResult==null)
@@ -94,34 +95,8 @@ class GSS {
/** perform all reduction operations */
public void reduce() throws ParseFailed {
- Reduction last = null;
- while(!reductionQueue.isEmpty()) {
- Reduction r = null;
-
- // ugly
- OUTER: for(int i=0; i 0)
- continue OUTER;
- }
- r = reductionQueue.get(i);
- reductionQueue.remove(r);
- break;
- }
-
- /*
- if (last == null) last = r;
- else if (r.compareTo(last) > 0) last = r;
- else if (r.compareTo(last) < 0) {
- if (r.targetPhase() != null)
- System.out.println("err " + last.compareTo(r) + " " + last.targetPhase().pos() +
- " " + r.targetPhase().pos() + " " + pos);
- }
- */
-
- r.perform();
- }
+ while(!reductionQueue.isEmpty())
+ reductionQueue.poll().perform();
}
public void newNodeFromReduction(Result result, State state, boolean fromEmptyReduction, Position reduction) {