1 // Copyright 2006 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() {
23 public Sequence createSequence(Production p) {
24 Sequence ret = super.createSequence(p);
25 if (ret != null) return ret;
26 return Sequence.create(p.nonTerminal, p.elements, p.drops, false);
30 CharInput input = new CharInput(new FileInputStream(targetFile), "", true);
31 Tree ret = new CharParser(meta).parse(input).expand1();
32 if (ret==null) throw new NullPointerException("CharParser returned null");
33 System.out.println(ret);
35 } catch (Throwable e) {
37 System.out.println(new String(baos.toByteArray()));