checkpoint
authoradam <adam@megacz.com>
Thu, 22 Dec 2005 03:03:36 +0000 (22:03 -0500)
committeradam <adam@megacz.com>
Thu, 22 Dec 2005 03:03:36 +0000 (22:03 -0500)
darcs-hash:20051222030336-5007d-b7e2a867eab13a983b56b934ddefece3c141729c.gz

TODO
src/edu/berkeley/sbp/misc/MetaGrammar.java
src/edu/berkeley/sbp/misc/ReflectiveWalker.java
src/edu/berkeley/sbp/misc/RegressionTests.java
src/edu/berkeley/sbp/tib/Tib.java

diff --git a/TODO b/TODO
index 14e38b5..27e9694 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,16 +1,7 @@
 _____________________________________________________________________________
 Immediately
 
 _____________________________________________________________________________
 Immediately
 
-  - simplify metagrammar => go to top-down rewriting => finalize metagrammar and rdp-op's
-
-  - What is our use model?
-    - Parse, attribute, unify       (ag)
-    - Parse, transform tree, walk   (rdp)
-    - Parse, walk
-    - cascading tree rewrites
-
-      ==> use the middle formalism "for now" and in meta.g; layer others
-          on top of it
+  - finalize metagrammar and rdp-op's
 
   - Lay down the law on the different kinds of Sequence productions
     and how they work.
 
   - Lay down the law on the different kinds of Sequence productions
     and how they work.
index 3501ee6..748bcf3 100644 (file)
@@ -127,19 +127,7 @@ public class MetaGrammar extends StringWalker {
             PreSequence ret = new PreSequence(o3, s);
             ret.drops[o1.length] = o3.length>1;
             return ret;
             PreSequence ret = new PreSequence(o3, s);
             ret.drops[o1.length] = o3.length>1;
             return ret;
-        } else if ("{".equals(head))
-            return nonTerminal("braced"+(anon++),
-                               new PreSequence[][] {
-                                   new PreSequence[] {
-                                       new PreSequence(new Element[] { leftBrace(),
-                                                                       ((PreSequence)walk(tree, 0)).buildUnion(),
-                                                                       rightBrace()
-                                       })
-                                   }
-                               },
-                               false,
-                               false);
-        else if ("[".equals(head) || "[~".equals(head)) {
+        } else if ("[".equals(head) || "[~".equals(head)) {
             boolean positive = "[".equals(head);
             Range[] rr = (Range[])walk(tree, 0);
             Range.Set ret = positive ? new Range.Set() : new Range.Set(new Range(true, true));
             boolean positive = "[".equals(head);
             Range[] rr = (Range[])walk(tree, 0);
             Range.Set ret = positive ? new Range.Set() : new Range.Set(new Range(true, true));
index c22e81c..f22f4b8 100644 (file)
@@ -5,6 +5,7 @@ import java.io.*;
 import java.util.*;
 import java.lang.reflect.*;
 
 import java.util.*;
 import java.lang.reflect.*;
 
+/** use of this class is not recommended; it can handle only S-attributed grammars */
 public class ReflectiveWalker extends StringWalker {
     public ReflectiveWalker()              { this.target = this; }
     public ReflectiveWalker(Object target) { this.target = target; }
 public class ReflectiveWalker extends StringWalker {
     public ReflectiveWalker()              { this.target = this; }
     public ReflectiveWalker(Object target) { this.target = target; }
index 943c611..50a3942 100644 (file)
@@ -8,20 +8,6 @@ import edu.berkeley.sbp.tib.*;
 public class RegressionTests {
 
     public static boolean yes = false;
 public class RegressionTests {
 
     public static boolean yes = false;
-    public static class MyWalker extends ReflectiveWalker {
-        public String top(Object[] o) { return "top("+join(o)+")"; }
-        public String str(String[] s) { String ret = ""; for(String st : s) ret += st; return ret; }
-        public String join(Object[] o) { String ret = ""; for(Object st : o) ret += st; return ret; }
-        public String whilex(Object s, Object y) { return "while("+s+") " + y; }
-        public String seq(Object[] statements) {
-            String ret = "";
-            for(Object s : statements) ret += s + ";\n";
-            return ret;
-        }
-        /*
-        public String bl(String s) { return "{" + s + "}"; }
-        */
-    };
 
     public static void main(String[] s) throws Exception {
         try {
 
     public static void main(String[] s) throws Exception {
         try {
@@ -131,7 +117,7 @@ public class RegressionTests {
                 else if ("tibcase".equals(tree.head()) || "testcase".equals(tree.head())) {
                     String input = string(tree.child(0));
                     String[] output = tree.numChildren()>2 ? ((String[])walk(tree, 1)) : new String[0];
                 else if ("tibcase".equals(tree.head()) || "testcase".equals(tree.head())) {
                     String input = string(tree.child(0));
                     String[] output = tree.numChildren()>2 ? ((String[])walk(tree, 1)) : new String[0];
-                    Union grammar = (Union)walk(tree, tree.numChildren()-1);
+                    Union grammar = (Union)((MetaGrammar)(new Tib.Grammar().walk(tree, tree.numChildren()-1))).done("s");
                     return new TestCase(input, output, grammar, "tibcase".equals(tree.head()));
                 } else if ("ts".equals(tree.head())) return walk(tree, 0);
                 else return super.walk(tree);
                     return new TestCase(input, output, grammar, "tibcase".equals(tree.head()));
                 } else if ("ts".equals(tree.head())) return walk(tree, 0);
                 else return super.walk(tree);
index 7f9b913..200544a 100644 (file)
@@ -285,5 +285,28 @@ public class Tib implements Token.Stream<CharToken> {
         return ret.toString();
     }
 
         return ret.toString();
     }
 
+    // Grammar //////////////////////////////////////////////////////////////////////////////
+
+    public static class Grammar extends MetaGrammar {
+        private int anon = 0;
+        public Object walk(Tree<String> tree) {
+            String head = tree.head();
+            if (tree.numChildren()==0) return super.walk(tree);
+            if ("{".equals(head))
+                return nonTerminal("braced"+(anon++),
+                                   new PreSequence[][] {
+                                       new PreSequence[] {
+                                           new PreSequence(new Element[] { CharToken.leftBrace,
+                                                                           ((PreSequence)walk(tree, 0)).buildUnion(),
+                                                                           CharToken.rightBrace
+                                           })
+                                       }
+                                   },
+                                   false,
+                                   false);
+            return super.walk(tree);
+        }
+    }
+
 }
 
 }