Skip to content

ShivamNagpal/expression-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.