checkpoint harmony
[sbp.git] / src / edu / berkeley / sbp / Parser.java
index 95c3985..cbf9b47 100644 (file)
@@ -41,7 +41,6 @@ public abstract class Parser<T extends Token, R> {
         int count = 1;
         for(;;) {
             loc = input.getLocation();
         int count = 1;
         for(;;) {
             loc = input.getLocation();
-            //current.checkFailure();
             current.reduce();
             Forest forest = current.token==null ? null : shiftedToken((T)current.token, loc);
             GSS.Phase next = gss.new Phase(current, this, current, input.next(count, gss.resets, gss.waits), loc, forest);
             current.reduce();
             Forest forest = current.token==null ? null : shiftedToken((T)current.token, loc);
             GSS.Phase next = gss.new Phase(current, this, current, input.next(count, gss.resets, gss.waits), loc, forest);
@@ -162,10 +161,18 @@ public abstract class Parser<T extends Token, R> {
         }
 
         /** a single state in the LR table and the transitions possible from it */
         }
 
         /** a single state in the LR table and the transitions possible from it */
-        public class State implements Comparable<Table.State>, Iterable<Position>, IntegerMappable {
+
+        public class State implements Comparable<Table.State>, IntegerMappable, Iterable<Position> {
         
             public int toInt() { return idx; }
 
         
             public int toInt() { return idx; }
 
+            public boolean lame() {
+                for(Position p : this)
+                    for(Position p2 = p; p2!=null; p2=p2.next())
+                        if (p2.isLast() && !p2.owner().lame)
+                            return false;
+                return true;
+            }
             /*
             public boolean isResolvable(Token t) {
                 boolean found = false;
             /*
             public boolean isResolvable(Token t) {
                 boolean found = false;
@@ -313,7 +320,13 @@ public abstract class Parser<T extends Token, R> {
                 }
             }
 
                 }
             }
 
-            public String toString() { return "state["+idx+"]"; }
+            public String toString() {
+                //return "state["+idx+"]";
+                StringBuffer ret = new StringBuffer();
+                ret.append("state["+idx+"]: ");
+                for(Position p : this) ret.append("{"+p+"}  ");
+                return ret.toString();
+            }
 
             public int compareTo(Table.State s) { return idx==s.idx ? 0 : idx < s.idx ? -1 : 1; }
         }
 
             public int compareTo(Table.State s) { return idx==s.idx ? 0 : idx < s.idx ? -1 : 1; }
         }