1 8 9 package org.lsmp.djepExamples; 10 import org.nfunk.jep.*; 11 12 15 public class AssignmentExample { 16 17 public static void main(String args[]) 18 { 19 JEP j = new JEP(); 21 j.addStandardConstants(); 22 j.addStandardFunctions(); 23 j.addComplex(); 24 j.setAllowUndeclared(true); 25 j.setImplicitMul(true); 26 27 j.setAllowAssignment(true); 29 30 j.parseExpression("x=3"); 32 j.getValueAsObject(); 34 j.parseExpression("y=2"); 36 j.getValueAsObject(); 37 38 j.parseExpression("x^y"); 40 Object val3 = j.getValueAsObject(); 41 System.out.println("Value is "+val3); 42 43 try 44 { 45 Node node1 = j.parse("z=i*pi"); 47 j.evaluate(node1); 48 Node node2 = j.parse("exp(z)"); 49 Object val2 = j.evaluate(node2); 50 System.out.println("Value: "+val2); 51 52 Node node3 = j.parse("z=x^y"); 54 j.setVarValue("x",new Double (2)); 55 j.setVarValue("y",new Double (3)); 56 j.evaluate(node3); 57 System.out.println(j.getVarValue("z")); } 59 catch(ParseException e) { 60 System.out.println("Error with parsing"); 61 } 62 catch(Exception e) { 63 System.out.println("Error with evaluation"); 64 } 65 } 66 } 67 | Popular Tags |