X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=adf93fa64d35b8c645d7e3c72928f8585fdf2e03;hp=9f2fb59249c7f6890d36909a7bd912a494e665fd;hb=c366dacc334fe2e35835164f5a37d3eebb2ca6d5;hpb=9ded11559a1b6f817e99355b1c9e2c88042e91d4 diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index 9f2fb59..adf93fa 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -36,6 +36,8 @@ 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(); } Topology toAtom() { @@ -45,9 +47,11 @@ public abstract class Sequence extends Element implements Iterable { protected final Element[] elements; + HashSet needed; + HashSet hated; final HashSet needs; final HashSet hates; - boolean lame = false; + public boolean lame = false; final Position firstp; Position firstp() { return firstp; } @@ -56,6 +60,12 @@ 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; + if (this.needs != null) + for(Sequence s : this.needs) + (s.needed==null?(s.needed=new HashSet()):s.needed).add(this); + if (this.hates != null) + for(Sequence s : this.hates) + (s.hated==null?(s.hated=new HashSet()):s.hated).add(this); this.elements = elements; this.firstp = new Position(0); } @@ -66,8 +76,7 @@ public abstract class Sequence extends Element implements Iterable { Forest epsilonForm() { if (epsilonForm==null) { epsilonForm = new Forest.Ref(); - Forest fo = firstp().rewrite(null); - epsilonForm.merge(fo); + epsilonForm.merge(firstp().rewrite2(null)); } return epsilonForm; } @@ -112,8 +121,11 @@ public abstract class Sequence extends Element implements Iterable { // Reduction ///////////////////////////////////////////////////////////////////////////////// final Forest rewrite(Token.Location loc) { - if (this==firstp() && eps) return epsilonForm; - eps = true; + if (this==firstp()) return epsilonForm(); + return rewrite2(loc); + } + + final Forest rewrite2(Token.Location loc) { for(int i=0; i { } Forest ret = Sequence.this.postReduce(loc, holder); for(int k=0; k { private final Object result; public Constant(Element[] e, Object result, HashSet and, HashSet not) { super(e, and, not); this.result = result; } public Forest postReduce(Token.Location loc, Forest[] args) { - return (Forest)Forest.leaf(loc, result, this); + return (Forest)Forest.leaf(loc, result); } static class Drop extends Constant { public Drop(Element[] e, HashSet and, HashSet not, boolean lame) { @@ -174,7 +185,7 @@ public abstract class Sequence extends Element implements Iterable { private final int idx; public Singleton(Element e, HashSet and, HashSet not) { this(new Element[] { e }, 0, and, not); } public Singleton(Element[] e, int idx, HashSet and, HashSet not) { super(e, and, not); this.idx = idx; } - public Forest postReduce(Token.Location loc, Forest[] args) { return (Forest)Forest.singleton(loc, args[idx], this); } + public Forest postReduce(Token.Location loc, Forest[] args) { return (Forest)Forest.singleton(loc, args[idx]); } } public static class Unwrap extends Sequence { @@ -183,13 +194,13 @@ public abstract class Sequence extends Element implements Iterable { 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[] args2 = new Forest[count]; int j = 0; for(int i=0; i { int j = 0; for(int i=0; i