I have some mathematical expressions as Java Strings (100 % 6)* 7 =
and Sin(45) + log 100 – 3 ^ 5 =
. I want to parse these on operands and operators then solve them.
But I don't want to use Java Regular Expressions. What is the best solution?
I have some mathematical expressions as Java Strings (100 % 6)* 7 =
and Sin(45) + log 100 – 3 ^ 5 =
. I want to parse these on operands and operators then solve them.
But I don't want to use Java Regular Expressions. What is the best solution?
bison+yacc may be what you want, a LALR text parser.
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
public class aaa {
public static void main(String []args){
try {
String xyz = "3*3+3";
String kkk = "(100 % 6)* 7";
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine se = manager.getEngineByName("JavaScript");
Object result1 = se.eval(xyz);
Object result2 = se.eval(kkk);
System.out.println("result1: "+result1);
System.out.println("result2: "+result2);
}
catch (Exception e) {
e.printStackTrace();
}
}
}