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