uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
What is uCalc?
Product:
Class:
A showcase of uCalc's unique advantages over traditional tools like Regex and simple evaluators through compelling, real-world examples.
Remarks
🤔 Why uCalc? A Quick Tour
You've heard that uCalc is a parser, but what does that really mean? And why would you choose it over familiar tools like Regular Expressions or built-in language features?
This quick tour will answer that question by showing you the core advantages that make uCalc uniquely powerful.
1. 🚀 The Expression Parser: More Than Just Math
Many tools can evaluate a simple math string. But uCalc's expression engine is a full-featured, dynamic language environment.
The uCalc Advantage: Runtime Customization
You can define new functions and operators at runtime without recompiling your application. This allows you to build custom, domain-specific languages (DSLs) on the fly.
For example, you can teach uCalc a new function in a single line:
// Define a new function directly in the engineuc.DefineFunction("InToCm(inches) = inches * 2.54");// Now you can use it immediatelyConsole.WriteLine(uc.EvalStr("InToCm(10)")); // Output: 25.4This dynamic nature goes far beyond simple evaluators and opens the door to creating powerful, user-configurable applications.
2. 🧠 The Transformer: Smarter Than Regex
This is the most important difference to understand. Regex is character-aware; uCalc's Transformer is token-aware.
What does that mean? It means the Transformer understands the structure of your text. It knows the difference between a variable name, a number, a string literal, and a comment. Regex just sees a stream of characters.
The Classic Regex Problem
Imagine you want to rename the variable rate to annual_rate in this line of code:rate = 0.05; print("Current rate is: " + rate);
A simple Regex find-and-replace for the word "rate" would incorrectly change it everywhere, including inside the string literal, corrupting your output.
The uCalc Advantage: Structural Safety
Because the Transformer tokenizes the text first, it knows that "Current rate is: " is a single, atomic string token. A rule to replace the variable rate will not even look inside the string, preventing the error. The example below demonstrates this perfectly.
3. 🧩 The Big Picture: A Unified Engine
The Expression Parser and the Transformer are not separate tools; they are two parts of a single, integrated engine. You can use the full power of the expression parser directly inside your transformation rules. This enables you to perform calculations, call functions, and use conditional logic during a find-and-replace operation, a capability far beyond standard tools.
Ready to see it in action? The next step will guide you through installing uCalc and running your first project.
Examples
Demonstrates the power of token-awareness by safely renaming a variable while ignoring its name inside a string literal—a common failure point for character-based Regex.
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
// A snippet of code where 'rate' is both a variable and part of a string
var source_code = """
rate = 0.05; // Set default rate
print("Current rate is: " + rate);
""";
Console.WriteLine("Original Code:");
Console.WriteLine(source_code);
Console.WriteLine("");
// Define a rule to rename the VARIABLE 'rate' to 'annual_rate'
t.FromTo("rate", "annual_rate");
t.SkipOver("// {text}");
// Run the transformation. The 'rate' inside the string is untouched.
Console.WriteLine("Transformed Code:");
Console.WriteLine(t.Transform(source_code));
Original Code:
rate = 0.05; // Set default rate
print("Current rate is: " + rate);
Transformed Code:
annual_rate = 0.05; // Set default rate
print("Current rate is: " + annual_rate); using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); // A snippet of code where 'rate' is both a variable and part of a string var source_code = """ rate = 0.05; // Set default rate print("Current rate is: " + rate); """; Console.WriteLine("Original Code:"); Console.WriteLine(source_code); Console.WriteLine(""); // Define a rule to rename the VARIABLE 'rate' to 'annual_rate' t.FromTo("rate", "annual_rate"); t.SkipOver("// {text}"); // Run the transformation. The 'rate' inside the string is untouched. Console.WriteLine("Transformed Code:"); Console.WriteLine(t.Transform(source_code));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
// A snippet of code where 'rate' is both a variable and part of a string
auto source_code = R"(rate = 0.05; // Set default rate
print("Current rate is: " + rate);)";
cout << "Original Code:" << endl;
cout << source_code << endl;
cout << "" << endl;
// Define a rule to rename the VARIABLE 'rate' to 'annual_rate'
t.FromTo("rate", "annual_rate");
t.SkipOver("// {text}");
// Run the transformation. The 'rate' inside the string is untouched.
cout << "Transformed Code:" << endl;
cout << t.Transform(source_code) << endl;
}
Original Code:
rate = 0.05; // Set default rate
print("Current rate is: " + rate);
Transformed Code:
annual_rate = 0.05; // Set default rate
print("Current rate is: " + annual_rate); #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; // A snippet of code where 'rate' is both a variable and part of a string auto source_code = R"(rate = 0.05; // Set default rate print("Current rate is: " + rate);)"; cout << "Original Code:" << endl; cout << source_code << endl; cout << "" << endl; // Define a rule to rename the VARIABLE 'rate' to 'annual_rate' t.FromTo("rate", "annual_rate"); t.SkipOver("// {text}"); // Run the transformation. The 'rate' inside the string is untouched. cout << "Transformed Code:" << endl; cout << t.Transform(source_code) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
'// A snippet of code where 'rate' is both a variable and part of a string
Dim source_code = "rate = 0.05; // Set default rate
print(""Current rate is: "" + rate);"
Console.WriteLine("Original Code:")
Console.WriteLine(source_code)
Console.WriteLine("")
'// Define a rule to rename the VARIABLE 'rate' to 'annual_rate'
t.FromTo("rate", "annual_rate")
t.SkipOver("// {text}")
'// Run the transformation. The 'rate' inside the string is untouched.
Console.WriteLine("Transformed Code:")
Console.WriteLine(t.Transform(source_code))
End Sub
End Module
Original Code:
rate = 0.05; // Set default rate
print("Current rate is: " + rate);
Transformed Code:
annual_rate = 0.05; // Set default rate
print("Current rate is: " + annual_rate); Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() '// A snippet of code where 'rate' is both a variable and part of a string Dim source_code = "rate = 0.05; // Set default rate print(""Current rate is: "" + rate);" Console.WriteLine("Original Code:") Console.WriteLine(source_code) Console.WriteLine("") '// Define a rule to rename the VARIABLE 'rate' to 'annual_rate' t.FromTo("rate", "annual_rate") t.SkipOver("// {text}") '// Run the transformation. The 'rate' inside the string is untouched. Console.WriteLine("Transformed Code:") Console.WriteLine(t.Transform(source_code)) End Sub End Module