From: adam Date: Fri, 21 Jul 2006 02:52:02 +0000 (-0400) Subject: checkpoint X-Git-Tag: tag_for_25-Mar~108 X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=d28917b3c84c429e8fd6587717df9e90a894b18f checkpoint darcs-hash:20060721025202-5007d-aa328d4455d0a597f8efbffe70844426e528abc7.gz --- diff --git a/src/edu/berkeley/sbp/Atom.java b/src/edu/berkeley/sbp/Atom.java index 306e126..0a8ad12 100644 --- a/src/edu/berkeley/sbp/Atom.java +++ b/src/edu/berkeley/sbp/Atom.java @@ -7,12 +7,19 @@ import edu.berkeley.sbp.util.*; import edu.berkeley.sbp.*; import edu.berkeley.sbp.*; -/** an element which matches exactly one input token */ +/** + * an element which matches some set of one-token-long input strings. + * + * This class is a topology over itself so that Atoms can be + * intersected and unioned with each other to result in other + * Atom's (rather than raw Topology's, which are not Elements). + * If you want the latter, use the getTokenTopology() method. + */ public abstract class Atom extends Element implements Topology> { - public abstract Topology 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 getTokenTopology(); + public abstract StringBuffer toString(StringBuffer sb); } diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index a440628..9825a9f 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -144,7 +144,7 @@ public abstract class Parser { // 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 state : all_states.values()) { @@ -237,7 +237,7 @@ public abstract class Parser { Atom a = (Atom)position.element(); HashSet hp = new HashSet(); 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 diff --git a/src/edu/berkeley/sbp/Walk.java b/src/edu/berkeley/sbp/Walk.java index b3432a9..c6bb514 100644 --- a/src/edu/berkeley/sbp/Walk.java +++ b/src/edu/berkeley/sbp/Walk.java @@ -88,7 +88,7 @@ abstract class Walk { public WalkTokenSet(Topology cs) { this.cs = cs; } public WalkTokenSet(Topology cs, Cache c) { super(c); this.cs = cs; } public Topology bottom(Element e) { return cs; } - public Topology walkAtom(Atom r) { cs = cs.union(r.underlying()); return cs; } + public Topology walkAtom(Atom r) { cs = cs.union(r.getTokenTopology()); return cs; } } static class First extends WalkTokenSet { @@ -155,7 +155,7 @@ abstract class Walk { 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) { diff --git a/src/edu/berkeley/sbp/chr/CharAtom.java b/src/edu/berkeley/sbp/chr/CharAtom.java index 89a45ad..f2f8e62 100644 --- a/src/edu/berkeley/sbp/chr/CharAtom.java +++ b/src/edu/berkeley/sbp/chr/CharAtom.java @@ -10,6 +10,8 @@ import edu.berkeley.sbp.Input.Location; public class CharAtom extends Atom { + 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)); } @@ -26,7 +28,6 @@ public class CharAtom extends Atom { 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 */ @@ -55,7 +56,7 @@ public class CharAtom extends Atom { public Topology> unwrap() { return this; } public Topology> empty() { return new CharAtom(); } - public Topology underlying() { return top(); } + public Topology getTokenTopology() { return top(); } public boolean contains(Atom v) { return top().containsAll(((CharAtom)v).top()); } public boolean disjoint(Topology> t) { return top().disjoint(((CharAtom)t).top()); }