integermappable
authoradam <adam@megacz.com>
Sun, 8 Jan 2006 09:44:07 +0000 (04:44 -0500)
committeradam <adam@megacz.com>
Sun, 8 Jan 2006 09:44:07 +0000 (04:44 -0500)
darcs-hash:20060108094407-5007d-a309c996154ec8f0447c8395fb4bfec349b33bb3.gz

src/edu/berkeley/sbp/GSS.java
src/edu/berkeley/sbp/Parser.java
src/edu/berkeley/sbp/misc/CharToken.java
src/edu/berkeley/sbp/util/IntegerTopology.java
src/edu/berkeley/sbp/util/TopologicalBag.java

index 1adb8e4..a8f8053 100644 (file)
@@ -24,7 +24,8 @@ class GSS {
     HashSet<Phase.Waiting> tail = new     HashSet<Phase.Waiting>();
     
     /** corresponds to a positions <i>between tokens</i> the input stream; same as Tomita's U_i's */
-    public class Phase implements Invokable<State, Forest, GSS.Phase.Node> {
+    public class Phase implements Invokable<State, Forest, GSS.Phase.Node>, IntegerMappable {
+        public int toInt() { return pos+1; }
 
         /** the token immediately after this phase */
         public  final Token token;
@@ -304,7 +305,6 @@ class GSS {
             Forest res = null;
             boolean ok = false;
             for(Phase.Node n : hash.values()) {
-                //if (n.holder().empty() && pos>0) continue;
                 if (token == null && n.state.isAccepting()) {
                     if (finalResult==null) finalResult = new Forest.Ref();
                     finalResult.merge(n.holder);
@@ -398,7 +398,6 @@ class GSS {
                 this.fe = fe;
                 this.state = state;
                 this.holder().merge(pending);
-                //if (holder().empty()) throw new Error(holder()+"");
                 Phase start = parent==null ? null : parent.phase();
                 if (parent != null) parents().add(parent, true);
                 if (Phase.this.hash.get(code(state, start)) != null) throw new Error("severe problem!");
index 3609182..95c3985 100644 (file)
@@ -162,8 +162,10 @@ public abstract class Parser<T extends Token, R> {
         }
 
         /** a single state in the LR table and the transitions possible from it */
-        public class State implements Comparable<Table.State>, Iterable<Position> {
+        public class State implements Comparable<Table.State>, Iterable<Position>, IntegerMappable {
         
+            public int toInt() { return idx; }
+
             /*
             public boolean isResolvable(Token t) {
                 boolean found = false;
index 2df1a4a..0793d80 100644 (file)
@@ -9,7 +9,7 @@ import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
 
 /** an implementation of Token for streams of Java <tt>char</tt> values */
-public class CharToken implements Token, IntegerTopology.IntegerMappable {
+public class CharToken implements Token, IntegerMappable {
 
     // Public //////////////////////////////////////////////////////////////////////////////
 
index e1bec15..e82ce73 100644 (file)
@@ -7,7 +7,7 @@ import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
 
 /** implementation of <tt>Topology</tt> for any class for which there is a mapping to the <tt>int</tt>s */
-public class IntegerTopology<V extends IntegerTopology.IntegerMappable> implements Topology<V> {
+public class IntegerTopology<V extends IntegerMappable> implements Topology<V> {
     private final Range.Set rs;
 
     private static final IntegerTopology empty = new IntegerTopology();
@@ -67,7 +67,4 @@ public class IntegerTopology<V extends IntegerTopology.IntegerMappable> implemen
         return sb.toString();
     }
     */
-    public static interface IntegerMappable {
-        public int toInt();
-    }
 }
index 6c538e6..9a18eef 100644 (file)
@@ -157,7 +157,7 @@ public class TopologicalBag<K,V> implements MapBag<Topology<K>,V>, VisitableMap<
         final Object[][]   v = new Object[size][]; v_.toArray(v);
         return new VisitableMap<K,V>() {
             public boolean contains(K k) {
-                IntegerTopology.IntegerMappable im = (IntegerTopology.IntegerMappable)k;
+                IntegerMappable im = (IntegerMappable)k;
                 int asint = im.toInt();
                 for(int i=0; i<size; i++)
                     if (min[i] <= asint && max[i] >= asint && v[i].length > 0)
@@ -165,7 +165,7 @@ public class TopologicalBag<K,V> implements MapBag<Topology<K>,V>, VisitableMap<
                 return false;
             }
             public <B,C> void invoke(K k, Invokable<V,B,C> ivbc, B b, C c) {
-                IntegerTopology.IntegerMappable im = (IntegerTopology.IntegerMappable)k;
+                IntegerMappable im = (IntegerMappable)k;
                 int asint = im.toInt();
                 for(int i=0; i<size; i++) {
                     if (min[i] <= asint && max[i] >= asint) {