+// 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;
public void expand(HashSet<Tree<NodeType>> ht) { expand(ht, new HashSet<Forest<NodeType>>(), null); }
static <NodeType> Forest<NodeType> create(Input.Region loc, NodeType head, Forest<NodeType>[] children, boolean lift) {
+ if (loc == null) throw new Error();
return new One<NodeType>(loc, head, children, lift);
}
abstract void gather(HashSet<Forest<NodeType>> ignore);
abstract void edges(GraphViz.Node n);
boolean ambiguous() { return false; }
-
+
+ abstract Input.Region getRegion();
// One //////////////////////////////////////////////////////////////////////////////
/** if true, the last child's children are considered children of this node */
private final boolean lift;
+ Input.Region getRegion() { return location; }
+
private One(Input.Region loc, NodeType head, Forest<NodeType>[] children, boolean lift) {
this.location = loc;
this.head = head;
/** An "ambiguity node"; this is immutable once it has been "looked at" */
static class Many<NodeType> extends Forest<NodeType> {
- HashSet<GSS.Phase.Node> parents = new HashSet<GSS.Phase.Node>();
private FastSet<Forest<NodeType>> hp = new FastSet<Forest<NodeType>>();
private boolean touched = false;
public Many() { }
+ Input.Region getRegion() { return hp.iterator().next().getRegion(); } // all should be identical
+
public Tree<NodeType> expand1() throws Ambiguous {
touched();
if (hp.size() > 1) {
void gather(HashSet<Forest<NodeType>> ht) {
touched();
+
+ // FIXME: do something more sensible here
+ if (ht.contains(this)) {
+ System.err.println("WARNING: grammar produced a circular forest\n" + this);
+ //throw new Error("grammar produced a circular forest:\n" + this);
+ return;
+ }
+
ht.add(this);
for(Forest<NodeType> f : hp) f.gather(ht);
}