X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=ee3fd4ba2090f082f5c669051c291c50e78a8b08;hp=e18f5efc5ca56271fa6e225e75e0bf07d7062cbd;hb=8e38701ecbc92deab21c4c224052ae128b279738;hpb=242a8711e98cbd3ed6d05271bf910fde38e9be9a diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index e18f5ef..ee3fd4b 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -56,15 +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); } - void reachable(HashSet h) { firstp().reachable(h); } - - 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); @@ -74,12 +80,6 @@ public abstract class Sequence extends Element implements Iterable { /** the imaginary position before or after an element of a sequence; corresponds to an "LR item" */ public class Position { - void reachable(HashSet h) { - if (h.contains(this)) return; - h.add(this); - if (element() != null) element().reachable(h); - } - final int pos; private final Position next; final Forest[] holder; @@ -111,10 +111,13 @@ public abstract class Sequence extends Element implements Iterable { // Reduction ///////////////////////////////////////////////////////////////////////////////// - Forest rewrite(Token.Location loc) { + final Forest rewrite(Token.Location loc) { + if (this==firstp() && eps) return epsilonForm; + eps = true; for(int i=pos; i ret = Sequence.this.postReduce(loc, holder); for(int k=0; k { Forest[] args2 = new Forest[count]; int j = 0; for(int i=0; i