X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=4f4baacb62315f466039ca27283f7366d5c1f631;hb=4eeae516c2ef96ca11d24f23fd5e80d12e7734a6;hp=df7a3ea2d0a9a2a1eed3c1de1cedef4d2996b25e;hpb=02d1ec40a590520818d5fd7c3c1f68c161ce5567;p=sbp.git diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index df7a3ea..4f4baac 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -7,19 +7,7 @@ import java.util.*; import java.lang.reflect.*; /** an efficient representation of a collection of trees (Tomita's shared packed parse forest) */ -public abstract class Forest /*extends PrintableTree>*/ implements Visitable> { - - public abstract void invoke(Invokable,B,C> ivbc, B b, C c); - private static class TreeMaker extends HashSet> implements Invokable,Boolean,Integer> { - public ArrayList> toks = new ArrayList>(); - public void invoke(Forest.Body bod, Boolean toss, Integer i) { - if (i==null) { - addAll(bod.expand(toss, 0, new TreeMaker())); - } else { - bod.expand(toss, i, this); - } - } - } +public abstract class Forest /*extends PrintableTree>*/ implements Visitable> { /** assume that this forest contains exactly one tree and return it; otherwise throw an exception */ public final Tree expand1() throws Ambiguous, ParseFailed { @@ -54,7 +42,6 @@ public abstract class Forest /*extends PrintableTree>*/ implem public void invoke(Invokable,B,C> ivbc, B b, C c) { ivbc.invoke(this, b, c); } - public Iterator> iterator() { return new SingletonIterator>(this); } private final Input.Location location; private final T tag; @@ -123,6 +110,20 @@ public abstract class Forest /*extends PrintableTree>*/ implem public Forest resolve() { return this; } } + public abstract void invoke(Invokable,B,C> ivbc, B b, C c); + private static class TreeMaker extends HashSet> implements Invokable,Boolean,Integer> { + public ArrayList> toks = new ArrayList>(); + public void invoke(Forest.Body bod, Boolean toss, Integer i) { + if (i==null) { + ArrayList> toks = this.toks; + this.toks = new ArrayList>(); + bod.expand(toss, 0, this); + this.toks = toks; + } else { + bod.expand(toss, i, this); + } + } + } // Statics //////////////////////////////////////////////////////////////////////////////