1 8 9 package org.lsmp.djepExamples; 10 import org.nfunk.jep.*; 11 import org.lsmp.djep.vectorJep.*; 12 import org.lsmp.djep.xjep.*; 13 16 public class VectorPrint { 17 static XJep j; 18 20 public static void main(String args[]) { 21 j = new XJep(new VectorJep()); 22 23 j.addStandardConstants(); 24 j.addStandardFunctions(); 25 j.addComplex(); 27 j.setAllowUndeclared(true); 28 j.setImplicitMul(true); 29 j.setAllowAssignment(true); 30 31 33 doStuff("3^2"); 34 doStuff("[1,2,3]"); doStuff("[1,2,3].[4,5,6]"); doStuff("[1,2,3]^^[4,5,6]"); doStuff("[1,2,3]+[4,5,6]"); doStuff("[[1,2],[3,4]]"); doStuff("[[1,2],[3,4]]*[1,0]"); doStuff("[1,0]*[[1,2],[3,4]]"); doStuff("x=[1,2,3]"); doStuff("x+x"); doStuff("x . x"); doStuff("x^^x"); doStuff("ele(x,2)"); doStuff("y=[[1,2],[3,4]]"); doStuff("y * y"); doStuff("ele(y,[1,2])"); } 50 51 public static void doStuff(String str) { 52 try { 53 Node node = j.parse(str); 54 Object value = j.evaluate(node); 55 j.print(node); 56 System.out.println("\tvalue " + value.toString()); 57 } 58 catch(ParseException e) { System.out.println("Parse error "+e.getMessage()); } 59 catch(Exception e) { 60 System.out.println("evaluation error "+e.getMessage()); 61 e.printStackTrace(); } 62 } 63 } 64 | Popular Tags |