/expression-parser

Java Library to parse and evaluates string expressions

Primary LanguageJavaApache License 2.0Apache-2.0

A light-weight library which parses and evaluates the string expressions.

Download

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'
}

Usage Illustration

String s = "<Put Expression String here>";
Expression expression = new Expression(s);
try {
    System.out.println(expression.evaluate());
} catch (ExpressionParserException e) {
    e.printStackTrace();
}

Documentation

Class Expression (com.nagpal.shivam.expressionparser.Expression)

Constructor Detail

Expression

public Expression(String expression)

constructs an Expression object initialized to the content of the specified string.

Parameters:

expression - a string expression.

Method Detail

evaluate

public double evaluate()

Evaluates the expression specified.

Returns:

Returns the result obtained after evaluation of the specified expression.

Throws:

ExpressionParserException (com.nagpal.shivam.expressionparser.ExpressionParserException) - if specified expression is invalid.