1 8 9 package org.lsmp.djepExamples; 10 import org.nfunk.jep.*; 11 import org.lsmp.djep.vectorJep.*; 12 15 public class VectorExample { 16 static VectorJep j; 17 18 public static void main(String args[]) { 19 j = new VectorJep(); 20 j.addStandardConstants(); 21 j.addStandardFunctions(); 22 j.addComplex(); 23 j.setAllowUndeclared(true); 24 j.setImplicitMul(true); 25 j.setAllowAssignment(true); 26 27 29 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("[[1,2],[3,4]]*[[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])"); } 46 47 public static void doStuff(String str) { 48 try { 49 Node node = j.parse(str); 50 Object value = j.evaluate(node); 51 System.out.println(str + "\tvalue " + value.toString()); 52 } 53 catch(ParseException e) { System.out.println("Parse error "+e.getMessage()); } 54 catch(Exception e) { System.out.println("evaluation error "+e.getMessage()); e.printStackTrace(); } 55 } 56 } 57 | Popular Tags |