fix javadoc generation
[sbp.git] / src / edu / berkeley / sbp / misc / Demo.java
1 // Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
2
3 package edu.berkeley.sbp.misc;
4
5 import edu.berkeley.sbp.*;
6 import edu.berkeley.sbp.chr.*;
7 import edu.berkeley.sbp.misc.*;
8 import edu.berkeley.sbp.meta.*;
9 import edu.berkeley.sbp.util.*;
10 import java.util.*;
11 import java.io.*;
12
13 public class Demo {
14     /*
15     // our grammar class
16     public static class Math {
17
18         public static @bind.as("(") Expr parenthesis(Expr e) { return e; }
19         public static class Expr implements Reflection.Show { }
20
21         public static @bind.as("Expr") class Numeric extends Expr {
22             public @bind.arg String numeric;
23         }
24
25         public static class BinOp extends Expr {
26             public @bind.arg Expr left;
27             public @bind.arg Expr right;
28         }
29
30         public static @bind.as("*") class Multiply extends BinOp { }
31         public static @bind.as("/") class Divide   extends BinOp { }
32         public static @bind.as("+") class Add      extends BinOp { }
33         public static @bind.as("-") class Subtract extends BinOp { }
34     }
35
36
37     // invoke "java -jar edu.berkeley.sbp.jar edu.berkeley.sbp.misc.Demo tests/demo.g <expr>"
38     public static void main(String[] s) throws Exception {
39
40         Parser metaGrammarParser   = new CharParser(MetaGrammar.newInstance());
41         Tree<String> parsedGrammar = metaGrammarParser.parse(new CharInput(new FileInputStream(s[0]))).expand1();
42         Grammar.Bindings gbr       = new AnnotationGrammarBindings(Math.class);
43         Union   mathGrammar        = Grammar.create(parsedGrammar, "Expr", gbr);
44         Parser  mathParser         = new CharParser(mathGrammar);
45
46         System.out.println("about to parse: \""+s[1]+"\"");
47         Tree tree = mathParser.parse(new CharInput(new StringReader(s[1]))).expand1();
48
49         // below is ugly voodoo which will go away very soon.  ignore it.
50         TreeFunctor tf = (TreeFunctor)tree.head();
51         Math.Expr e = (Math.Expr)tf.invoke(tree);
52         // above is ugly voodoo which will go away very soon.  ignore it.
53
54         System.out.println("done!");
55         System.out.println(Reflection.show(e));
56     }
57     */
58 }