Nathan has posted 4 posts at DZone. View Full User Profile

Jep 3.2 - Java Expression Parser

02.29.2008
| 12728 views |
  • submit to reddit
Location: 
Edmonton, AB Canada

JEP is a Java library for parsing and evaluating mathematical expressions. With this package you can allow your users to enter an arbitrary formula as a string, and instantly evaluate it. JEP supports user defined variables, constants, and functions. A number of common mathematical functions and constants are included.

As of February, a new release of Jep is available! We made a bunch of improvements to the configurable parser component, making it even more powerful than before. Additionally you can now analyse parsed expressions, parse multiple expressions separated by semi-colons, and much more.

See the Jep web site for more information: http://www.singularsys.com/jep

Changes from Jep 3.1 to 3.2:

General Changes:

  • Added support for expression tree analysis using TreeAnalyser
  • Fixed errors in the documentation of the default configuration
  • Improved the operator table

Changes to the configurable parser:

  • New StandardConfigurableParser class
  • Parse error reporting with line and column numbers
  • Added support for hexadecimal numbers (e.g. 0x1F)
  • Added support for bitwise operators (bitwise or: a | b, bit shifting a << 2) in BitwiseOperatorTable
  • Added support for a?b:c, x+=1, ++x syntax
  • Added support for case-insensitive operators
  • Added support for multiple expressions separated by semicolons
  • Added support for multiple dimensional array access (a[1][1] accesses the first element of a two-dimensional array)
  • Fixed issues with escape characters
  • Fixed power and unary minus precedence to be consistent with the standard parser ("-3^2" should equal -9)
0
Published at DZone with permission of its author, Nathan Funk.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Artur Biesiadowski replied on Sat, 2008/03/01 - 4:41am

For people looking for something similar with bit better licensing terms, I would suggest Janino - I have quite pleasant experience with it. There is no extra math support like in JEP, but bit more on java evaluation part.

http://www.janino.net/

 

Raphael Valyi replied on Sat, 2008/03/01 - 9:37am

Hi

I remember considering using JEP some years ago and actually went for Fractal Aid (I can't really remember why, may be licensing had to be GPL compatible or beacause of the good documentation and very clean code).  I've been very happy working with it, here is the link for anybody wanting to give it a try:

http://fraid.sourceforge.net/

BTW,  I'm very eager to try mixing it with JRuby when I get some spare time.

Hope this helps,

Raphaël Valyi.

Nathan Funk replied on Sat, 2008/03/01 - 11:16am

There are some advantages that Jep has over Janino and FrAid. Here are some reasons why you might prefer Jep:

  • Licensing: Jep is commercially licensed, while Janino is BSD and FrAid is GPL licensed. If you are integrating a component in your software and selling it for commercially, your lawyers will typically be more comfortable with a commercial license.
  • Customizability: Jep includes two parsers to choose from. The "configurable parser" allows run-time configuration which few other expression parsers do. For example you can add and remove operators without having to recompile the library. 
  • Size: Jep is targeted at parsing single expressions and blocks of expressions. If you do not require all the syntax of Java, Janino is overkill. The FrAid JAR file size (488Kb) is over double the size of Jep's (210Kb).
  • Documentation: We value documentation highly unlike many open source projects. Though FrAid's documentation is good, Janino does not appear to have a manual besides JavaDoc.
  • Code Quality: I haven't used Janino or Fractal Aid, nor looked at their code. But users have mentioned multiple times that they enjoy working with Jep because of the quality of the product.

Of course everybody is free to evaluate for their specific use cases. If you have chosen other products after evaluating Jep, we would like to hear about it!

Nathan Funk 

http://www.singularsys.com/jep 

Ivaylo Iliev replied on Wed, 2008/04/30 - 12:37am

Hmm, the last posting needs some correction.

FrAid is 488KB but with:

  • all the graphics (2D & 3D),
  • Runge-Kutta solvers,
  • FFT,
  • MIDI,
  • sound card support (sample+playback),
  • GUI IO (consoles and such),
  • installers
  • etc.

In the form most comparable to JEP it is 217KB - http://fraid.sourceforge.net/begin/fraid_core.jar (and it is still a complete stand alone system, not parser only) I haven't used JEP and am not comparing it with FrAid, just happen to know FrAid...

Like the licensing argument as well ;)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.