X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=cf64ed272a57322dd12473acf5c44049a07bf920;hp=1730f607eba82daeb513f88053b53d08137a33e2;hb=dc9bb3a45ed306e2e35549076842b3e74efecb48;hpb=449c39e0dafd7c736bfcd8d56bbd08b7a99e25a4 diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 1730f60..cf64ed2 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -1,12 +1,9 @@ // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license package edu.berkeley.sbp; -import edu.berkeley.sbp.*; -import edu.berkeley.sbp.Sequence.Position; import edu.berkeley.sbp.util.*; import java.io.*; import java.util.*; -import java.lang.reflect.*; /** * @@ -20,26 +17,31 @@ public abstract class Forest implements GraphViz.ToGraphViz { public abstract Tree expand1() throws Ambiguous; /** expand this forest into a set of trees */ - public void expand(HashSet> ht) { expand(ht, new HashSet>(), null); } - - static Forest create(Input.Region loc, NodeType head, Forest[] children, boolean lift) { - if (loc == null) throw new RuntimeException("invoked Forest.create(null,,,,) -- this should never happen"); - return new One(loc, head, children, lift); + public Iterable> expand() { + HashSet> ht = new HashSet>(); + expand(ht, new HashSet>(), null); + return ht; } - /** create a new forest */ - public static Forest create(Input.Region loc, NodeType head, Forest[] children) { - return Forest.create(loc, head, children, false); } + /** returns the input Region which this Forest was parsed from */ + public abstract Input.Region getRegion(); // Package-Private ////////////////////////////////////////////////////////////////////////////// + static Forest create(Input.Region region, NodeType head, Forest[] children, boolean lift) { + if (region == null) throw new RuntimeException("invoked Forest.create(region=null) -- this should never happen"); + return new One(region, head, children, lift); + } + + /** create a new forest */ + public static Forest create(Input.Region region, NodeType head, Forest[] children) { + return Forest.create(region, head, children, false); } + abstract void expand(HashSet> ht, HashSet> ignore, Tree bogus); abstract void gather(HashSet> ignore); abstract void edges(GraphViz.Node n); boolean ambiguous() { return false; } - abstract Input.Region getRegion(); - // One ////////////////////////////////////////////////////////////////////////////// /** A "single" forest with a head and child subforests */ @@ -52,7 +54,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { /** if true, the last child's children are considered children of this node */ private final boolean lift; - Input.Region getRegion() { return location; } + public Input.Region getRegion() { return location; } private One(Input.Region loc, NodeType head, Forest[] children, boolean lift) { this.location = loc; @@ -78,7 +80,8 @@ public abstract class Forest implements GraphViz.ToGraphViz { if (ignore.contains(this)) { ht.add(bogus); return; } expand(0, new Tree[children.length], ht, ignore, bogus); } - private void expand(final int i, Tree[] ta, HashSet> ht, HashSet> ignore, Tree bogus) { + private void expand(final int i, Tree[] ta, HashSet> ht, HashSet> ignore, + Tree bogus) { if (i==children.length) { ht.add(new Tree(location, head, ta, lift)); } else { @@ -135,7 +138,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { public Many() { } - Input.Region getRegion() { return hp.iterator().next().getRegion(); } // all should be identical + public Input.Region getRegion() { return hp.iterator().next().getRegion(); } // all should be identical public Tree expand1() throws Ambiguous { touched();