throw error when Forest created with head()
[sbp.git] / src / edu / berkeley / sbp / GSS.java
index f0a4cea..91ef765 100644 (file)
@@ -25,7 +25,7 @@ class GSS {
     /** corresponds to a positions <i>between tokens</i> the input stream; same as Tomita's U_i's */
     class Phase<Tok> implements Invokable<State, Result, Object>, IntegerMappable, GraphViz.ToGraphViz, Iterable<Node> {
 
-        public ArrayList<Reduction> reductionQueue = new ArrayList<Reduction>();
+        public PriorityQueue<Reduction> reductionQueue = new PriorityQueue<Reduction>();
 
         public void invoke(State st, Result result, Object o) {
             //shifts++;
@@ -89,40 +89,15 @@ class GSS {
                 if (token == null) continue;
                 n.state().invokeShifts(token, this, new Result(result, n, null), null);
             }
+            for(Node n : hash.values()) n.check();
             if (!good && token!=null) ParseFailed.error("unexpected character", this);
             if (token==null && finalResult==null) ParseFailed.error("unexpected end of file", this);
         }
 
         /** 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<reductionQueue.size(); i++) {
-                    for(int j=0; j<reductionQueue.size(); j++) {
-                        if (i==j) continue;
-                        if (reductionQueue.get(i).compareTo(reductionQueue.get(j)) > 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) {