.NET Math Expression Parser


This is a math expression parser written in C#, which evaluates mathematical expressions such as for example cos(x)-sin(x)+2 with given values.

Example usage:

// Import the assembly that contains the parser
using info.lundin.Math;
// some other imports
using System;
using System.Collections;
public class Test
{
public static void Main( String[] args )
{
// Instantiate the parser
ExpressionParser parser = new ExpressionParser();
// Create a hashtable to hold values
Hashtable h = new Hashtable();
// Add variables and values to hashtable
h.Add( "x", 1.ToString() );
h.Add( "y", 2.ToString() );
// Parse and write the result
double result = parser.Parse( "xcos(y)", h );
Console.WriteLine( Result: {0}, result );
}
}

The parser supports most common mathematical operators and functions such as:

Operators:

+, -, *, /, ^, %

Functions:

sqrt, sin, cos, tan, atan, acos, asin, acotan, exp, ln, 10log, fac, sinh, cosh, tanh, abs, ceil, floor, sfac, round, fpart.

Logical:

!, ==, !=, ||, &&, >, < , >=, <=