- /*
- Tree<String> gram = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
- MetaGrammar g = (MetaGrammar)new MetaGrammar().walk(gram);
- Union meta = g.done();
- //Tree<String> out = new CharParser(meta).parse(new FileInputStream(s[1])).expand1();
- Forest<String> out = new CharParser(meta).parse(new FileInputStream(s[1]));
- GraphViz gv = new GraphViz();
- out.toGraphViz(gv);
- gv.dump(new PrintWriter(new OutputStreamWriter(System.out)));
- */
+
+ Parser metaGrammarParser = new CharParser(MetaGrammar.newInstance());
+ Tree<String> parsedGrammar = metaGrammarParser.parse(new CharInput(new FileInputStream(s[0]))).expand1();
+ Grammar.Bindings gbr = new AnnotationGrammarBindings(Math.class);
+ Union mathGrammar = Grammar.create(parsedGrammar, "Expr", gbr);
+ Parser mathParser = new CharParser(mathGrammar);
+
+ System.out.println("about to parse: \""+s[1]+"\"");
+ Tree tree = mathParser.parse(new CharInput(new StringReader(s[1]))).expand1();
+
+ // below is ugly voodoo which will go away very soon. ignore it.
+ TreeFunctor tf = (TreeFunctor)tree.head();
+ Math.Expr e = (Math.Expr)tf.invoke(tree);
+ // above is ugly voodoo which will go away very soon. ignore it.
+
+ System.out.println("done!");
+ System.out.println(Reflection.show(e));