From: Adam Megacz Date: Thu, 21 Jan 2010 18:10:01 +0000 (-0800) Subject: fix build issues with CommandLine.java X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=524d11f5988dd94b1977d78a5c9378a6f59f0cc9 fix build issues with CommandLine.java --- 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; diff --git a/src/edu/berkeley/sbp/meta/MetaGrammar.java b/src/edu/berkeley/sbp/meta/MetaGrammar.java index e35b389..79cd3f5 100644 --- a/src/edu/berkeley/sbp/meta/MetaGrammar.java +++ b/src/edu/berkeley/sbp/meta/MetaGrammar.java @@ -10,7 +10,7 @@ import java.lang.annotation.*; import java.lang.reflect.*; import java.io.*; -class MetaGrammar { +public class MetaGrammar { /** Used to rebuild MetaGrammar.java, and not for much else */ public static void main(String[] args) throws Exception { @@ -34,7 +34,7 @@ class MetaGrammar { out.append("\n // DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED\n"); - Union u = GrammarAST.buildFromAST(MetaGrammar.meta, "s", null); + Union u = getMetaGrammar(); Tree t = new CharParser((Union)u).parse(new FileInputStream(args[0])).expand1(); t.toJava(out); @@ -51,6 +51,7 @@ class MetaGrammar { } static final Tree meta; + public static Union getMetaGrammar() { return GrammarAST.buildFromAST(meta, "s", null); } static { Tree t = null; diff --git a/src/edu/berkeley/sbp/misc/CommandLine.java b/src/edu/berkeley/sbp/misc/CommandLine.java index b462e6f..9994a1b 100644 --- a/src/edu/berkeley/sbp/misc/CommandLine.java +++ b/src/edu/berkeley/sbp/misc/CommandLine.java @@ -9,22 +9,14 @@ import edu.berkeley.sbp.chr.*; import java.io.*; public class CommandLine { - /* public static void main(String[] argv) throws Throwable { String grammarFile = argv[0]; String targetFile = argv[1]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { System.setErr(new PrintStream(baos)); - Tree res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(grammarFile)).expand1(); - Union meta = Grammar.create(res, "s", - new Grammar.Bindings() { - //public Sequence createSequence(Production p) { - //Sequence ret = super.createSequence(p); - //if (ret != null) return ret; - //return Sequence.create(p.nonTerminal, p.elements, p.drops, false); - //} - }); + Tree res = new CharParser(MetaGrammar.getMetaGrammar()).parse(new FileInputStream(grammarFile)).expand1(); + Union meta = GrammarAST.buildFromAST(res, "s", null); CharInput input = new CharInput(new FileInputStream(targetFile), "", true); Tree ret = new CharParser(meta).parse(input).expand1(); if (ret==null) throw new NullPointerException("CharParser returned null"); @@ -36,5 +28,4 @@ public class CommandLine { System.exit(-1); } } - */ }