A light-weight library which parses and evaluates the string expressions.
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.ShivamNagpal:ExpressionParser:2.3'
}
String s = "<Put Expression String here>";
Expression expression = new Expression(s);
try {
System.out.println(expression.evaluate());
} catch (ExpressionParserException e) {
e.printStackTrace();
}
Class Expression (com.nagpal.shivam.expressionparser.Expression)
public Expression(String expression)
constructs an Expression object initialized to the content of the specified string.
expression - a string expression.
public double evaluate()
Evaluates the expression specified.
Returns the result obtained after evaluation of the specified expression.
ExpressionParserException (com.nagpal.shivam.expressionparser.ExpressionParserException) - if specified expression is invalid.