I'm working on a tool in the context of a java project to evaluate a custom domain specific, rule-like expression like
min-5 avg datalist > Number
with the individual tokens meaning the following:
- min-5 : optional minimum (or maximum, in that case max-5) occurences of the following term
- avg : an optional aggregation function which operates on the following token datalist (can also be sum or anything similar)
- datalist : A list of data (type: integer/ double) which will be available before the evaluation of the entire expression starts, can be reduced to a single value by the preceding aggregation function
- operator: conditional operator < or > or =
- Number: value for the conditional operator
Note(s):
- The optional amount of occurrences and the aggregation can not happen both, that would make no sense.
- There can be multiple of the above expressions, chained with and/or
- These expressions are external input, not pre-defined
The evaluation of this expression should output a boolean
As I am rather new to expression evaluation / parsing I am searching for an elegant way to solve this, possibly with a java framework/tool.
What I've tried so far:
- Parsing by hand which turned out not so nicely
- Trying to use Janino Expression Evaluator, but I don't know how to handle this programmatically
I am searching for a solution to solve this in an elegant way, I am thankful for any suggestions