fix build issues with CommandLine.java
authorAdam Megacz <megacz@cs.berkeley.edu>
Thu, 21 Jan 2010 18:10:01 +0000 (10:10 -0800)
committerAdam Megacz <adam@megacz.com>
Thu, 21 Jan 2010 18:10:01 +0000 (10:10 -0800)
src/edu/berkeley/sbp/Grammar.java
src/edu/berkeley/sbp/meta/MetaGrammar.java
src/edu/berkeley/sbp/misc/CommandLine.java

index d04ec0a..6185601 100644 (file)
@@ -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<Token> {
+public abstract class Grammar<Token> {
     protected Union rootUnion;
 
-    public HashMap<Sequence, Topology> follow = new HashMap<Sequence, Topology>();
-    public HashSet<Sequence> followEof = new HashSet<Sequence>();
-    public final HashMap<SequenceOrElement,Boolean> possiblyEpsilon = new HashMap<SequenceOrElement,Boolean>();
-    public HashSet<SequenceOrElement> all = new HashSet<SequenceOrElement>();
+    HashMap<Sequence, Topology> follow = new HashMap<Sequence, Topology>();
+    HashSet<Sequence> followEof = new HashSet<Sequence>();
+    final HashMap<SequenceOrElement,Boolean> possiblyEpsilon = new HashMap<SequenceOrElement,Boolean>();
+    HashSet<SequenceOrElement> all = new HashSet<SequenceOrElement>();
 
     abstract Topology<Token> 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<Token> {
 
     // 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<Token> {
         }
     }
 
-    public Topology epsilonFollowSet(Union u) {
+    Topology epsilonFollowSet(Union u) {
         Topology ret = emptyTopology();
         for(Sequence s : u)
             ret = ret.union(epsilonFollowSet(s, new HashSet<Sequence>()));
         return ret;
     }
-    public Topology epsilonFollowSet(Sequence seq, HashSet<Sequence> seen) {
+    Topology epsilonFollowSet(Sequence seq, HashSet<Sequence> 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<Token> {
         return ret;
     }
 
-    public Topology first(SequenceOrElement e, HashSet<Sequence> seen) {
+    Topology first(SequenceOrElement e, HashSet<Sequence> seen) {
         if (e instanceof Atom) return ((Atom)e).getTokenTopology();
         Topology ret = emptyTopology();
         if (e instanceof Union) {
@@ -127,13 +128,13 @@ abstract class Grammar<Token> {
         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<Sequence> eq = new HashSet<Sequence>();
         gatherNulledSubsequences(parent, eq);
         return eq.contains(potentialSubSequence);
@@ -152,7 +153,7 @@ abstract class Grammar<Token> {
 
     // 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<Token> {
         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<Token> {
         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;
index e35b389..79cd3f5 100644 (file)
@@ -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;
index b462e6f..9994a1b 100644 (file)
@@ -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<String> 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<String> 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);
         }
     }
-    */
 }