X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=31d8f29ad4061cca5812ef6d819b5025d983ebf6;hb=23091054a6842031d168c2628216c2310149cc5d;hp=0ac3500bfd476d358c509062fdc2785dce43b54b;hpb=c8a17fdd2e149fe5feecd96c71b7f2cab286ab96;p=sbp.git diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index 0ac3500..31d8f29 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -45,16 +45,13 @@ public abstract class Sequence extends Element implements Iterable { public static Sequence rewritingSequence(Object tag, Element[] e, boolean[] drops) { return new RewritingSequence(tag, e, drops); } - //////////////////////////////////////////////////////////////////////////////// + public static Sequence regionRewritingSequence(Functor tagfunctor, Element[] e, boolean[] drops) { + return new RegionRewritingSequence(tagfunctor, e, drops); } - public Element follow = null; - public final Topology follow() { return follow==null ? null : Atom.toAtom(follow); } + //////////////////////////////////////////////////////////////////////////////// - Topology toAtom() { - if (elements.length!=1) - throw new RuntimeException("cannot invoke toAtom() on a Sequence with " + elements.length + " elements: " + this); - return Atom.toAtom(elements[0]); - } + public Atom follow = null; + public final Topology follow() { return follow; } public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); s.needed.add(ret); return ret; } public Sequence not(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); return ret; } @@ -77,10 +74,10 @@ public abstract class Sequence extends Element implements Iterable { } // DO NOT MESS WITH THE FOLLOWING LINE!!! - private Forest.Ref epsilonForm = null; + private Forest.Many epsilonForm = null; Forest epsilonForm() { if (epsilonForm!=null) return epsilonForm; - epsilonForm = new Forest.Ref(); + epsilonForm = new Forest.Many(); epsilonForm.merge(firstp().rewrite(null, false)); return epsilonForm; } @@ -181,7 +178,7 @@ public abstract class Sequence extends Element implements Iterable { public Constant(Element[] e, Object result) { super(e); this.result = result; } Sequence _clone() { return new Constant(elements, result); } public Forest postReduce(Input.Region loc, Forest[] args, Position p) { - return (Forest)Forest.leaf(loc, result, p); + return (Forest)Forest.create(loc, result, null, false); } static class Drop extends Constant { Sequence _clone() { return new Drop(elements, lame); } @@ -199,7 +196,7 @@ public abstract class Sequence extends Element implements Iterable { private final int idx; public Singleton(Element e) { this(new Element[] { e }, 0); } public Singleton(Element[] e, int idx) { super(e); this.idx = idx; } - public Forest postReduce(Input.Region loc, Forest[] args, Position p) { return (Forest)Forest.singleton(loc, args[idx], p); } + public Forest postReduce(Input.Region loc, Forest[] args, Position p) { return args[idx]; } Sequence _clone() { return new Singleton(elements,idx); } } @@ -212,18 +209,34 @@ public abstract class Sequence extends Element implements Iterable { Sequence _clone() { return new Unwrap(elements, drops); } public Forest postReduce(Input.Region loc, Forest[] args, Position p) { for(int i=0; i[] args2 = new Forest[count]; int j = 0; for(int i=0; i tagf; + public RegionRewritingSequence(Functor tagfunctor, Element[] e, boolean[] drops) { + super(null, e, drops); + this.tagf = tagfunctor; + } + public Forest postReduce(Input.Region loc, Forest[] args, Position p) { + this.tag = tagf.invoke(loc); + Forest ret = super.postReduce(loc, args, p); + this.tag = null; + return ret; } } static class RewritingSequence extends Sequence { - /*private*/public final Object tag; + /*private*/public /*final*/ Object tag; private final boolean[] drops; private int count = 0; Sequence _clone() { return new RewritingSequence(tag, elements, drops); } @@ -239,7 +252,7 @@ public abstract class Sequence extends Element implements Iterable { int j = 0; for(int i=0; i