diff --git a/README.md b/README.md index 47502f3..6e86e67 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,38 @@ During the optimization phase, the abstract syntax tree is optimized for executi In this phase the abstract syntax tree is executed in either interpreted mode or in dynamic compilation mode. ## Examples -Jace.NET can be used in a couple of ways \ No newline at end of file +Jace.NET can be used in a couple of ways: + +To directly execute a given mathematical function using the provided variables: +```csharp +Dictionary variables = new Dictionary(); +variables.Add("var1", 2.5); +variables.Add("var2", 3.4); + +CalculationEngine engine = new CalculationEngine(); +double result = engine.Calculate("var1*var2", variables); +``` + +To build a .NET Func accepting a dictionary as input containing the values for each variable: +```csharp +CalculationEngine engine = new CalculationEngine(); +Func, double> function = engine.Build("var1+2/(3*otherVariable)"); + +Dictionary variables = new Dictionary(); +variables.Add("var1", 2); +variables.Add("otherVariable", 4.2); + +double result = function(2, 4.2); +``` + +To build a typed .NET Func: +```csharp +CalculationEngine engine = new CalculationEngine(); +Func function = (Func)engine.Function("var1+2/(3*otherVariable)") + .Parameter("var1", DataType.Integer) + .Parameter("otherVariable", DataType.FloatingPoint) + .Result(DataType.FloatingPoint) + .Build(); + +double result = function(2, 4.2); +``` \ No newline at end of file