checkpoint harmony
authoradam <adam@megacz.com>
Wed, 11 Jan 2006 05:56:46 +0000 (00:56 -0500)
committeradam <adam@megacz.com>
Wed, 11 Jan 2006 05:56:46 +0000 (00:56 -0500)
darcs-hash:20060111055646-5007d-43e684dd054f777d270e1de4dd482fd995b1e3ea.gz

src/edu/berkeley/sbp/Parser.java
src/edu/berkeley/sbp/Sequence.java
src/edu/berkeley/sbp/Walk.java

index f642878..18bec5a 100644 (file)
@@ -91,7 +91,7 @@ public abstract class Parser<T extends Token, R> {
                     if (start0.contains(p.owner()) && p.next()==null)
                         state.accept = true;
 
-                    if (p.isRightNullable(cache)) {
+                    if (isRightNullable(p)) {
                         Walk.Follow wf = new Walk.Follow(top.empty(), p.owner(), all_elements, cache);
                         Reduction red = new Reduction(p);
 
@@ -121,6 +121,12 @@ public abstract class Parser<T extends Token, R> {
             }
         }
 
+        private boolean isRightNullable(Position p) {
+            if (p.isLast()) return true;
+            if (!p.element().possiblyEpsilon(this)) return false;
+            return isRightNullable(p.next());
+        }
+
         /** a single state in the LR table and the transitions possible from it */
 
         public class State implements Comparable<Table.State>, IntegerMappable, Iterable<Position> {
index adf93fa..d274013 100644 (file)
@@ -100,11 +100,6 @@ public abstract class Sequence extends Element implements Iterable<Element> {
         }
 
         boolean isFirst() { return pos==0; }
-        boolean isRightNullable(Walk.Cache cache) {
-            if (isLast()) return true;
-            if (!element().possiblyEpsilon(cache)) return false;
-            return next().isRightNullable(cache);
-        }
 
         /** the element immediately after this Position, or null if this is the last Position */
         public Element  element() { return pos>=elements.length ? null : elements[pos]; }
@@ -142,7 +137,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
             for(Position p = Sequence.this.firstp(); p != null; p = p.next()) {
                 ret.append(' ');
                 if (p==this) ret.append(" | ");
-                if (p.element()!=null) ret.append(p.element().possiblyEpsilon(null) ? "["+p.element()+"]" : p.element());
+                if (p.element()!=null) ret.append(p.element());
                 else                   ret.append(' ');
             }
             ret.append("}>");
index db76747..22ef52e 100644 (file)
@@ -170,7 +170,6 @@ abstract class Walk<T> {
         public final HashMap<Element,Boolean> possiblyEpsilon = new HashMap<Element,Boolean>();
         public HashMap<Element,Boolean> eof = new HashMap<Element,Boolean>();
         public HashMap<Element,Topology> follow = new HashMap<Element,Topology>();
-        //public HashMap<Element,HashSet<Element>>  ys            = new HashMap<Element,HashSet<Element>>();
         public HashMapBag<Element,Element>  ys = new HashMapBag<Element,Element>();
         public HashMap<Element,Topology> atoms = new HashMap<Element,Topology>();
     }