X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=b31b307ad39b466b0ac54517cb5683a2b551b84d;hb=a7b84506c2e1ed63343db215f76afced082e2826;hp=d8f39fd860301538c3eee496144f19564f9ad6e6;hpb=aeae43c3255b14e4ba65e0171b87c48bbf953c31;p=sbp.git diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index d8f39fd..b31b307 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -81,13 +81,13 @@ public abstract class Sequence extends Element implements Iterable { return epsilonForm; } - protected abstract Forest postReduce(Token.Location loc, Forest[] args); + protected abstract Forest postReduce(Input.Location loc, Forest[] args); // Position ////////////////////////////////////////////////////////////////////////////// /** the imaginary position before or after an element of a sequence; corresponds to an "LR item" */ - public class Position { + public class Position implements IntegerMappable { private Forest zero = null; public Forest zero() { @@ -123,12 +123,12 @@ public abstract class Sequence extends Element implements Iterable { // Position ///////////////////////////////////////////////////////////////////////////////// - final Forest rewrite(Token.Location loc) { + final Forest rewrite(Input.Location loc) { if (this==firstp()) return epsilonForm(); return rewrite2(loc); } - final Forest rewrite2(Token.Location loc) { + final Forest rewrite2(Input.Location loc) { for(int i=0; i { ret.append("}>"); return ret.toString(); } + private final int idx = master_position_idx++; + public int toInt() { return idx; } } - + private static int master_position_idx = 0; // toString ////////////////////////////////////////////////////////////////////////////// @@ -172,7 +174,7 @@ public abstract class Sequence extends Element implements Iterable { static class Constant extends Sequence { 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) { + public Forest postReduce(Input.Location loc, Forest[] args) { return (Forest)Forest.leaf(loc, result); } static class Drop extends Constant { @@ -188,14 +190,14 @@ 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]); } + public Forest postReduce(Input.Location loc, Forest[] args) { return (Forest)Forest.singleton(loc, args[idx]); } } 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) { + public Forest postReduce(Input.Location loc, Forest[] args) { for(int i=0; i { this.drops = drops == null ? new boolean[e.length] : drops; for(int i=0; i Forest postReduce(Token.Location loc, Forest[] args) { + public Forest postReduce(Input.Location loc, Forest[] args) { Forest[] args2 = new Forest[count]; int j = 0; for(int i=0; i