I am trying to design an expression tree builder that can be used to build an expression tree that can be evaluated lazily with provided context (hash map). Required set of operators is AND
/OR
/NOT
, <
,<=
,>
,>=
,=
,!=
, in_range
(inclusive or not). Expression tree must support a short circuiting (not computing more than needed for the final result). Evaluation result is either true or false. Which nodes in my case must be intermediate and which are the leafs? I suppose
AND
/OR
/NOT
are intermediate ones and predicates (<
,<=
,>
,>=
,=
,!=
, in_range
) will be leaf nodes? Or each predicate will be represented as a subtree?
I recently did this for my employer. I haven't talked to them about open-sourcing it yet, though, so I can't show you any code. I can give you some advice, though.
a <= b
, then a
and b
are numbers or strings. You will probably also want math so you can write a <= b+1
, etc. My solution was that:
a
, b
, 1
, etc.)a < b
, for example, is known to produce a Boolean result.IS NULL
and IS NOT NULL
to your language.