+ System.out.println(((Tree)walk(res)).toString(0, 0, 120));
+ }
+
+ public static Tree<String> walk(Tree<String> tree) {
+ String head = tree.head();
+ if ("stringify".equals(head)) {
+ String ret = "";
+ for(Tree<String> t : tree.child(0)) ret += t;
+ return new Tree<String>(null, ret);
+ }
+ Tree<String>[] children = new Tree[tree.numChildren()];
+ for(int i=0; i<children.length; i++) children[i] = walk(tree.child(i));
+ return new Tree<String>(null, head, children);