X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FGrammar.java;fp=src%2Fedu%2Fberkeley%2Fsbp%2FGrammar.java;h=61856014f777bb84e1bddc1908b5e6cf4175936b;hp=d04ec0ab315aeb1aa30f9f1243ade137d2416303;hb=524d11f5988dd94b1977d78a5c9378a6f59f0cc9;hpb=a804bff254ea2ede83ba75b5235d7e3bd22a5ddb diff --git a/src/edu/berkeley/sbp/Grammar.java b/src/edu/berkeley/sbp/Grammar.java index d04ec0a..6185601 100644 --- a/src/edu/berkeley/sbp/Grammar.java +++ b/src/edu/berkeley/sbp/Grammar.java @@ -14,18 +14,19 @@ import java.util.*; * analyses depend on which elements *reference* a given element, * rather than which elements *are referenced by* a given element. * - * This class is package-private because it is likely to change often. + * All members of this class are package-private because they are + * likely to change often. */ -abstract class Grammar { +public abstract class Grammar { protected Union rootUnion; - public HashMap follow = new HashMap(); - public HashSet followEof = new HashSet(); - public final HashMap possiblyEpsilon = new HashMap(); - public HashSet all = new HashSet(); + HashMap follow = new HashMap(); + HashSet followEof = new HashSet(); + final HashMap possiblyEpsilon = new HashMap(); + HashSet all = new HashSet(); abstract Topology emptyTopology(); - public Grammar(Union root) { + Grammar(Union root) { this.rootUnion = root; if (root != null) for(Sequence s : root) @@ -34,9 +35,9 @@ abstract class Grammar { // Follow ////////////////////////////////////////////////////////////////////////////// - public Topology follow(Sequence s) { return follow.get(s); } + Topology follow(Sequence s) { return follow.get(s); } - public void buildFollowSet(Sequence seq, Topology followTopology, boolean eof) { + void buildFollowSet(Sequence seq, Topology followTopology, boolean eof) { all.add(seq); Topology old = follow.get(seq); if (old==null) old = followTopology; @@ -63,13 +64,13 @@ abstract class Grammar { } } - public Topology epsilonFollowSet(Union u) { + Topology epsilonFollowSet(Union u) { Topology ret = emptyTopology(); for(Sequence s : u) ret = ret.union(epsilonFollowSet(s, new HashSet())); return ret; } - public Topology epsilonFollowSet(Sequence seq, HashSet seen) { + Topology epsilonFollowSet(Sequence seq, HashSet seen) { Topology ret = seq.follow==null ? emptyTopology().complement() : seq.follow.getTokenTopology(); if (seen.contains(seq)) return ret; seen.add(seq); @@ -84,7 +85,7 @@ abstract class Grammar { return ret; } - public Topology first(SequenceOrElement e, HashSet seen) { + Topology first(SequenceOrElement e, HashSet seen) { if (e instanceof Atom) return ((Atom)e).getTokenTopology(); Topology ret = emptyTopology(); if (e instanceof Union) { @@ -127,13 +128,13 @@ abstract class Grammar { return ret; } - public boolean isRightNullable(Pos p) { + boolean isRightNullable(Pos p) { if (p.isLast()) return true; if (!possiblyEpsilon(p.element())) return false; return isRightNullable(p.next()); } - public boolean isNulledSubsequence(Sequence parent, Sequence potentialSubSequence) { + boolean isNulledSubsequence(Sequence parent, Sequence potentialSubSequence) { HashSet eq = new HashSet(); gatherNulledSubsequences(parent, eq); return eq.contains(potentialSubSequence); @@ -152,7 +153,7 @@ abstract class Grammar { // Pos Ordinality Comparisons ////////////////////////////////////////////////////////////////////////////// - public boolean canKill(Pos mep, Pos himp) { + boolean canKill(Pos mep, Pos himp) { if (!isRightNullable(mep)) return false; if (!isRightNullable(himp)) return false; Sequence me = mep.owner(); @@ -166,7 +167,7 @@ abstract class Grammar { return false; } - public boolean canNeed(Pos mep, Pos himp) { + boolean canNeed(Pos mep, Pos himp) { if (!isRightNullable(mep)) return false; if (!isRightNullable(himp)) return false; Sequence me = mep.owner(); @@ -180,7 +181,7 @@ abstract class Grammar { return false; } - public int comparePositions(Pos position, Pos rposition) { + int comparePositions(Pos position, Pos rposition) { int ret = 0; if (canKill(position, rposition) && canKill(rposition, position)) throw new Error(); if (canKill(position, rposition)) ret = -1;