X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=6b615dcd4460f7ffa3a0133474120924e0947294;hp=2eddfc4f01b1dcd163a6c11ea07ffa9ccef06846;hb=5d18f5606c9296e6b0c5749f05fc68f358ace2f6;hpb=420af63003ce87aaf07048665dc9c055f575140e diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index 2eddfc4..6b615dc 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -46,13 +46,11 @@ public abstract class Sequence extends Element implements Iterable { //////////////////////////////////////////////////////////////////////////////// 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(); } + public final Topology noFollow() { return noFollow==null ? null : Atom.toAtom(noFollow); } Topology toAtom() { if (elements.length!=1) throw new RuntimeException("cannot invoke toAtom() on a Sequence with " + elements.length + " elements: " + this); - return elements[0].toAtom(); + return Atom.toAtom(elements[0]); } protected final Element[] elements; @@ -74,12 +72,10 @@ public abstract class Sequence extends Element implements Iterable { // DO NOT MESS WITH THE FOLLOWING LINE!!! private Forest.Ref epsilonForm = null; - private boolean eps = false; Forest epsilonForm() { - if (epsilonForm==null) { - epsilonForm = new Forest.Ref(); - epsilonForm.merge(firstp().rewrite2(null)); - } + if (epsilonForm!=null) return epsilonForm; + epsilonForm = new Forest.Ref(); + epsilonForm.merge(firstp().rewrite(null, false)); return epsilonForm; } @@ -125,12 +121,9 @@ public abstract class Sequence extends Element implements Iterable { // Position ///////////////////////////////////////////////////////////////////////////////// - final Forest rewrite(Input.Location loc) { - if (this==firstp()) return epsilonForm(); - return rewrite2(loc); - } - - final Forest rewrite2(Input.Location loc) { + final Forest rewrite(Input.Location loc) { return rewrite(loc, true); } + private final Forest rewrite(Input.Location loc, boolean epsilonCheck) { + if (epsilonCheck && this==firstp()) return epsilonForm(); for(int i=0; i