Skip to content
Shaun Lawrence edited this page Aug 27, 2019 · 3 revisions

Expressive is a cross-platform expression parsing and evaluation framework. The cross-platform nature is achieved through compiling for .NET Standard so it will run on practically any platform.

Design and Implementation

There are 3 main stages of the parsing/evaluation of an Expression.

  1. Tokenising - this deals with walking through the characters in the expression and matching the items against the known set of Operators, Functions and Values.
  2. Compiling - once the Expression has been tokenised the set of tokens is then used to build a tree of internal IExpression nodes.
  3. Evaluation - each individual IExpression node is then evaluated to determine it's result and eventually the overall result of the top level Expression.

Error handling

The Expression will terminate early in the following situations:

  1. Any part of the tokenising process fails (i.e. unrecognised tokens).
  2. If any of the Functions are supplied with an incorrect number of parameters.

Aggregate operator

Operators can now handle aggregates (i.e. a variable passed in as an array of values will each be enumerated).

var expression = new Expression("[array] + 2");
var result = expression.Evaluate(new Dictionary<string, object> { ["variable"] = new [] { 2, 3, 4, 5});
// result == 16

Lazy Parameter evaluation

Each individual parameter will only be evaluated at the point of being used within its IExpression node. This will prevent parts of an expression being evaluated should the result already be determined (e.g. when the left hand side of an && (logical AND) operator being false).

Clone this wiki locally
You can’t perform that action at this time.