uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Compiles a string expression into an intermediate, reusable object for high-performance evaluation.
An Expression object representing the compiled, ready-to-evaluate form of the input string.
The Parse method is the first step in uCalc's high-performance, two-stage evaluation model. It takes a string expression and compiles it into a reusable Expression object. This object can then be evaluated repeatedly using methods like Evaluate or EvaluateStr.
The most significant advantage of this two-step process is performance. Parsing an expression—analyzing its syntax and building an execution plan—is computationally more expensive than evaluating it. If you need to calculate the same formula multiple times (e.g., in a loop with changing variable values), using Parse is far more efficient than calling Eval or EvalStr repeatedly.
for (i = 1 to 1000) result = uc.Eval("x*2+y");var p = uc.Parse("x*2+y"); for (i = 1 to 1000) result = p.Evaluate();The expression string passed to Parse can leverage the full power of the uCalc engine:
Double) is used.An Expression object created by Parse holds resources and must be released when no longer needed to prevent memory leaks. You can manage its lifecycle in two ways:
using statement.Expression object on the stack (RAII).### ⚖️ Comparative Analysis* **vs. `Eval()` in Scripting Languages (Python, JS)**: While `eval()` combines parsing and evaluation into one step, uCalc's `Parse` exposes the intermediate compiled object. This gives developers granular control, enabling performance optimizations and introspection (e.g., checking an expression's return type before evaluating it).* **vs. C# Expression Trees**: Building expression trees in C# from strings is complex. `Parse` provides a simple, direct way to achieve a similar result at runtime from dynamic user input.* **vs. `uCalc.Eval()` and `uCalc.EvalStr()`**: These methods are convenient for single-use evaluations. Use `Parse` when you anticipate evaluating the same expression structure more than once.ID: 396
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine("Parsing the expression '100 / 4'...");
using (var parsedExpr = new uCalc.Expression("100 / 4")) {
//var parsedExpr = uc.Parse("100 / 4");
Console.WriteLine("Evaluating the result...");
Console.WriteLine($"Result: {parsedExpr.Evaluate()}");
}
Parsing the expression '100 / 4'...
Evaluating the result...
Result: 25 using uCalcSoftware; var uc = new uCalc(); Console.WriteLine("Parsing the expression '100 / 4'..."); using (var parsedExpr = new uCalc.Expression("100 / 4")) { //var parsedExpr = uc.Parse("100 / 4"); Console.WriteLine("Evaluating the result..."); Console.WriteLine($"Result: {parsedExpr.Evaluate()}"); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << "Parsing the expression '100 / 4'..." << endl;
{
uCalc::Expression parsedExpr("100 / 4");
parsedExpr.Owned(); // Causes parsedExpr to be released when it goes out of scope
//var parsedExpr = uc.Parse("100 / 4");
cout << "Evaluating the result..." << endl;
cout << "Result: " << parsedExpr.Evaluate() << endl;
}
}
Parsing the expression '100 / 4'...
Evaluating the result...
Result: 25 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << "Parsing the expression '100 / 4'..." << endl; { uCalc::Expression parsedExpr("100 / 4"); parsedExpr.Owned(); // Causes parsedExpr to be released when it goes out of scope //var parsedExpr = uc.Parse("100 / 4"); cout << "Evaluating the result..." << endl; cout << "Result: " << parsedExpr.Evaluate() << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine("Parsing the expression '100 / 4'...")
Using parsedExpr As New uCalc.Expression("100 / 4")
'//var parsedExpr = uc.Parse("100 / 4");
Console.WriteLine("Evaluating the result...")
Console.WriteLine($"Result: {parsedExpr.Evaluate()}")
End Using
End Sub
End Module
Parsing the expression '100 / 4'...
Evaluating the result...
Result: 25 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine("Parsing the expression '100 / 4'...") Using parsedExpr As New uCalc.Expression("100 / 4") '//var parsedExpr = uc.Parse("100 / 4"); Console.WriteLine("Evaluating the result...") Console.WriteLine($"Result: {parsedExpr.Evaluate()}") End Using End Sub End Module
ID: 31
using uCalcSoftware;
var uc = new uCalc();
var VariableX = uc.DefineVariable("x");
var Expression = "x^2 * 10"; // Replace this with your expression
Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---");
var ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x++) {
VariableX.Value(x);
Console.WriteLine(ParsedExpr.Evaluate());
}
ParsedExpr.Release();
VariableX.Release();
--- Efficient: Parse() once, then Evaluate() in a loop ---
10
40
90
160
250
360
490
640
810
1000 using uCalcSoftware; var uc = new uCalc(); var VariableX = uc.DefineVariable("x"); var Expression = "x^2 * 10"; // Replace this with your expression Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---"); var ParsedExpr = uc.Parse(Expression); for (double x = 1; x <= 10; x++) { VariableX.Value(x); Console.WriteLine(ParsedExpr.Evaluate()); } ParsedExpr.Release(); VariableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto VariableX = uc.DefineVariable("x");
auto Expression = "x^2 * 10"; // Replace this with your expression
cout << "--- Efficient: Parse() once, then Evaluate() in a loop ---" << endl;
auto ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x++) {
VariableX.Value(x);
cout << ParsedExpr.Evaluate() << endl;
}
ParsedExpr.Release();
VariableX.Release();
}
--- Efficient: Parse() once, then Evaluate() in a loop ---
10
40
90
160
250
360
490
640
810
1000 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto VariableX = uc.DefineVariable("x"); auto Expression = "x^2 * 10"; // Replace this with your expression cout << "--- Efficient: Parse() once, then Evaluate() in a loop ---" << endl; auto ParsedExpr = uc.Parse(Expression); for (double x = 1; x <= 10; x++) { VariableX.Value(x); cout << ParsedExpr.Evaluate() << endl; } ParsedExpr.Release(); VariableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim VariableX = uc.DefineVariable("x")
Dim Expression = "x^2 * 10" '// Replace this with your expression
Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---")
Dim ParsedExpr = uc.Parse(Expression)
For x As Double = 1 To 10
VariableX.Value(x)
Console.WriteLine(ParsedExpr.Evaluate())
Next
ParsedExpr.Release()
VariableX.Release()
End Sub
End Module
--- Efficient: Parse() once, then Evaluate() in a loop ---
10
40
90
160
250
360
490
640
810
1000 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim VariableX = uc.DefineVariable("x") Dim Expression = "x^2 * 10" '// Replace this with your expression Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---") Dim ParsedExpr = uc.Parse(Expression) For x As Double = 1 To 10 VariableX.Value(x) Console.WriteLine(ParsedExpr.Evaluate()) Next ParsedExpr.Release() VariableX.Release() End Sub End Module
ID: 32
using uCalcSoftware;
var uc = new uCalc();
var VariableX = uc.DefineVariable("x");
var ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer
// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
// (such as evaluating a variable that was explicitly defined as integer;
// other arithmetic operators typically evaluate to Double floating point).
for (double x = 1; x <= 10; x++) {
VariableX.Value(x);
Console.WriteLine("x = " + VariableX.ValueStr() + " Result = " + (ParsedExpr.EvaluateInt32()).ToString());
}
ParsedExpr.Release();
VariableX.Release();
x = 1 Result = 0
x = 2 Result = 1
x = 3 Result = 1
x = 4 Result = 2
x = 5 Result = 2
x = 6 Result = 3
x = 7 Result = 3
x = 8 Result = 4
x = 9 Result = 4
x = 10 Result = 5 using uCalcSoftware; var uc = new uCalc(); var VariableX = uc.DefineVariable("x"); var ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer // NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer // (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer // (such as evaluating a variable that was explicitly defined as integer; // other arithmetic operators typically evaluate to Double floating point). for (double x = 1; x <= 10; x++) { VariableX.Value(x); Console.WriteLine("x = " + VariableX.ValueStr() + " Result = " + (ParsedExpr.EvaluateInt32()).ToString()); } ParsedExpr.Release(); VariableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto VariableX = uc.DefineVariable("x");
auto ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer
// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
// (such as evaluating a variable that was explicitly defined as integer;
// other arithmetic operators typically evaluate to Double floating point).
for (double x = 1; x <= 10; x++) {
VariableX.Value(x);
cout << "x = " + VariableX.ValueStr() + " Result = " + to_string(ParsedExpr.EvaluateInt32()) << endl;
}
ParsedExpr.Release();
VariableX.Release();
}
x = 1 Result = 0
x = 2 Result = 1
x = 3 Result = 1
x = 4 Result = 2
x = 5 Result = 2
x = 6 Result = 3
x = 7 Result = 3
x = 8 Result = 4
x = 9 Result = 4
x = 10 Result = 5 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto VariableX = uc.DefineVariable("x"); auto ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer // NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer // (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer // (such as evaluating a variable that was explicitly defined as integer; // other arithmetic operators typically evaluate to Double floating point). for (double x = 1; x <= 10; x++) { VariableX.Value(x); cout << "x = " + VariableX.ValueStr() + " Result = " + to_string(ParsedExpr.EvaluateInt32()) << endl; } ParsedExpr.Release(); VariableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim VariableX = uc.DefineVariable("x")
Dim ParsedExpr = uc.Parse("x / 2", "Integer") '// Causes output of "x / 2" to convert to an integer
'// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
'// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
'// (such as evaluating a variable that was explicitly defined as integer;
'// other arithmetic operators typically evaluate to Double floating point).
For x As Double = 1 To 10
VariableX.Value(x)
Console.WriteLine("x = " + VariableX.ValueStr() + " Result = " + (ParsedExpr.EvaluateInt32()).ToString())
Next
ParsedExpr.Release()
VariableX.Release()
End Sub
End Module
x = 1 Result = 0
x = 2 Result = 1
x = 3 Result = 1
x = 4 Result = 2
x = 5 Result = 2
x = 6 Result = 3
x = 7 Result = 3
x = 8 Result = 4
x = 9 Result = 4
x = 10 Result = 5 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim VariableX = uc.DefineVariable("x") Dim ParsedExpr = uc.Parse("x / 2", "Integer") '// Causes output of "x / 2" to convert to an integer '// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer '// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer '// (such as evaluating a variable that was explicitly defined as integer; '// other arithmetic operators typically evaluate to Double floating point). For x As Double = 1 To 10 VariableX.Value(x) Console.WriteLine("x = " + VariableX.ValueStr() + " Result = " + (ParsedExpr.EvaluateInt32()).ToString()) Next ParsedExpr.Release() VariableX.Release() End Sub End Module
ID: 1460
using uCalcSoftware;
var uc = new uCalc();
var variableX = uc.DefineVariable("x");
var userExpression = "x * 2 + 5";
var Total = 0.0;
var UpperBound = 1000000; // One million
// Parse the expression just once before the loop begins.
var parsedExpr = uc.Parse(userExpression);
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
for (double x = 1; x <= UpperBound; x++) {
variableX.Value(x);
Total = Total + parsedExpr.Evaluate();
}
stopwatch.Stop();
//Uncomment the following line to reveal the actual speed:
//Console.WriteLine($"Elapsed Milliseconds: {stopwatch.ElapsedMilliseconds} ms");
Console.Write("Sum(1, "); Console.Write(UpperBound); Console.Write(", "); Console.Write(userExpression); Console.Write(") = "); Console.Write(Total);
Sum(1, 1000000, x * 2 + 5) = 1000006000000 using uCalcSoftware; var uc = new uCalc(); var variableX = uc.DefineVariable("x"); var userExpression = "x * 2 + 5"; var Total = 0.0; var UpperBound = 1000000; // One million // Parse the expression just once before the loop begins. var parsedExpr = uc.Parse(userExpression); var stopwatch = System.Diagnostics.Stopwatch.StartNew(); for (double x = 1; x <= UpperBound; x++) { variableX.Value(x); Total = Total + parsedExpr.Evaluate(); } stopwatch.Stop(); //Uncomment the following line to reveal the actual speed: //Console.WriteLine($"Elapsed Milliseconds: {stopwatch.ElapsedMilliseconds} ms"); Console.Write("Sum(1, "); Console.Write(UpperBound); Console.Write(", "); Console.Write(userExpression); Console.Write(") = "); Console.Write(Total);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto variableX = uc.DefineVariable("x");
auto userExpression = "x * 2 + 5";
auto Total = 0.0;
auto UpperBound = 1000000; // One million
// Parse the expression just once before the loop begins.
auto parsedExpr = uc.Parse(userExpression);
for (double x = 1; x <= UpperBound; x++) {
variableX.Value(x);
Total = Total + parsedExpr.Evaluate();
}
cout << "Sum(1, " << UpperBound << ", " << userExpression << ") = " << (long long)Total;
}
Sum(1, 1000000, x * 2 + 5) = 1000006000000 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto variableX = uc.DefineVariable("x"); auto userExpression = "x * 2 + 5"; auto Total = 0.0; auto UpperBound = 1000000; // One million // Parse the expression just once before the loop begins. auto parsedExpr = uc.Parse(userExpression); for (double x = 1; x <= UpperBound; x++) { variableX.Value(x); Total = Total + parsedExpr.Evaluate(); } cout << "Sum(1, " << UpperBound << ", " << userExpression << ") = " << (long long)Total; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim variableX = uc.DefineVariable("x")
Dim userExpression = "x * 2 + 5"
Dim Total = 0.0
Dim UpperBound = 1000000 '// One million
'// Parse the expression just once before the loop begins.
Dim parsedExpr = uc.Parse(userExpression)
Dim stopwatch = System.Diagnostics.Stopwatch.StartNew()
For x As Double = 1 To UpperBound
variableX.Value(x)
Total = Total + parsedExpr.Evaluate()
Next
stopwatch.Stop()
'//Uncomment the following line to reveal the actual speed:
'//Console.WriteLine($"Elapsed Milliseconds: {stopwatch.ElapsedMilliseconds} ms");
Console.Write("Sum(1, ")
Console.Write(UpperBound)
Console.Write(", ")
Console.Write(userExpression)
Console.Write(") = ")
Console.Write(Total)
End Sub
End Module
Sum(1, 1000000, x * 2 + 5) = 1000006000000 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim variableX = uc.DefineVariable("x") Dim userExpression = "x * 2 + 5" Dim Total = 0.0 Dim UpperBound = 1000000 '// One million '// Parse the expression just once before the loop begins. Dim parsedExpr = uc.Parse(userExpression) Dim stopwatch = System.Diagnostics.Stopwatch.StartNew() For x As Double = 1 To UpperBound variableX.Value(x) Total = Total + parsedExpr.Evaluate() Next stopwatch.Stop() '//Uncomment the following line to reveal the actual speed: '//Console.WriteLine($"Elapsed Milliseconds: {stopwatch.ElapsedMilliseconds} ms"); Console.Write("Sum(1, ") Console.Write(UpperBound) Console.Write(", ") Console.Write(userExpression) Console.Write(") = ") Console.Write(Total) End Sub End Module