1 import org.nfunk.jep.*; 2 3 6 class CustFunc { 7 8 11 public CustFunc() { 12 13 } 14 15 19 public static void main(String args[]) { 20 21 JEP parser = new JEP(); String expr = "1 + half(2)"; 23 double value; 24 25 System.out.println("Starting CustFunc..."); 26 parser.addStandardFunctions(); 27 parser.addStandardConstants(); 28 parser.addFunction("half", new Half()); 30 parser.parseExpression(expr); if (parser.hasError()) { 32 System.out.println("Error while parsing"); 33 System.out.println(parser.getErrorInfo()); 34 return; 35 } 36 37 value = parser.getValue(); if (parser.hasError()) { 39 System.out.println("Error during evaluation"); 40 System.out.println(parser.getErrorInfo()); 41 return; 42 } 43 44 System.out.println(expr + " = " + value); } 46 } 47 | Popular Tags |