X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Ftib%2FTibDoc.java;h=f3195eca34374c014331a19c6a6db34e84222f7c;hb=6cbea0bd6ae3e4ce5a175767b3e926b9b902bdc4;hp=538d80874ef04876b00e6b882c62c007b8c6dd5b;hpb=92632cd2b60dc20e157128696edc81e3a07eaec6;p=sbp.git diff --git a/src/edu/berkeley/sbp/tib/TibDoc.java b/src/edu/berkeley/sbp/tib/TibDoc.java index 538d808..f3195ec 100644 --- a/src/edu/berkeley/sbp/tib/TibDoc.java +++ b/src/edu/berkeley/sbp/tib/TibDoc.java @@ -3,38 +3,50 @@ // You may not use this file except in compliance with the License. package edu.berkeley.sbp.tib; -//import org.ibex.util.*; -//import org.ibex.io.*; import edu.berkeley.sbp.*; import edu.berkeley.sbp.misc.*; import edu.berkeley.sbp.util.*; +import edu.berkeley.sbp.chr.*; import java.util.*; import java.io.*; public class TibDoc { - - public static void main(String[] s) throws Exception { - System.out.println("parsing " + s[0]); - Tree res = new CharToken.CharToStringParser(MetaGrammar.make()).parse(new CharToken.Stream(new FileInputStream(s[0]))).expand1(); - MetaGrammar gram = (MetaGrammar)new Tib.Grammar().walk(res); - //System.out.println(gram); - Union mg = gram.done(); - - System.out.println("\nparsing " + s[1]); - Forest f = new CharToken.CharToStringParser(mg).parse(new Tib(new FileInputStream(s[1]))); - - System.out.println(); - System.out.println(f); - System.out.println(); - System.out.println(((Tree)new StringifyWalker().walk(f.expand1())).toPrettyString()); - String st = new HTMLWalker().walk(f.expand1()).toString(); - System.out.println(st); - FileOutputStream fos = new FileOutputStream("out.html"); - PrintWriter p = new PrintWriter(new OutputStreamWriter(fos)); - p.println(st); - p.flush(); - p.close(); + public static void main(String[] s) throws Exception { + try { + System.out.println("parsing " + s[0]); + Tree res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1(); + MetaGrammar gram = (MetaGrammar)new Tib.Grammar().walk(res); + //System.out.println(gram); + Union mg = gram.done(); + + System.out.println("\nparsing " + s[1]); + Forest f = new CharParser(mg).parse(new Tib(new FileInputStream(s[1]))); + + System.out.println(); + System.out.println(f); + System.out.println(); + System.out.println(((Tree)new StringifyWalker().walk(f.expand1())).toPrettyString()); + + String st = new HTMLWalker().walk(f.expand1()).toString(); + System.out.println(st); + FileOutputStream fos = new FileOutputStream("out.html"); + PrintWriter p = new PrintWriter(new OutputStreamWriter(fos)); + p.println(st); + p.flush(); + p.close(); + } catch (Ambiguous a) { + FileOutputStream fos = new FileOutputStream("/Users/megacz/Desktop/out.dot"); + PrintWriter p = new PrintWriter(new OutputStreamWriter(fos)); + GraphViz gv = new GraphViz(); + a.ambiguity.toGraphViz(gv); + gv.dump(p); + p.flush(); + p.close(); + + } catch (Exception e) { + e.printStackTrace(); + } } public static class StringifyWalker extends ReflectiveWalker { @@ -63,6 +75,7 @@ public class TibDoc { public static class HTMLWalker extends ReflectiveWalker { //public void header() { throw new Error(); } public String li(Object o) { return "
  • "+o+"
  • "; } + public String li(Object a, Object o) { return "
  • "+o+"
  • "; } public String ul(String[] li) { return ""; } public String ol(String[] li) { return "
      "+join(li,"")+"
    "; } public String hr() { return "\n
    \n"; }