KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djepExamples > PrintExample


1 /* @author rich
2  * Created on 26-Feb-2004
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8
9 package org.lsmp.djepExamples;
10 import org.nfunk.jep.*;
11 import org.lsmp.djep.xjep.*;
12 /**
13  * @author Rich Morris
14  * Created on 26-Feb-2004
15  */

16 public class PrintExample {
17
18     public static void main(String JavaDoc[] args) {
19         XJep j = new XJep();
20         j.addStandardConstants();
21         j.addStandardFunctions();
22         j.addComplex();
23         j.setAllowUndeclared(true);
24         j.setImplicitMul(true);
25         j.setAllowAssignment(true);
26
27         try
28         {
29             // parse expression
30
Node node = j.parse("a*b+c*(d+sin(x))");
31             // print it
32
j.println(node);
33             // convert to string
34
String JavaDoc str = j.toString(node);
35             System.out.println("String is '"+str+"'");
36             j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true);
37             j.println(node);
38             
39             j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false);
40             Node node2=j.parse("1*x^1+0");
41             j.println(node2);
42             Node simp=j.simplify(node2);
43             j.println(simp);
44
45         }
46         catch(ParseException e) { System.out.println("Parse error"); }
47     }
48 }
49
Popular Tags