This project is read-only.
  • Small library for parsing and evaluating arithmetical expressions defined by strings.
  • Supports expressions with .NET primitive types: Int32, Int64, Single, Double, Decimal.
  • Standard arithmetics operators supported (including "raise to power" operator).
  • Implicit multiplication supported (more mathematical & lightweight syntax).
  • Works on .NET 2.0, .NET CF 2.0/3.5 and Silverlight 2.0 target platforms.
  • Well-documented and very easy to use API.
Performance benefits:
  • Very fast parsing, no need for building any expression trees.
  • No parser generators used, own clearly written parser provided.
  • It's really fast for most common usage scenarios.
  • Expressions is strongly-typed - no boxing/unboxing caused.
  • Ability to validate expression without doing any other work.
  • Choose between interpretation or runtime compilation to MSIL code.
  • Best solutions for all usage scenarios, depending on needed evaluates count:
    • Once - use quick interpretation mode (parse and evaluate by one pass).
    • Many - create Interpret object and use it with different arguments, with no re-parse.
    • Much many - create Evaluator object (using compiler - slow startup, fastest evaluation).
    • Many in some argument range - create highly specialized Tabulator object.
Evaluator<T> and Tabulator<T> objects:
  • Thread-safe - may be used in multi-threaded apps without any concurrency problems.
  • Created objects are garbage-collected and independent from the expression's context.
  • Fastest tabulation possible - compiling method with tabulation cycle with no delegate calls.
Interpret<T> object:
  • Independent from the expression's context, that may be collected by GC when no longer used.
  • No memory allocations per evaluation (excepting when BCL performs the reflection calls).
  • Replacing simple reflection calls with the delegates calls witch is much faster.
Expression optimizer:
  • Constants folding: 2^8 + x/(6+3+x) became 256 + x/(9+x).
  • Functions folding: 2x * sin(pi/6) became 2x * 0.5 (beware of side-effects!).
  • Pow optimization: x^4 became x*x*x*x (much faster to evaluate).
  • Parameterize expressions by using user-defined arguments list.
  • Use constants from user-defined list (like pi, e, inf) into expressions.
  • Import methods from any other .NET type into expression's context.
  • Culture-sensitive parsing (string compare, decimal and arguments separators).
  • There is ability to import built-in constants and functions easily.
  • Optional case-sensitive mode for identifiers.
  • Optional arithmetic overflow checks.
  • ValueRange<T> class for representing ranges of values with handy features.
  • SyntaxException class provides detailed information about syntax errors.
  • String resources may be easily localized (already included: en, ru, pl).
Wiki pages:

Project licensed under the LGPL: as long as you dynamically link (ie: add a reference) to the officially released assemblies, you can use it in commercial and non-commercial applications.

Few words about:

This project was inspired by the FLEE project, but written in different, much easier way.
Sorry for my English, it is not my native language :)

Future plans:
  • CalcNetwork class for representing networks of expressions.
  • Support for user-defined types as generic parameters.
  • Improve expression optimizer's algorithms.

Last edited Feb 6, 2010 at 1:17 PM by Pelmen64, version 23