Home
Javaluator is a simple, but powerful, infix expression evaluator for Java.

Evaluating an expression is as simple as the following lines :

String expression = "(2^3-1)*sin(pi/4)/ln(pi^2)";
Double result = new DoubleEvaluator().evaluate(expression);

This library requires Java 6+ and is available for free under Apache License, version 2.0.

Key features:

  • Functions support: including variable number of arguments and functions with no argument.
  • Constants support: for example pi and e when evaluating expressions on doubles.
  • Variables support: Expressions can include variables (example "sin(x)").
  • Highly configurable: This library comes with some built-in functions and operators, it is very easy to reduce the number of them (for example, the trigonometric functions can be removed from the function set if you want to implement a financial calculator).
    It's also easy to define your own bracket pairs ({},[], etc ...) or to add your own operators, functions or constants.
  • Extensible: This library is provided with an evaluator that deals with expression on real numbers, if you need one on complex numbers, or on anything else, you can implement your own.
  • Localization: Function and constant's names can be changed easily
  • Expression syntax check: Basic infix evaluators consider expressions such as "4 3 +" as valid expressions. Javaluator performs a full syntax check while evaluating the expression.
  • Small footprint: This library is distributed as a 26kB jar. It needs no external library in order to run.
If you want to learn more on these features, please have a look at the tutorial.

Limitations:

  • Only unary and binary operators are supported (ternary operators such as condition?value if true:value if false are not).
  • Non-associative operators are not supported.

A demonstration application that requires Java 7+ is available at https://fathzer.github.io/javaluator/javaluator-demo.jar.
Download it then run: java -jar javaluator-demo.jar
Advertising

Back to top