X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=917fea588fd1dc37f1bdf02f5b45c72c3e2197c9;hb=cf349fcf2f460e53ad5f9dd0397eb382c4aa92b2;hp=705208f672d5305446865bcb31d26ca8f632801a;hpb=21c2c8445fd1d0c6ed630a2ecb259ddd9712c750;p=sbp.git diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 705208f..917fea5 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -10,9 +10,9 @@ import java.lang.reflect.*; public abstract class Forest { /** assume that this forest contains exactly one tree and return it; otherwise throw an exception */ - public final Tree expand1() throws Parser.Ambiguous, Parser.Failed { + public final Tree expand1() throws Ambiguous, ParseFailed { Iterator> it = expand(true).iterator(); - if (!it.hasNext()) throw new Parser.Failed(); + if (!it.hasNext()) throw new ParseFailed(); return it.next(); } @@ -71,43 +71,32 @@ public abstract class Forest { } return h; } - void addTo(HashSet h) { - if (!singleton) h.add(this); - else for(Body b : (IterableForest)tokens[0]) b.addTo(h); - } + void addTo(FastSet h) { if (!singleton) h.add(this, true); else for(Body b : (IterableForest)tokens[0]) b.addTo(h); } - - private boolean rep = false; public String toString() { - if (rep) return "***"; - try { - rep = true; - StringBuffer ret = new StringBuffer(); - for(int i=0; i 0) { - ret.append(q); - ret.append(" "); - } + StringBuffer ret = new StringBuffer(); + for(int i=0; i 0) { + ret.append(q); + ret.append(" "); } - String tail = ret.toString().trim(); - String head = (tag!=null && !tag.toString().equals("")) ? (tail.length() > 0 ? tag+":" : tag+"") : ""; - if (tail.length() > 0) tail = "{" + tail + "}"; - return head + tail; - } finally { - rep = false; } + String tail = ret.toString().trim(); + String head = (tag!=null && !tag.toString().equals("")) ? (tail.length() > 0 ? tag+":" : tag+"") : ""; + if (tail.length() > 0) tail = "{" + tail + "}"; + return head + tail; } } // Ref ////////////////////////////////////////////////////////////////////////////// - static abstract class IterableForest extends Forest implements Iterable> { + private static abstract class IterableForest extends Forest implements Iterable> { public abstract Iterator> iterator(); } @@ -154,7 +143,7 @@ public abstract class Forest { HashSet> ret = new HashSet>(); for(Body b : results) ret.addAll(b.expand(toss, new ArrayList>(), 0, new HashSet>())); - if (toss && ret.size() > 1) throw new Parser.Ambiguous(this); + if (toss && ret.size() > 1) throw new Ambiguous(this); return ret; } @@ -184,6 +173,5 @@ public abstract class Forest { // Statics ////////////////////////////////////////////////////////////////////////////// private static Tree[] tree_hint = new Tree[0]; - private static Body[] body_hint = new Body[0]; private static final Forest[] emptyForestArray = new Forest[0]; }