X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=634d6adc9e95082b274392919d01df8dd451c76a;hp=b00f069a57509fdb0ff23e553a98f118105d8ad5;hb=757a65beee80a2aedfab746b9e36269a41c5bcdc;hpb=c8a17fdd2e149fe5feecd96c71b7f2cab286ab96 diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index b00f069..634d6ad 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -77,12 +77,9 @@ public abstract class Forest /*extends PrintableTree>*/ public InnerAmbiguous(Forest f) { this.f = f; } } - static Forest singleton(Input.Region loc, Position p) { - return create(loc, null, new Forest[] { }, false, true, p); } - static Forest singleton(Input.Region loc, Forest body, Position p) { return body; } - static Forest leaf(Input.Region loc, T tag, Position p) { return create(loc, tag, null, false, false, p); } - public static Forest create(Input.Region loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton, Position p) { - return new MyBody(loc, tag, tokens, unwrap, singleton, p); + static Forest leaf(Input.Region loc, T tag) { return create(loc, tag, null, false); } + public static Forest create(Input.Region loc, T tag, Forest[] tokens, boolean unwrap) { + return new MyBody(loc, tag, tokens, unwrap); } // Body ////////////////////////////////////////////////////////////////////////////// @@ -93,6 +90,11 @@ public abstract class Forest /*extends PrintableTree>*/ public boolean ambiguous() { return false; } public /*protected*/ static class MyBody extends Forest implements Body /* extends PrintableTree> implements */ { + private final Input.Region location; + private final T tag; + private final Forest[] tokens; + private final boolean unwrap; + public boolean isTransparent() { return false; } public boolean isHidden() { return false; } public GraphViz.Node toGraphViz(GraphViz gv) { @@ -100,7 +102,7 @@ public abstract class Forest /*extends PrintableTree>*/ GraphViz.Node n = gv.createNode(this); n.label = headToString()==null?"":headToString(); n.directed = true; - n.comment = reduction==null?null:reduction+""; + //n.comment = reduction==null?null:reduction+""; edges(n); return n; } @@ -121,32 +123,24 @@ public abstract class Forest /*extends PrintableTree>*/ ivbc.invoke(this, b, c); } - private final Input.Region location; - private final T tag; - private final Forest[] tokens; - private final boolean unwrap; - private final boolean singleton; - private final Sequence.Position reduction; - - private MyBody(Input.Region loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton, Position reduction) { + private MyBody(Input.Region loc, T tag, Forest[] tokens, boolean unwrap) { this.location = loc; this.tag = tag; this.tokens = tokens==null ? emptyForestArray : new Forest[tokens.length]; if (tokens != null) System.arraycopy(tokens, 0, this.tokens, 0, tokens.length); if (tokens != null) for(int i=0; i>[] ht, HashSet> target) { gather(tl, ht, target, new Tree[ht.length], 0); } private void gather(TaskList tl, HashSet>[] ht, HashSet> target, Tree[] trees, int i) { if (i==ht.length) { - target.add(new Tree(location, tag, trees)); + target.add(new Tree(location, tag, trees, unwrap)); return; } for(Tree tree : ht[i]) { + /* if (unwrap && i==trees.length-1) { // I think this is wrong Tree[] trees2 = new Tree[trees.length - 1 + tree.numChildren()]; @@ -155,17 +149,14 @@ public abstract class Forest /*extends PrintableTree>*/ trees2[trees.length-1+j] = tree.child(j); target.add(new Tree(location, tag, trees2)); } else { + */ trees[i] = tree; gather(tl, ht, target, trees, i+1); trees[i] = null; - } + //} } } public void expand(TaskList tl, HashSet> ht) { - if (singleton) { - tokens[0].expand(tl, ht); - return; - } HashSet>[] children = new HashSet[tokens.length]; tl.gather(this, children, ht); for(int i=0; i /*extends PrintableTree>*/ } public void expand(final int i, final TreeBuilder h) { - if (singleton) { - tokens[0].visit(h, null, i); - return; - } if (i==0) h.start(tag, location); if (i==tokens.length) { h.finish(tag, location); + /* } else if (unwrap && i==tokens.length-1) { if (tokens[i] != null) tokens[i].visit(h, null, 0); + */ } else { tokens[i].visit(new TreeBuilder(h.toss) { @@ -194,7 +183,7 @@ public abstract class Forest /*extends PrintableTree>*/ public void addTree(Tree t) { toks.add(t); } public void finish(T head, Input.Region loc) { int old = h.toks.size(); - h.addTree(new Tree(loc, head, toks.toArray(tree_hint))); + h.addTree(new Tree(loc, head, toks.toArray(tree_hint), unwrap)); expand(i+1, h); while(h.toks.size() > old) h.toks.remove(h.toks.size()-1); }