https://github.com/alxnull/calcex
A simple mathematical expression parser and evaluator for .NET.
https://github.com/alxnull/calcex
csharp dotnet evaluator expression-evaluator math-parser mathematics mathml netstandard parser
Last synced: 9 months ago
JSON representation
A simple mathematical expression parser and evaluator for .NET.
- Host: GitHub
- URL: https://github.com/alxnull/calcex
- Owner: alxnull
- License: bsd-3-clause
- Created: 2019-09-25T07:39:44.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-25T14:45:53.000Z (over 6 years ago)
- Last Synced: 2025-04-19T09:03:44.598Z (10 months ago)
- Topics: csharp, dotnet, evaluator, expression-evaluator, math-parser, mathematics, mathml, netstandard, parser
- Language: C#
- Homepage:
- Size: 66.4 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Calcex
[](https://ci.appveyor.com/project/alxnull/calcex)
[](https://ci.appveyor.com/project/alxnull/calcex)
[](https://github.com/alxnull/calcex/blob/master/LICENSE.txt)
[](https://www.nuget.org/packages/calcex.core/)
A simple mathematical expression parser and evaluator for .NET.
This repository contains _calcex.core_, the actual .NET parser library, the _calcex_ .NET Core CLI and a sample Windows GUI.
## Overview
**Calcex.Core** is a basic parser and evaluator library for mathematical expressions built on .NET Core.
Some functionalities are:
- support for many common arithmetic and bitwise operators (*, ^, %, &, ...)
- support for many mathematical functions (sin, ln, log, min, ...)
- user-defined variables and functions
- evaluate to double, decimal or boolean values
- compile expressions into callable delegates
- convert expressions to postfix notation and MathML strings
**Calcex.Console** contains a simple command-line interface that provides easy access to the mathematical evaluators.
**Calcex.Windows** contains _Calcex App_, a basic GUI calculator app for Windows built using WPF.
## How To (Calcex.Core)
### Simple example
```csharp
Parser parser = new Parser();
// Set a custom variable
parser.SetVariable("x", -12);
// Parse
var tree = parser.Parse("2*pi+5-x");
// Evaluate to double
double doubleResult = tree.Evaluate();
// Evaluate to decimal
decimal decimalResult = tree.EvaluateDecimal();
// Compile to delegate
Func func = tree.Compile("x");
```
Fore more, visit the [Calcex wiki](https://github.com/alxnull/calcex/wiki).
## License
Calcex is published under [BSD-3-Clause license](LICENSE.txt).