Immediately
- do Forest/Tree still need a Region?
+ - reconsider the degree of genericization
+ - GraphViz stuff pollutes the API...
- Forest needs a "manual access" API
- the unwrap bit in Forest makes it really hard to expose an API for forests
abstract void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus);
abstract void gather(HashSet<Forest<T>> ignore);
+ abstract void edges(GraphViz.Node n);
boolean ambiguous() { return false; }
- public abstract void edges(GraphViz.Node n);
-
// One //////////////////////////////////////////////////////////////////////////////
import java.lang.reflect.*;
/** implements Tomita's Graph Structured Stack */
-public class GSS {
+class GSS {
- public static int count = 0;
- public static int shifts = 0;
- public static int reductions = 0;
+ static int count = 0;
+ static int shifts = 0;
+ static int reductions = 0;
+ int resets = 0;
+ int waits = 0;
public GSS() { }
private Phase.Node[] reducing_list = null;
- public int resets = 0;
- public int waits = 0;
// FIXME: right now, these are the performance bottleneck
HashMapBag<Sequence,Phase.Waiting> waiting = new HashMapBag<Sequence,Phase.Waiting>();
HashMapBag<Integer,Sequence> expected = new HashMapBag<Integer,Sequence>();
/** FIXME */
- public Forest.Many finalResult;
+ Forest.Many finalResult;
/** corresponds to a positions <i>between tokens</i> the input stream; same as Tomita's U_i's */
class Phase<Tok> implements Invokable<State, Forest, Phase<Tok>.Node>, IntegerMappable, GraphViz.ToGraphViz, Iterable<Phase.Node> {
protected Parser(Table<Tok> pt) { this.pt = pt; }
/** implement this method to create the output forest corresponding to a lone shifted input token */
- public abstract Forest<Result> shiftToken(Input.Location oldloc, Tok t, Input.Location newloc);
+ protected abstract Forest<Result> shiftToken(Input.Location oldloc, Tok t, Input.Location newloc);
- public boolean helpgc = true;
+ boolean helpgc = true;
public String toString() { return pt.toString(); }
public boolean isTransparent() { return false; }
public boolean isHidden() { return false; }
-
}
/** an element which can produce one of several alternatives */
public class Union extends Element implements Iterable<Sequence> {
+ private final String name;
+ private final boolean synthetic;
+ private final List<Sequence> alternatives = new ArrayList<Sequence>();
+
/**
* Since every cycle in a non-degenerate grammar contains at
* least one Union, every instance of this class must be able to
* @param synthetic if true, this Union's "long form" is "obvious" and should not be displayed when printing the grammar
*/
public Union() { this(null, false); }
- public Union(String shortForm) { this(shortForm, false); }
- public Union(String shortForm, boolean synthetic) {
- this.shortForm = shortForm;
+ public Union(String name) { this(name, false); }
+ public Union(String name, boolean synthetic) {
+ this.name = name;
this.synthetic = synthetic;
}
- final String shortForm;
- final boolean synthetic;
- private final List<Sequence> alternatives = new ArrayList<Sequence>();
-
public Iterator<Sequence> iterator() { return alternatives.iterator(); }
public boolean contains(Sequence s) { return alternatives.contains(s); }
// Display //////////////////////////////////////////////////////////////////////////////
public String getName() {
- if (shortForm != null) return shortForm;
+ if (name != null) return name;
return "(anon_union)";
}
public String toString() {
- if (shortForm != null) return shortForm;
+ if (name != null) return name;
StringBuffer sb = new StringBuffer();
sb.append("(");
bodyToString(sb, "", " | ");