X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=b16a33d54e43fa8f17d4ced6a0041ee266d54b77;hp=ead35511fd0c1986b994c4b610c0a2bc4ccff118;hb=90500a338733b6ba0d5b9c0cdc5a7afea38173ae;hpb=842f3c9b981b35721bb50d49e85c11085b2040a3 diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index ead3551..b16a33d 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -37,7 +37,7 @@ 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, null, pt.start, true); + current.newNode(null, Forest.leaf(null, null), pt.start, true); int count = 1; for(;;) { loc = input.getLocation(); @@ -162,8 +162,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 +321,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; } } @@ -382,6 +398,7 @@ public abstract class Parser { } private void finish(GSS.Phase.Node parent, Forest result, GSS.Phase target) { State state = parent.state.gotoSetNonTerminals.get(position.owner()); + if (result==null) throw new Error(); if (state!=null) target.newNode(parent, result, state, numPop<=0, this); }