rename GrammarBuilder -> GrammarAST
authoradam <adam@megacz.com>
Sun, 27 May 2007 20:20:05 +0000 (16:20 -0400)
committeradam <adam@megacz.com>
Sun, 27 May 2007 20:20:05 +0000 (16:20 -0400)
darcs-hash:20070527202005-5007d-2875e8c5b9218d64c2dd1ce7ea2f7994dc0155c6.gz

src/edu/berkeley/sbp/meta/GrammarAST.java [moved from src/edu/berkeley/sbp/meta/GrammarBuilder.java with 97% similarity]
src/edu/berkeley/sbp/misc/RegressionTests.java

similarity index 97%
rename from src/edu/berkeley/sbp/meta/GrammarBuilder.java
rename to src/edu/berkeley/sbp/meta/GrammarAST.java
index ec734f7..63c4392 100644 (file)
@@ -39,7 +39,7 @@ public class GrammarBuilder {
      *  @param gbr a GrammarBindingResolver that resolves grammatical reductions into tree-node-heads
      */
     public static Union buildFromAST(Tree grammarAST, String startingNonterminal, File[] includes) {
      *  @param gbr a GrammarBindingResolver that resolves grammatical reductions into tree-node-heads
      */
     public static Union buildFromAST(Tree grammarAST, String startingNonterminal, File[] includes) {
-        return new GrammarBuilder(includes, "").buildGrammar(grammarAST, startingNonterminal);
+        return new GrammarAST(includes, "").buildGrammar(grammarAST, startingNonterminal);
     }
 
     public static Object illegalTag = ""; // this is the tag that should never appear in the non-dropped output FIXME
     }
 
     public static Object illegalTag = ""; // this is the tag that should never appear in the non-dropped output FIXME
@@ -47,17 +47,16 @@ public class GrammarBuilder {
     private final String prefix;
     private final File[] includes;
 
     private final String prefix;
     private final File[] includes;
 
-    //public GrammarBuilder(String path) { this(path, ""); }
-    public GrammarBuilder(File[] includes, String prefix) {
+    public GrammarAST(File[] includes, String prefix) {
         this.prefix = prefix;
         this.includes = includes;
     }
 
         this.prefix = prefix;
         this.includes = includes;
     }
 
-    public Union buildGrammar(Tree t, String rootNonTerminal) {
-        return ((GrammarBuilder.GrammarNode)walk(t)).build(rootNonTerminal);
-    }
+    // Methods //////////////////////////////////////////////////////////////////////////////
 
 
-    private ElementNode epsilon = new LiteralNode("");
+    private Union buildGrammar(Tree t, String rootNonTerminal) {
+        return ((GrammarAST.GrammarNode)walk(t)).build(rootNonTerminal);
+    }
 
     public Object[] walkChildren(Tree t) {
         Object[] ret = new Object[t.size()];
 
     public Object[] walkChildren(Tree t) {
         Object[] ret = new Object[t.size()];
@@ -152,8 +151,8 @@ public class GrammarBuilder {
             return new NonTerminalNode(tag, seqs, false, null, false);
         }
         if (head.equals("TestCase"))
             return new NonTerminalNode(tag, seqs, false, null, false);
         }
         if (head.equals("TestCase"))
-            return new RegressionTests.TestCase((String)walk(t.child(0)),
-                                                (String)walk(t.child(1)),
+            return new RegressionTests.TestCase(walkString(t.child(0)),
+                                                walkString(t.child(1)),
                                                 (String[])Reflection.coerce(walkChildren(t.child(2)), String[].class),
                                                 (Union)walk(t.child(3)),
                                                 false,
                                                 (String[])Reflection.coerce(walkChildren(t.child(2)), String[].class),
                                                 (Union)walk(t.child(3)),
                                                 false,
@@ -177,8 +176,10 @@ public class GrammarBuilder {
         throw new RuntimeException("unknown head: \"" + head + "\" => " + (head.equals("...")));
     }
     
         throw new RuntimeException("unknown head: \"" + head + "\" => " + (head.equals("...")));
     }
     
-    /** A grammar (a set of nonterminals) */
-    public class GrammarNode extends HashMap<String,NonTerminalNode> {
+    // Nodes //////////////////////////////////////////////////////////////////////////////
+
+    /** Root node of a grammar's AST; a set of named nonterminals */
+    private class GrammarNode extends HashMap<String,NonTerminalNode> {
         public GrammarNode(NonTerminalNode[] nonterminals) {
             for(NonTerminalNode nt : nonterminals) {
                 if (nt==null) continue;
         public GrammarNode(NonTerminalNode[] nonterminals) {
             for(NonTerminalNode nt : nonterminals) {
                 if (nt==null) continue;
index 6fd3dd0..13be93f 100644 (file)
@@ -37,12 +37,12 @@ public class RegressionTests {
 
             System.err.println("parsing " + s[0]);
             Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(s[0])).expand1();
 
             System.err.println("parsing " + s[0]);
             Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(s[0])).expand1();
-            Union meta = GrammarBuilder.buildFromAST(res, "s", includes);
+            Union meta = GrammarAST.buildFromAST(res, "s", includes);
 
             System.err.println("parsing " + s[1]);
             res = new CharParser(meta).parse(new FileInputStream(s[1])).expand1();
 
 
             System.err.println("parsing " + s[1]);
             res = new CharParser(meta).parse(new FileInputStream(s[1])).expand1();
 
-            Union testcasegrammar = GrammarBuilder.buildFromAST(res, "s", includes);
+            Union testcasegrammar = GrammarAST.buildFromAST(res, "s", includes);
             if (testcasegrammar==null) return;
             CharParser parser = new CharParser(testcasegrammar);
 
             if (testcasegrammar==null) return;
             CharParser parser = new CharParser(testcasegrammar);
 
@@ -63,7 +63,7 @@ public class RegressionTests {
             }
             System.err.println("expanding...");
 
             }
             System.err.println("expanding...");
 
-            TestCase[] expanded = (TestCase[])new GrammarBuilder(includes, "").walkChildren(r2.expand1());
+            TestCase[] expanded = (TestCase[])new GrammarAST(includes, "").walkChildren(r2.expand1());
             for(TestCase tc : expanded)
                 tc.execute();
 
             for(TestCase tc : expanded)
                 tc.execute();