checkpoint harmony
[sbp.git] / src / edu / berkeley / sbp / Sequence.java
index d274013..d8f39fd 100644 (file)
@@ -89,6 +89,14 @@ public abstract class Sequence extends Element implements Iterable<Element> {
     /** the imaginary position before or after an element of a sequence; corresponds to an "LR item" */
     public class Position {
 
+        private Forest zero = null;
+        public Forest zero() {
+            if (zero != null) return zero;
+            if (pos > 0) throw new Error();
+            return zero = rewrite(null);
+        }
+
+
                 final int      pos;
         private final Position next;
                 final Forest[] holder;
@@ -113,7 +121,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
         /** true iff this Position is the last one in the sequence */
         public boolean isLast() { return next()==null; }
 
-        // Reduction /////////////////////////////////////////////////////////////////////////////////
+        // Position /////////////////////////////////////////////////////////////////////////////////
 
         final <T> Forest<T> rewrite(Token.Location loc) {
             if (this==firstp()) return epsilonForm();