085f26eb80a7ebf5594b9478d30a8bce6f8f0847
[sbp.git] / src / edu / berkeley / sbp / misc / Java15.java
1 // Copyright 2006 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package edu.berkeley.sbp.misc;
6 import edu.berkeley.sbp.*;
7 import edu.berkeley.sbp.misc.*;
8 import edu.berkeley.sbp.meta.*;
9 import edu.berkeley.sbp.util.*;
10 import edu.berkeley.sbp.chr.*;
11 import edu.berkeley.sbp.bind.*;
12 import java.util.*;
13 import java.io.*;
14
15 public class Java15 {
16
17     public static void main(String[] s) throws Exception {
18
19         try {
20             Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(s[0])).expand1();
21             
22             //AnnotationGrammarBindings resolver = new AnnotationGrammarBindings(Java15.class);
23             Grammar.Bindings resolver = new Grammar.Bindings();
24             Union javaGrammar = Grammar.create(res, "s", resolver);
25
26             System.err.println("parsing " + s[1]);
27             Tree t = new CharParser(javaGrammar).parse(new FileInputStream(s[1])).expand1();
28
29             System.out.println("tree:\n" + t.toPrettyString());
30
31         } catch (Ambiguous a) {
32             FileOutputStream fos = new FileOutputStream("/Users/megacz/Desktop/out.dot");
33             PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));
34             GraphViz gv = new GraphViz();
35             a.getAmbiguity().toGraphViz(gv);
36             gv.dump(p);
37             p.flush();
38             p.close();
39             a.printStackTrace();
40             
41         } catch (Exception e) {
42             e.printStackTrace();
43         }
44
45     }
46
47 }