What's a good library for parsing mathematical expressions in java? [closed]

I wrote a simple but capable Math Expression Evaluator a while back, which is free and open-source. It's main advantage is being fast and tiny - both are a good thing with hand-held devices. If it meets your need you are welcome to use it.

Primary Features:

  • Basic math operators, with inferred precedence (^ * × · / ÷ % + -).
  • Explicit precedence with parenthesis.
  • Implicit multiplication of bracketed subexpressions.
  • Correct right-associativity of exponentials (power operator).
  • Direct support for hexadecimal numbers prefixed by 0x.
  • Constants and variables.
  • Extensible operators.
  • Extensible functions.
  • 20 KiB footprint.

Example

MathEval math=new MathEval();

math.setVariable("Top",    5);
math.setVariable("Left",  20);
math.setVariable("Bottom",15);
math.setVariable("Right", 60);

System.out.println("Middle: "+math.evaluate("floor((Right+1-Left)/2)"));

JEval is a good alternative. I abandoned Jep due to it becoming commercial. The only concern is that JEval seems to be a little dormant at the moment (last release in 2008).


Try https://code.google.com/p/expressionoasis/. It is an extensible Expression Evaluation framework and will meet such requirements.