Java expression parser (extensive)
On this page you find the source code for an expression parser written with Java. It is a console program and supports all common mathematical features. Furthermore, you can assign your own variables and functions. The project is written using Eclipse, the most well known Java IDE. The parser works in two steps: first, the expression string is parsed into an object tree. Next, the object tree is evaluated and the results are returned.
To run the program, you can run one of the provided batch files,
or you can enter
java -jar Parser.jar on a command line.
The features of the expression parser are:
- & | << >>
- = <> < > <= >=
- + -
- * / % ||
- Abs, Exp, Sign, Sqrt, Log, Log10
- Sin, Cos, Tan, Asin, Acos, Atan, Atan2
- Avg, Max, Median, Min, Prod, Std, Sum, Var
- You can assign new functions, like f(x,y)=2*x^y+3
- Built-in: Pi, e
- You can assign new variables, like myvar=3.4/2
- Support for scientific notation
- Built-in error handling
You can download the source code and binaries below.
As Java programs can be run on various platforms, you can execute the program on Windows, Linux, or Macintosh. Here is a screenshot taken on Ubuntu.
Jos de Jong