X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=cbf9b479f5bfb7e7fd763c5e08a68dc03ac450a4;hp=c270a90b3d434bf88ecb49ad39814ba1f7547503;hb=c366dacc334fe2e35835164f5a37d3eebb2ca6d5;hpb=526da96dd06e152d194ec92c9ef9df6085a1251b diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index c270a90..cbf9b47 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -37,11 +37,10 @@ public abstract class Parser { GSS gss = new GSS(); Token.Location loc = input.getLocation(); GSS.Phase current = gss.new Phase(null, this, null, input.next(1, 0, 0), loc, null); - current.newNode(null, Forest.leaf(null, null, null), pt.start, true); + current.newNode(null, Forest.leaf(null, null), pt.start, true); 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); @@ -162,8 +161,18 @@ public abstract class Parser { } /** a single state in the LR table and the transitions possible from it */ - public class State implements Comparable, Iterable { + + public class State implements Comparable, IntegerMappable, Iterable { + 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; @@ -311,7 +320,13 @@ public abstract class Parser { } } - 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; } }