_____________________________________________________________________________
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.
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));
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 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 {
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 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);
+ }
+ }
+
}