////////////////////////////////////////////////////////////////////////////////
public Element noFollow = null;
+ public String name = null;
+ public void setName(String name) { this.name = name; }
public final Topology noFollow() { return noFollow==null ? null : noFollow.toAtom(); }
Topology toAtom() {
protected final Element[] elements;
+ HashSet<Sequence> needed;
+ HashSet<Sequence> hated;
final HashSet<Sequence> needs;
final HashSet<Sequence> hates;
- boolean lame = false;
+ public boolean lame = false;
final Position firstp;
Position firstp() { return firstp; }
protected Sequence(Element[] elements, HashSet<Sequence> and, HashSet<Sequence> not) {
this.needs = and==null ? new HashSet<Sequence>() : and;
this.hates = not==null ? new HashSet<Sequence>() : not;
+ if (this.needs != null)
+ for(Sequence s : this.needs)
+ (s.needed==null?(s.needed=new HashSet<Sequence>()):s.needed).add(this);
+ if (this.hates != null)
+ for(Sequence s : this.hates)
+ (s.hated==null?(s.hated=new HashSet<Sequence>()):s.hated).add(this);
this.elements = elements;
this.firstp = new Position(0);
}
Forest epsilonForm() {
if (epsilonForm==null) {
epsilonForm = new Forest.Ref();
- Forest fo = firstp().rewrite(null);
- epsilonForm.merge(fo);
+ epsilonForm.merge(firstp().rewrite2(null));
}
return epsilonForm;
}
// Reduction /////////////////////////////////////////////////////////////////////////////////
final <T> Forest<T> rewrite(Token.Location loc) {
- if (this==firstp() && eps) return epsilonForm;
- eps = true;
+ if (this==firstp()) return epsilonForm();
+ return rewrite2(loc);
+ }
+
+ final <T> Forest<T> rewrite2(Token.Location loc) {
for(int i=0; i<pos; i++) if (holder[i]==null) throw new Error("realbad " + i);
for(int i=pos; i<elements.length; i++) {
if (holder[i]==null) holder[i] = elements[i].epsilonForm();
}
Forest<T> ret = Sequence.this.postReduce(loc, holder);
for(int k=0; k<pos; k++) holder[k] = null; // to help GC
- if (this==firstp()) { if (epsilonForm==null) epsilonForm=new Forest.Ref(); epsilonForm.merge(ret); return epsilonForm; }
return ret;
}