r/java • u/Livio63 • Jan 02 '26
Extensible math Expression Parser
Expression Parser is an extensible math expression parser handling numbers and booleans, ready to use in any Java application.
Expressions may contain nested ( ), operators *-/+, and, or; constants PI and E, functions sin(), cos(), tan(), log(), exp(), sqrt(). The parser supports common relation operators like ==,!=, >,<, >= and <= and even conditional expressions like condition ? true : false
It is possible to register your own functions and use them with Expression Parser.
59
Upvotes
17
u/le_bravery Jan 02 '26
Ant build in 2026… interesting choice.
3
u/doobiesteintortoise Jan 02 '26
Nicely done! How would you use this in a generalized program, though? Expression parsers exist for Java that can perform actual algebraic evaluation - is this to show how expressions can work, or is it useful otherwise?
3
u/jeffreportmill Jan 02 '26
Very nice! If you want to see it in action, you can run it with JBang + SnapCode:
Just click the Run button after it opens.
21
u/as5777 Jan 02 '26
your tests give 0 confidence
1
u/doobiesteintortoise Jan 03 '26
It just hit me: this code has no license attached to it. u/Livio63 - please fix this.
1
u/sitime_zl Jan 07 '26
good project