checkpoint
authoradam <adam@megacz.com>
Fri, 21 Jul 2006 02:52:02 +0000 (22:52 -0400)
committeradam <adam@megacz.com>
Fri, 21 Jul 2006 02:52:02 +0000 (22:52 -0400)
darcs-hash:20060721025202-5007d-aa328d4455d0a597f8efbffe70844426e528abc7.gz

src/edu/berkeley/sbp/Atom.java
src/edu/berkeley/sbp/Parser.java
src/edu/berkeley/sbp/Walk.java
src/edu/berkeley/sbp/chr/CharAtom.java

index 306e126..0a8ad12 100644 (file)
@@ -7,12 +7,19 @@ import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.*;
 
 import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.*;
 
-/** <font color=green>an element which matches exactly one input token</font> */
+/**
+ *  <font color=green>an element which matches some set of one-token-long input strings</font>.
+ *
+ *  This class is a topology over itself so that Atoms can be
+ *  intersected and unioned with each other to result in other
+ *  Atom<T>'s (rather than raw Topology<T>'s, which are not Elements).
+ *  If you want the latter, use the getTokenTopology() method.
+ */
 public abstract class Atom<T> extends Element implements Topology<Atom<T>> {
 
 public abstract class Atom<T> extends Element implements Topology<Atom<T>> {
 
-    public  abstract Topology<T>  underlying();
-    public  abstract String       toString();
-    public           StringBuffer toString(StringBuffer sb) { sb.append(this); return sb; }
+    /** the set (topology) of tokens that can match this element */
+    public abstract Topology<T>  getTokenTopology();
 
 
+    public abstract StringBuffer toString(StringBuffer sb);
 }
 
 }
 
index a440628..9825a9f 100644 (file)
@@ -144,7 +144,7 @@ public abstract class Parser<Tok, Result> {
                     // if the element following this position is an atom, copy the corresponding
                     // set of rows out of the "master" goto table and into this state's shift table
                     if (p.element() != null && p.element() instanceof Atom)
                     // if the element following this position is an atom, copy the corresponding
                     // set of rows out of the "master" goto table and into this state's shift table
                     if (p.element() != null && p.element() instanceof Atom)
-                        state.shifts.addAll(state.gotoSetTerminals.subset(((Atom)p.element()).underlying()));
+                        state.shifts.addAll(state.gotoSetTerminals.subset(((Atom)p.element()).getTokenTopology()));
                 }
             if (top instanceof IntegerTopology)
                 for(State<Tok> state : all_states.values()) {
                 }
             if (top instanceof IntegerTopology)
                 for(State<Tok> state : all_states.values()) {
@@ -237,7 +237,7 @@ public abstract class Parser<Tok, Result> {
                     Atom a = (Atom)position.element();
                     HashSet<Position> hp = new HashSet<Position>();
                     reachable(position.next(), hp);
                     Atom a = (Atom)position.element();
                     HashSet<Position> hp = new HashSet<Position>();
                     reachable(position.next(), hp);
-                    bag0.addAll(a.underlying(), hp);
+                    bag0.addAll(a.getTokenTopology(), hp);
                 }
 
                 // Step 1b: for each _minimal, contiguous_ set of characters having an identical next-position
                 }
 
                 // Step 1b: for each _minimal, contiguous_ set of characters having an identical next-position
index b3432a9..c6bb514 100644 (file)
@@ -88,7 +88,7 @@ abstract class Walk<T> {
         public WalkTokenSet(Topology<Tok> cs)          { this.cs = cs; }
         public WalkTokenSet(Topology<Tok> cs, Cache c) { super(c); this.cs = cs; }
         public Topology<Tok> bottom(Element e)         { return cs; }
         public WalkTokenSet(Topology<Tok> cs)          { this.cs = cs; }
         public WalkTokenSet(Topology<Tok> cs, Cache c) { super(c); this.cs = cs; }
         public Topology<Tok> bottom(Element e)         { return cs; }
-        public Topology<Tok> walkAtom(Atom r)          { cs = cs.union(r.underlying()); return cs; }
+        public Topology<Tok> walkAtom(Atom r)          { cs = cs.union(r.getTokenTopology()); return cs; }
     }
 
     static class First<Tok extends Input> extends WalkTokenSet<Tok> {
     }
 
     static class First<Tok extends Input> extends WalkTokenSet<Tok> {
@@ -155,7 +155,7 @@ abstract class Walk<T> {
 
             if (e instanceof Sequence) {
                 Sequence s = (Sequence)e;
 
             if (e instanceof Sequence) {
                 Sequence s = (Sequence)e;
-                if (s.follow() != null) cs = cs.intersect(s.follow().underlying());
+                if (s.follow() != null) cs = cs.intersect(s.follow().getTokenTopology());
             }
 
             if (c != null && e==me) {
             }
 
             if (c != null && e==me) {
index 89a45ad..f2f8e62 100644 (file)
@@ -10,6 +10,8 @@ import edu.berkeley.sbp.Input.Location;
 
 public class CharAtom extends Atom<Character> {
 
 
 public class CharAtom extends Atom<Character> {
 
+    public StringBuffer toString(StringBuffer sb) { sb.append(this); return sb; }
+
     public CharAtom() { this(new CharTopology()); }
     public CharAtom(char a) { this(a,a); }
     public CharAtom(char a, char b) { this(new CharTopology(a, b)); }
     public CharAtom() { this(new CharTopology()); }
     public CharAtom(char a) { this(a,a); }
     public CharAtom(char a, char b) { this(new CharTopology(a, b)); }
@@ -26,7 +28,6 @@ public class CharAtom extends Atom<Character> {
     public static final Atom braces     = new CharAtom(left,right)   { public String toString() { return "[{}]"; } };
 
     public static Atom set(Range.Set r) { return new CharAtom(new CharTopology(r)); }
     public static final Atom braces     = new CharAtom(left,right)   { public String toString() { return "[{}]"; } };
 
     public static Atom set(Range.Set r) { return new CharAtom(new CharTopology(r)); }
-
     public String toString() { return t.toString(); }
 
     /** returns an element which exactly matches the string given */
     public String toString() { return t.toString(); }
 
     /** returns an element which exactly matches the string given */
@@ -55,7 +56,7 @@ public class CharAtom extends Atom<Character> {
 
     public Topology<Atom<Character>>       unwrap() { return this; }
     public Topology<Atom<Character>>       empty()  { return new CharAtom(); }
 
     public Topology<Atom<Character>>       unwrap() { return this; }
     public Topology<Atom<Character>>       empty()  { return new CharAtom(); }
-    public Topology<Character>             underlying()  { return top(); }
+    public Topology<Character>             getTokenTopology()  { return top(); }
 
     public boolean           contains(Atom<Character> v) { return top().containsAll(((CharAtom)v).top()); }
     public boolean           disjoint(Topology<Atom<Character>> t) { return top().disjoint(((CharAtom)t).top()); }
 
     public boolean           contains(Atom<Character> v) { return top().containsAll(((CharAtom)v).top()); }
     public boolean           disjoint(Topology<Atom<Character>> t) { return top().disjoint(((CharAtom)t).top()); }