12,395,261 members (63,540 online)

225.2K views
402 bookmarked
Posted

# A Calculation Engine for .NET

, 1 Sep 2013 CPOL
A calculation engine that is small, fast, and extensible.
 ```﻿Friend Class Logical ' Methods Public Shared Sub Register(ByVal ce As CalcEngine) ce.RegisterFunction("AND", 1, Integer.MaxValue, New CalcEngineFunction(AddressOf Logical.And)) ce.RegisterFunction("OR", 1, Integer.MaxValue, New CalcEngineFunction(AddressOf Logical.Or)) ce.RegisterFunction("NOT", 1, New CalcEngineFunction(AddressOf Logical.Not)) ce.RegisterFunction("IF", 3, New CalcEngineFunction(AddressOf Logical.If)) ce.RegisterFunction("TRUE", 0, New CalcEngineFunction(AddressOf Logical.True)) ce.RegisterFunction("FALSE", 0, New CalcEngineFunction(AddressOf Logical.False)) End Sub Private Shared Function [And](ByVal p As List(Of Expression)) As Object Dim b As Boolean = True Dim v As Expression For Each v In p b = (b AndAlso CBool(v)) Next Return b End Function Private Shared Function [False](ByVal p As List(Of Expression)) As Object Return False End Function Private Shared Function [If](ByVal p As List(Of Expression)) As Object If p.Item(0) Is Nothing Then Return p.Item(2).Evaluate Else If CBool(p.Item(0)) Then Return p.Item(1).Evaluate Else Return p.Item(2).Evaluate End If End If End Function Private Shared Function [Not](ByVal p As List(Of Expression)) As Object Return Not CBool(p.Item(0)) End Function Private Shared Function [Or](ByVal p As List(Of Expression)) As Object Dim b As Boolean = False Dim v As Expression For Each v In p b = (b OrElse CBool(v)) Next Return b End Function Private Shared Function [True](ByVal p As List(Of Expression)) As Object Return True End Function End Class ```

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.