X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=9f2fb59249c7f6890d36909a7bd912a494e665fd;hp=b33279352a9a6b61c4cfd4bfa3e29629c3670e6f;hb=9ded11559a1b6f817e99355b1c9e2c88042e91d4;hpb=84a4a8204373b996105e69edf91d2f9fae7b4bcb diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index b332793..9f2fb59 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -56,13 +56,21 @@ public abstract class Sequence extends Element implements Iterable { protected Sequence(Element[] elements, HashSet and, HashSet not) { this.needs = and==null ? new HashSet() : and; this.hates = not==null ? new HashSet() : not; - //for(Sequence s : needs) s.lame = true; - //for(Sequence s : hates) s.lame = true; this.elements = elements; this.firstp = new Position(0); } - Forest epsilonForm() { return firstp().rewrite(null); } + // 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(); + Forest fo = firstp().rewrite(null); + epsilonForm.merge(fo); + } + return epsilonForm; + } protected abstract Forest postReduce(Token.Location loc, Forest[] args); @@ -103,10 +111,17 @@ public abstract class Sequence extends Element implements Iterable { // Reduction ///////////////////////////////////////////////////////////////////////////////// - Forest rewrite(Token.Location loc) { - for(int i=pos; i Forest rewrite(Token.Location loc) { + if (this==firstp() && eps) return epsilonForm; + eps = true; + for(int i=0; i ret = Sequence.this.postReduce(loc, holder); for(int k=0; k { public Forest postReduce(Token.Location loc, Forest[] args) { return (Forest)Forest.singleton(loc, args[idx], this); } } - static class Unwrap extends Sequence { + public static class Unwrap extends Sequence { private boolean[] drops; public Unwrap(Element[] e, HashSet and, HashSet not) { super(e, and, not); this.drops = null; } public Unwrap(Element[] e, boolean[] drops, HashSet and, HashSet not) { super(e, and, not); this.drops = drops; } public Forest postReduce(Token.Location loc, Forest[] args) { + for(int i=0; i { } static class RewritingSequence extends Sequence { - private final Object tag; + /*private*/public final Object tag; private final boolean[] drops; private int count = 0; public RewritingSequence(Object tag, Element[] e, HashSet and, HashSet not) { this(tag, e, null, and, not); } @@ -192,6 +208,7 @@ public abstract class Sequence extends Element implements Iterable { Forest[] args2 = new Forest[count]; int j = 0; for(int i=0; i