1 // Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp.misc;
5 import edu.berkeley.sbp.*;
6 import edu.berkeley.sbp.misc.*;
7 import edu.berkeley.sbp.meta.*;
8 import edu.berkeley.sbp.chr.*;
11 public class CommandLine {
13 public static void main(String[] argv) throws Throwable {
14 String grammarFile = argv[0];
15 String targetFile = argv[1];
16 ByteArrayOutputStream baos = new ByteArrayOutputStream();
18 System.setErr(new PrintStream(baos));
19 Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(grammarFile)).expand1();
20 Union meta = Grammar.create(res, "s",
21 new Grammar.Bindings() {
22 //public Sequence createSequence(Production p) {
23 //Sequence ret = super.createSequence(p);
24 //if (ret != null) return ret;
25 //return Sequence.create(p.nonTerminal, p.elements, p.drops, false);
28 CharInput input = new CharInput(new FileInputStream(targetFile), "", true);
29 Tree ret = new CharParser(meta).parse(input).expand1();
30 if (ret==null) throw new NullPointerException("CharParser returned null");
31 System.out.println(ret);
33 } catch (Throwable e) {
35 System.out.println(new String(baos.toByteArray()));