Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gsscoder/exprengine
.NET expression evaluator engine
https://github.com/gsscoder/exprengine
api csharp dot-net dotnet-core evaluator expression library
Last synced: 27 days ago
JSON representation
.NET expression evaluator engine
- Host: GitHub
- URL: https://github.com/gsscoder/exprengine
- Owner: gsscoder
- License: mit
- Created: 2012-12-27T06:27:37.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2020-02-22T19:58:24.000Z (over 4 years ago)
- Last Synced: 2024-09-28T22:40:54.303Z (about 1 month ago)
- Topics: api, csharp, dot-net, dotnet-core, evaluator, expression, library
- Language: C#
- Homepage:
- Size: 3.51 MB
- Stars: 21
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
README
# Expression Engine
This project is a simple mathematical expression parser written in C#. It's the refactoring of a previous project and uses an AST-evaluation algorithm. You can use built-in or bind your functions and variables to global scope.
## Documentation
Documentation is available in the project [Wiki](https://github.com/gsscoder/exprengine/wiki).
## Targets
- .NET Standard 2.0
- .NET Framework 4.0, 4.5, 4.6.1## At a glance:
```csharp
var contex = new Context()
.SetVariable("G", 6.67428D)
.SetVariable("earth_mass", Evaluate.As("5.97219 * pow(10,24)")) // 5.97219E+24 kg
.SetVariable("lunar_mass", Evaluate.As("7.34767309 * pow(10,22)")) // 7.34767309E+22 kg
.SetVariable("perigee_dist", 356700000D) // moon-earth distance at perigee in m
.SetFunction("calc_force", (object[] args) => ((double) args[0] * (double) args[1]) / Math.Pow((double) args[2], 2));
var result = contex.EvaluateAs("G * calc_force(earth_mass, lunar_mass, perigee_dist)"); // 2.3018745174107073E+31
bool isGCorrect = contex.EvaluateAs("G == 6.67428");
```## REPL
```sh
$ dotnet build -c release
...
$ ./artifacts/ExpressionEngine.REPL/Release/netcoreapp3.1/xeval --help
xeval 1.0.0
Copyright © Giacomo Stelluti Scala, 2012-2020
This is free software. You may redistribute copies of it under the terms of
the MIT License .
Usage: xeval [EXPRESSION]
xeval --interactive
xeval -f [FILENAME]
cmdx | xeval-f, --filename Input text file to be evaluated.
-i, --interactive Run in interactive mode.
-q, --quiet Print only the evaluation results.
-v, --version Print version information and exit.
--help Display this help screen.
```