uCalc SDK Interactive Examples
Demonstrates enabling multiple floating-point error types and observing the results.
ID: 349
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine("--- Default Behavior (No Errors Raised) ---");
Console.WriteLine($"1/0: {uc.EvalStr("1/0")}");
Console.WriteLine($"0/0: {uc.EvalStr("0/0")}");
Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}");
Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}");
Console.WriteLine("");
Console.WriteLine("--- Enable Invalid Operation & Underflow ---");
// You can pass multiple enum members to enable them simultaneously
uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow);
Console.WriteLine($"Current flags: {uc.Error.FloatingPointErrorsToTrap}"); // Should be 16 (Invalid) + 2 (Underflow) = 18
Console.WriteLine($"1/0: {uc.EvalStr("1/0")}"); // Not enabled, returns inf
Console.WriteLine($"0/0: {uc.EvalStr("0/0")}"); // Enabled, raises error
Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}"); // Not enabled, returns inf
Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}"); // Enabled, raises error
--- Default Behavior (No Errors Raised) ---
1/0: inf
0/0: nan
Overflow (5*10^308): inf
Underflow (10^-308/10000): 0
--- Enable Invalid Operation & Underflow ---
Current flags: 18
1/0: inf
0/0: Invalid operation
Overflow (5*10^308): inf
Underflow (10^-308/10000): Floating point underflow using uCalcSoftware; var uc = new uCalc(); Console.WriteLine("--- Default Behavior (No Errors Raised) ---"); Console.WriteLine($"1/0: {uc.EvalStr("1/0")}"); Console.WriteLine($"0/0: {uc.EvalStr("0/0")}"); Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}"); Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}"); Console.WriteLine(""); Console.WriteLine("--- Enable Invalid Operation & Underflow ---"); // You can pass multiple enum members to enable them simultaneously uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow); Console.WriteLine($"Current flags: {uc.Error.FloatingPointErrorsToTrap}"); // Should be 16 (Invalid) + 2 (Underflow) = 18 Console.WriteLine($"1/0: {uc.EvalStr("1/0")}"); // Not enabled, returns inf Console.WriteLine($"0/0: {uc.EvalStr("0/0")}"); // Enabled, raises error Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}"); // Not enabled, returns inf Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}"); // Enabled, raises error
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << "--- Default Behavior (No Errors Raised) ---" << endl;
cout << "1/0: " << uc.EvalStr("1/0") << endl;
cout << "0/0: " << uc.EvalStr("0/0") << endl;
cout << "Overflow (5*10^308): " << uc.EvalStr("5*10^308") << endl;
cout << "Underflow (10^-308/10000): " << uc.EvalStr("10^-308/10000") << endl;
cout << "" << endl;
cout << "--- Enable Invalid Operation & Underflow ---" << endl;
// You can pass multiple enum members to enable them simultaneously
uc.Error().SetFloatingPointErrorsToTrap(ErrorCode::FloatInvalid, ErrorCode::FloatUnderflow);
cout << "Current flags: " << uc.Error().FloatingPointErrorsToTrap() << endl; // Should be 16 (Invalid) + 2 (Underflow) = 18
cout << "1/0: " << uc.EvalStr("1/0") << endl; // Not enabled, returns inf
cout << "0/0: " << uc.EvalStr("0/0") << endl; // Enabled, raises error
cout << "Overflow (5*10^308): " << uc.EvalStr("5*10^308") << endl; // Not enabled, returns inf
cout << "Underflow (10^-308/10000): " << uc.EvalStr("10^-308/10000") << endl; // Enabled, raises error
}
--- Default Behavior (No Errors Raised) ---
1/0: inf
0/0: nan
Overflow (5*10^308): inf
Underflow (10^-308/10000): 0
--- Enable Invalid Operation & Underflow ---
Current flags: 18
1/0: inf
0/0: Invalid operation
Overflow (5*10^308): inf
Underflow (10^-308/10000): Floating point underflow #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << "--- Default Behavior (No Errors Raised) ---" << endl; cout << "1/0: " << uc.EvalStr("1/0") << endl; cout << "0/0: " << uc.EvalStr("0/0") << endl; cout << "Overflow (5*10^308): " << uc.EvalStr("5*10^308") << endl; cout << "Underflow (10^-308/10000): " << uc.EvalStr("10^-308/10000") << endl; cout << "" << endl; cout << "--- Enable Invalid Operation & Underflow ---" << endl; // You can pass multiple enum members to enable them simultaneously uc.Error().SetFloatingPointErrorsToTrap(ErrorCode::FloatInvalid, ErrorCode::FloatUnderflow); cout << "Current flags: " << uc.Error().FloatingPointErrorsToTrap() << endl; // Should be 16 (Invalid) + 2 (Underflow) = 18 cout << "1/0: " << uc.EvalStr("1/0") << endl; // Not enabled, returns inf cout << "0/0: " << uc.EvalStr("0/0") << endl; // Enabled, raises error cout << "Overflow (5*10^308): " << uc.EvalStr("5*10^308") << endl; // Not enabled, returns inf cout << "Underflow (10^-308/10000): " << uc.EvalStr("10^-308/10000") << endl; // Enabled, raises error }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine("--- Default Behavior (No Errors Raised) ---")
Console.WriteLine($"1/0: {uc.EvalStr("1/0")}")
Console.WriteLine($"0/0: {uc.EvalStr("0/0")}")
Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}")
Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}")
Console.WriteLine("")
Console.WriteLine("--- Enable Invalid Operation & Underflow ---")
'// You can pass multiple enum members to enable them simultaneously
uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow)
Console.WriteLine($"Current flags: {uc.Error.FloatingPointErrorsToTrap}") '// Should be 16 (Invalid) + 2 (Underflow) = 18
Console.WriteLine($"1/0: {uc.EvalStr("1/0")}") '// Not enabled, returns inf
Console.WriteLine($"0/0: {uc.EvalStr("0/0")}") '// Enabled, raises error
Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}") '// Not enabled, returns inf
Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}") '// Enabled, raises error
End Sub
End Module
--- Default Behavior (No Errors Raised) ---
1/0: inf
0/0: nan
Overflow (5*10^308): inf
Underflow (10^-308/10000): 0
--- Enable Invalid Operation & Underflow ---
Current flags: 18
1/0: inf
0/0: Invalid operation
Overflow (5*10^308): inf
Underflow (10^-308/10000): Floating point underflow Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine("--- Default Behavior (No Errors Raised) ---") Console.WriteLine($"1/0: {uc.EvalStr("1/0")}") Console.WriteLine($"0/0: {uc.EvalStr("0/0")}") Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}") Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}") Console.WriteLine("") Console.WriteLine("--- Enable Invalid Operation & Underflow ---") '// You can pass multiple enum members to enable them simultaneously uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow) Console.WriteLine($"Current flags: {uc.Error.FloatingPointErrorsToTrap}") '// Should be 16 (Invalid) + 2 (Underflow) = 18 Console.WriteLine($"1/0: {uc.EvalStr("1/0")}") '// Not enabled, returns inf Console.WriteLine($"0/0: {uc.EvalStr("0/0")}") '// Enabled, raises error Console.WriteLine($"Overflow (5*10^308): {uc.EvalStr("5*10^308")}") '// Not enabled, returns inf Console.WriteLine($"Underflow (10^-308/10000): {uc.EvalStr("10^-308/10000")}") '// Enabled, raises error End Sub End Module
Demonstrates getting a token's initial type and then changing it using the setter overload.
ID: 677
using uCalcSoftware;
var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
var myToken = t.Tokens.Add("###", TokenType.Generic);
Console.Write("Initial Type: ");
Console.WriteLine(myToken.TypeOfToken == TokenType.Generic);
// Change the type
myToken.TypeOfToken = TokenType.Reducible;
Console.Write("New Type is Reducible: ");
Console.WriteLine(myToken.TypeOfToken == TokenType.Reducible);
}
Initial Type: True
New Type is Reducible: True using uCalcSoftware; var uc = new uCalc(); using (var t = new uCalc.Transformer()) { var myToken = t.Tokens.Add("###", TokenType.Generic); Console.Write("Initial Type: "); Console.WriteLine(myToken.TypeOfToken == TokenType.Generic); // Change the type myToken.TypeOfToken = TokenType.Reducible; Console.Write("New Type is Reducible: "); Console.WriteLine(myToken.TypeOfToken == TokenType.Reducible); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
{
uCalc::Transformer t;
t.Owned(); // Causes t to be released when it goes out of scope
auto myToken = t.Tokens().Add("###", TokenType::Generic);
cout << "Initial Type: ";
cout << tf(myToken.TypeOfToken() == TokenType::Generic) << endl;
// Change the type
myToken.TypeOfToken(TokenType::Reducible);
cout << "New Type is Reducible: ";
cout << tf(myToken.TypeOfToken() == TokenType::Reducible) << endl;
}
}
Initial Type: True
New Type is Reducible: True #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; { uCalc::Transformer t; t.Owned(); // Causes t to be released when it goes out of scope auto myToken = t.Tokens().Add("###", TokenType::Generic); cout << "Initial Type: "; cout << tf(myToken.TypeOfToken() == TokenType::Generic) << endl; // Change the type myToken.TypeOfToken(TokenType::Reducible); cout << "New Type is Reducible: "; cout << tf(myToken.TypeOfToken() == TokenType::Reducible) << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using t As New uCalc.Transformer()
Dim myToken = t.Tokens.Add("###", TokenType.Generic)
Console.Write("Initial Type: ")
Console.WriteLine(myToken.TypeOfToken = TokenType.Generic)
'// Change the type
myToken.TypeOfToken = TokenType.Reducible
Console.Write("New Type is Reducible: ")
Console.WriteLine(myToken.TypeOfToken = TokenType.Reducible)
End Using
End Sub
End Module
Initial Type: True
New Type is Reducible: True Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using t As New uCalc.Transformer() Dim myToken = t.Tokens.Add("###", TokenType.Generic) Console.Write("Initial Type: ") Console.WriteLine(myToken.TypeOfToken = TokenType.Generic) '// Change the type myToken.TypeOfToken = TokenType.Reducible Console.Write("New Type is Reducible: ") Console.WriteLine(myToken.TypeOfToken = TokenType.Reducible) End Using End Sub End Module
Demonstrates getting the last error message after a failed operation.
ID: 322
using uCalcSoftware;
var uc = new uCalc();
// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error.
uc.EvalStr("5 * (10 +");
// Check the error message from the last operation.
Console.WriteLine($"Last error message: {uc.Error.Message}");
Last error message: Bracket delimiter error using uCalcSoftware; var uc = new uCalc(); // Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error. uc.EvalStr("5 * (10 +"); // Check the error message from the last operation. Console.WriteLine($"Last error message: {uc.Error.Message}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error.
uc.EvalStr("5 * (10 +");
// Check the error message from the last operation.
cout << "Last error message: " << uc.Error().Message() << endl;
}
Last error message: Bracket delimiter error #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error. uc.EvalStr("5 * (10 +"); // Check the error message from the last operation. cout << "Last error message: " << uc.Error().Message() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error.
uc.EvalStr("5 * (10 +")
'// Check the error message from the last operation.
Console.WriteLine($"Last error message: {uc.Error.Message}")
End Sub
End Module
Last error message: Bracket delimiter error Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error. uc.EvalStr("5 * (10 +") '// Check the error message from the last operation. Console.WriteLine($"Last error message: {uc.Error.Message}") End Sub End Module
Demonstrates how `GlobalMaximum` invalidates a search if a rule matches too many times.
ID: 879
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
var rule = t.FromTo("ERROR", "[ERR]");
rule.GlobalMaximum = 2;
// This input has 3 matches, which exceeds the maximum of 2.
string input1 = "ERROR 1, ERROR 2, ERROR 3";
t.Transform(input1);
Console.WriteLine($"Input 1 Match Count: {t.Matches.Count()}"); // Expect 0
// This input has 2 matches, which is within the limit.
string input2 = "ERROR 1, ERROR 2";
t.Transform(input2);
Console.WriteLine($"Input 2 Match Count: {t.Matches.Count()}"); // Expect 2
Console.WriteLine(t);
Input 1 Match Count: 0
Input 2 Match Count: 2
[ERR] 1, [ERR] 2 using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); var rule = t.FromTo("ERROR", "[ERR]"); rule.GlobalMaximum = 2; // This input has 3 matches, which exceeds the maximum of 2. string input1 = "ERROR 1, ERROR 2, ERROR 3"; t.Transform(input1); Console.WriteLine($"Input 1 Match Count: {t.Matches.Count()}"); // Expect 0 // This input has 2 matches, which is within the limit. string input2 = "ERROR 1, ERROR 2"; t.Transform(input2); Console.WriteLine($"Input 2 Match Count: {t.Matches.Count()}"); // Expect 2 Console.WriteLine(t);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
auto rule = t.FromTo("ERROR", "[ERR]");
rule.GlobalMaximum(2);
// This input has 3 matches, which exceeds the maximum of 2.
string input1 = "ERROR 1, ERROR 2, ERROR 3";
t.Transform(input1);
cout << "Input 1 Match Count: " << t.Matches().Count() << endl; // Expect 0
// This input has 2 matches, which is within the limit.
string input2 = "ERROR 1, ERROR 2";
t.Transform(input2);
cout << "Input 2 Match Count: " << t.Matches().Count() << endl; // Expect 2
cout << t << endl;
}
Input 1 Match Count: 0
Input 2 Match Count: 2
[ERR] 1, [ERR] 2 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; auto rule = t.FromTo("ERROR", "[ERR]"); rule.GlobalMaximum(2); // This input has 3 matches, which exceeds the maximum of 2. string input1 = "ERROR 1, ERROR 2, ERROR 3"; t.Transform(input1); cout << "Input 1 Match Count: " << t.Matches().Count() << endl; // Expect 0 // This input has 2 matches, which is within the limit. string input2 = "ERROR 1, ERROR 2"; t.Transform(input2); cout << "Input 2 Match Count: " << t.Matches().Count() << endl; // Expect 2 cout << t << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim rule = t.FromTo("ERROR", "[ERR]")
rule.GlobalMaximum = 2
'// This input has 3 matches, which exceeds the maximum of 2.
Dim input1 As String = "ERROR 1, ERROR 2, ERROR 3"
t.Transform(input1)
Console.WriteLine($"Input 1 Match Count: {t.Matches.Count()}") '// Expect 0
'// This input has 2 matches, which is within the limit.
Dim input2 As String = "ERROR 1, ERROR 2"
t.Transform(input2)
Console.WriteLine($"Input 2 Match Count: {t.Matches.Count()}") '// Expect 2
Console.WriteLine(t)
End Sub
End Module
Input 1 Match Count: 0
Input 2 Match Count: 2
[ERR] 1, [ERR] 2 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() Dim rule = t.FromTo("ERROR", "[ERR]") rule.GlobalMaximum = 2 '// This input has 3 matches, which exceeds the maximum of 2. Dim input1 As String = "ERROR 1, ERROR 2, ERROR 3" t.Transform(input1) Console.WriteLine($"Input 1 Match Count: {t.Matches.Count()}") '// Expect 0 '// This input has 2 matches, which is within the limit. Dim input2 As String = "ERROR 1, ERROR 2" t.Transform(input2) Console.WriteLine($"Input 2 Match Count: {t.Matches.Count()}") '// Expect 2 Console.WriteLine(t) End Sub End Module
Demonstrates how a Transformer is created from a uCalc instance and used to apply Rules to text.
ID: 1335
using uCalcSoftware;
var uc = new uCalc();
// 1. The uCalc instance (uc) is the factory
// 2. Create a Transformer from the instance
using (var t = new uCalc.Transformer(uc)) {
// 3. Define a Rule on the transformer
t.FromTo("apple", "FRUIT");
// 4. Process text and get the result
Console.WriteLine(t.Transform("An apple a day."));
};
An FRUIT a day. using uCalcSoftware; var uc = new uCalc(); // 1. The uCalc instance (uc) is the factory // 2. Create a Transformer from the instance using (var t = new uCalc.Transformer(uc)) { // 3. Define a Rule on the transformer t.FromTo("apple", "FRUIT"); // 4. Process text and get the result Console.WriteLine(t.Transform("An apple a day.")); };
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// 1. The uCalc instance (uc) is the factory
// 2. Create a Transformer from the instance
{
uCalc::Transformer t(uc);
t.Owned(); // Causes t to be released when it goes out of scope
// 3. Define a Rule on the transformer
t.FromTo("apple", "FRUIT");
// 4. Process text and get the result
cout << t.Transform("An apple a day.") << endl;
};
}
An FRUIT a day. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // 1. The uCalc instance (uc) is the factory // 2. Create a Transformer from the instance { uCalc::Transformer t(uc); t.Owned(); // Causes t to be released when it goes out of scope // 3. Define a Rule on the transformer t.FromTo("apple", "FRUIT"); // 4. Process text and get the result cout << t.Transform("An apple a day.") << endl; }; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// 1. The uCalc instance (uc) is the factory
'// 2. Create a Transformer from the instance
Using t As New uCalc.Transformer(uc)
'// 3. Define a Rule on the transformer
t.FromTo("apple", "FRUIT")
'// 4. Process text and get the result
Console.WriteLine(t.Transform("An apple a day."))
End Using
End Sub
End Module
An FRUIT a day. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// 1. The uCalc instance (uc) is the factory '// 2. Create a Transformer from the instance Using t As New uCalc.Transformer(uc) '// 3. Define a Rule on the transformer t.FromTo("apple", "FRUIT") '// 4. Process text and get the result Console.WriteLine(t.Transform("An apple a day.")) End Using End Sub End Module
Demonstrates how uCalc's token-aware Transformer safely renames a variable without corrupting a string literal, a common failure point for Regex.
ID: 1173
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
// A rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value");
// The input string where 'x' appears both as a variable and inside a string
var code = """
if (x > 10) print("Max value is x");
""";
// The transformation correctly ignores the 'x' inside the quoted string
Console.WriteLine(t.Transform(code));
if (value > 10) print("Max value is x"); using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); // A rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value"); // The input string where 'x' appears both as a variable and inside a string var code = """ if (x > 10) print("Max value is x"); """; // The transformation correctly ignores the 'x' inside the quoted string Console.WriteLine(t.Transform(code));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
// A rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value");
// The input string where 'x' appears both as a variable and inside a string
auto code = R"(if (x > 10) print("Max value is x");)";
// The transformation correctly ignores the 'x' inside the quoted string
cout << t.Transform(code) << endl;
}
if (value > 10) print("Max value is x"); #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; // A rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value"); // The input string where 'x' appears both as a variable and inside a string auto code = R"(if (x > 10) print("Max value is x");)"; // The transformation correctly ignores the 'x' inside the quoted string cout << t.Transform(code) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
'// A rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value")
'// The input string where 'x' appears both as a variable and inside a string
Dim code = "if (x > 10) print(""Max value is x"");"
'// The transformation correctly ignores the 'x' inside the quoted string
Console.WriteLine(t.Transform(code))
End Sub
End Module
if (value > 10) print("Max value is x"); Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() '// A rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value") '// The input string where 'x' appears both as a variable and inside a string Dim code = "if (x > 10) print(""Max value is x"");" '// The transformation correctly ignores the 'x' inside the quoted string Console.WriteLine(t.Transform(code)) End Sub End Module
Demonstrates implicit parsing on assignment and implicit evaluation when writing to the console.
ID: 803
See: Shortcut notations
using uCalcSoftware;
var uc = new uCalc();
var expr = new uCalc.Expression("3+4");
Console.WriteLine($"Initial: {expr}"); // Implicit EvaluateStr
expr = "20+100"; // Implicit Parse
Console.WriteLine($"Reassigned: {expr}"); // Implicit EvaluateStr
Initial: 7
Reassigned: 120 using uCalcSoftware; var uc = new uCalc(); var expr = new uCalc.Expression("3+4"); Console.WriteLine($"Initial: {expr}"); // Implicit EvaluateStr expr = "20+100"; // Implicit Parse Console.WriteLine($"Reassigned: {expr}"); // Implicit EvaluateStr
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Expression expr("3+4");
cout << "Initial: " << expr << endl; // Implicit EvaluateStr
expr = "20+100"; // Implicit Parse
cout << "Reassigned: " << expr << endl; // Implicit EvaluateStr
}
Initial: 7
Reassigned: 120 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Expression expr("3+4"); cout << "Initial: " << expr << endl; // Implicit EvaluateStr expr = "20+100"; // Implicit Parse cout << "Reassigned: " << expr << endl; // Implicit EvaluateStr }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim expr As New uCalc.Expression("3+4")
Console.WriteLine($"Initial: {expr}") '// Implicit EvaluateStr
expr = "20+100" '// Implicit Parse
Console.WriteLine($"Reassigned: {expr}") '// Implicit EvaluateStr
End Sub
End Module
Initial: 7
Reassigned: 120 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim expr As New uCalc.Expression("3+4") Console.WriteLine($"Initial: {expr}") '// Implicit EvaluateStr expr = "20+100" '// Implicit Parse Console.WriteLine($"Reassigned: {expr}") '// Implicit EvaluateStr End Sub End Module
Demonstrates interoperability between `Transformer` and `String` objects, and chaining methods to create nested views.
ID: 1159
See: (Constructor)
using uCalcSoftware;
var uc = new uCalc();
// Create a transformer and perform a transformation
var t = uc.NewTransformer();
t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;";
t.FromTo("1", "100");
t.Transform();
// --- Interoperability and Chaining ---
var Pattern = "if ({cond})";
// 1. Create a uCalc.String from a Transformer.
// 2. Chain .After() to get a "live view" of the text after the pattern.
var s = new uCalc.String(t);
var after_first_if = s.After(Pattern);
Console.WriteLine(after_first_if.Text);
// 3. Chain another .After() on the child string.
var after_second_if = after_first_if.After(Pattern);
Console.WriteLine(after_second_if.Text);
// --- String to Transformer Conversion ---
// 4. Create a uCalc.String and assign it text.
var s2 = new uCalc.String();
s2 = "This is a test";
// 5. Create a Transformer from the uCalc.String to use transformer-specific methods.
var t2 = new uCalc.Transformer(s2);
Console.WriteLine(t2.Text);
y = x * 2; else if(x == 5) y = x - 100;
y = x - 100;
This is a test using uCalcSoftware; var uc = new uCalc(); // Create a transformer and perform a transformation var t = uc.NewTransformer(); t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;"; t.FromTo("1", "100"); t.Transform(); // --- Interoperability and Chaining --- var Pattern = "if ({cond})"; // 1. Create a uCalc.String from a Transformer. // 2. Chain .After() to get a "live view" of the text after the pattern. var s = new uCalc.String(t); var after_first_if = s.After(Pattern); Console.WriteLine(after_first_if.Text); // 3. Chain another .After() on the child string. var after_second_if = after_first_if.After(Pattern); Console.WriteLine(after_second_if.Text); // --- String to Transformer Conversion --- // 4. Create a uCalc.String and assign it text. var s2 = new uCalc.String(); s2 = "This is a test"; // 5. Create a Transformer from the uCalc.String to use transformer-specific methods. var t2 = new uCalc.Transformer(s2); Console.WriteLine(t2.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Create a transformer and perform a transformation
auto t = uc.NewTransformer();
t.Text("if (x > 3) y = x * 2; else if(x == 5) y = x - 1;");
t.FromTo("1", "100");
t.Transform();
// --- Interoperability and Chaining ---
auto Pattern = "if ({cond})";
// 1. Create a uCalc.String from a Transformer.
// 2. Chain .After() to get a "live view" of the text after the pattern.
uCalc::String s(t);
auto after_first_if = s.After(Pattern);
cout << after_first_if.Text() << endl;
// 3. Chain another .After() on the child string.
auto after_second_if = after_first_if.After(Pattern);
cout << after_second_if.Text() << endl;
// --- String to Transformer Conversion ---
// 4. Create a uCalc.String and assign it text.
uCalc::String s2;
s2 = "This is a test";
// 5. Create a Transformer from the uCalc.String to use transformer-specific methods.
uCalc::Transformer t2(s2);
cout << t2.Text() << endl;
}
y = x * 2; else if(x == 5) y = x - 100;
y = x - 100;
This is a test #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Create a transformer and perform a transformation auto t = uc.NewTransformer(); t.Text("if (x > 3) y = x * 2; else if(x == 5) y = x - 1;"); t.FromTo("1", "100"); t.Transform(); // --- Interoperability and Chaining --- auto Pattern = "if ({cond})"; // 1. Create a uCalc.String from a Transformer. // 2. Chain .After() to get a "live view" of the text after the pattern. uCalc::String s(t); auto after_first_if = s.After(Pattern); cout << after_first_if.Text() << endl; // 3. Chain another .After() on the child string. auto after_second_if = after_first_if.After(Pattern); cout << after_second_if.Text() << endl; // --- String to Transformer Conversion --- // 4. Create a uCalc.String and assign it text. uCalc::String s2; s2 = "This is a test"; // 5. Create a Transformer from the uCalc.String to use transformer-specific methods. uCalc::Transformer t2(s2); cout << t2.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Create a transformer and perform a transformation
Dim t = uc.NewTransformer()
t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;"
t.FromTo("1", "100")
t.Transform()
'// --- Interoperability and Chaining ---
Dim Pattern = "if ({cond})"
'// 1. Create a uCalc.String from a Transformer.
'// 2. Chain .After() to get a "live view" of the text after the pattern.
Dim s As New uCalc.String(t)
Dim after_first_if = s.After(Pattern)
Console.WriteLine(after_first_if.Text)
'// 3. Chain another .After() on the child string.
Dim after_second_if = after_first_if.After(Pattern)
Console.WriteLine(after_second_if.Text)
'// --- String to Transformer Conversion ---
'// 4. Create a uCalc.String and assign it text.
Dim s2 As New uCalc.String()
s2 = "This is a test"
'// 5. Create a Transformer from the uCalc.String to use transformer-specific methods.
Dim t2 As New uCalc.Transformer(s2)
Console.WriteLine(t2.Text)
End Sub
End Module
y = x * 2; else if(x == 5) y = x - 100;
y = x - 100;
This is a test Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Create a transformer and perform a transformation Dim t = uc.NewTransformer() t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;" t.FromTo("1", "100") t.Transform() '// --- Interoperability and Chaining --- Dim Pattern = "if ({cond})" '// 1. Create a uCalc.String from a Transformer. '// 2. Chain .After() to get a "live view" of the text after the pattern. Dim s As New uCalc.String(t) Dim after_first_if = s.After(Pattern) Console.WriteLine(after_first_if.Text) '// 3. Chain another .After() on the child string. Dim after_second_if = after_first_if.After(Pattern) Console.WriteLine(after_second_if.Text) '// --- String to Transformer Conversion --- '// 4. Create a uCalc.String and assign it text. Dim s2 As New uCalc.String() s2 = "This is a test" '// 5. Create a Transformer from the uCalc.String to use transformer-specific methods. Dim t2 As New uCalc.Transformer(s2) Console.WriteLine(t2.Text) End Sub End Module
Demonstrates introspection within a callback, retrieving the parameter count of the calling function.
ID: 614
See: Count = [Int64]
using uCalcSoftware;
var uc = new uCalc();
static void ItemCallback(uCalc.Callback cb) {
Console.WriteLine($"Function '{cb.Item.Name}' was called.");
Console.WriteLine($"It is defined with {cb.Item.Count} parameters.");
}
uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback);
uc.EvalStr("MyFunc(1, 2)");
Function 'myfunc' was called.
It is defined with 2 parameters. using uCalcSoftware; var uc = new uCalc(); static void ItemCallback(uCalc.Callback cb) { Console.WriteLine($"Function '{cb.Item.Name}' was called."); Console.WriteLine($"It is defined with {cb.Item.Count} parameters."); } uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback); uc.EvalStr("MyFunc(1, 2)");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call ItemCallback(uCalcBase::Callback cb) {
cout << "Function '" << cb.Item().Name() << "' was called." << endl;
cout << "It is defined with " << cb.Item().Count() << " parameters." << endl;
}
int main() {
uCalc uc;
uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback);
uc.EvalStr("MyFunc(1, 2)");
}
Function 'myfunc' was called.
It is defined with 2 parameters. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call ItemCallback(uCalcBase::Callback cb) { cout << "Function '" << cb.Item().Name() << "' was called." << endl; cout << "It is defined with " << cb.Item().Count() << " parameters." << endl; } int main() { uCalc uc; uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback); uc.EvalStr("MyFunc(1, 2)"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub ItemCallback(ByVal cb As uCalc.Callback)
Console.WriteLine($"Function '{cb.Item.Name}' was called.")
Console.WriteLine($"It is defined with {cb.Item.Count} parameters.")
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("MyFunc(x, y) As Double", AddressOf ItemCallback)
uc.EvalStr("MyFunc(1, 2)")
End Sub
End Module
Function 'myfunc' was called.
It is defined with 2 parameters. Imports System Imports uCalcSoftware Public Module Program Public Sub ItemCallback(ByVal cb As uCalc.Callback) Console.WriteLine($"Function '{cb.Item.Name}' was called.") Console.WriteLine($"It is defined with {cb.Item.Count} parameters.") End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("MyFunc(x, y) As Double", AddressOf ItemCallback) uc.EvalStr("MyFunc(1, 2)") End Sub End Module
Demonstrates the basic creation and immediate evaluation of an expression object.
ID: 563
See: (Constructor), Introduction
using uCalcSoftware;
var uc = new uCalc();
// Basic construction and evaluation using the default uCalc instance.
using (var MyExpr = new uCalc.Expression("10 * (2 + 3)")) {
Console.WriteLine(MyExpr.Evaluate());
}
50 using uCalcSoftware; var uc = new uCalc(); // Basic construction and evaluation using the default uCalc instance. using (var MyExpr = new uCalc.Expression("10 * (2 + 3)")) { Console.WriteLine(MyExpr.Evaluate()); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Basic construction and evaluation using the default uCalc instance.
{
uCalc::Expression MyExpr("10 * (2 + 3)");
MyExpr.Owned(); // Causes MyExpr to be released when it goes out of scope
cout << MyExpr.Evaluate() << endl;
}
}
50 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Basic construction and evaluation using the default uCalc instance. { uCalc::Expression MyExpr("10 * (2 + 3)"); MyExpr.Owned(); // Causes MyExpr to be released when it goes out of scope cout << MyExpr.Evaluate() << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Basic construction and evaluation using the default uCalc instance.
Using MyExpr As New uCalc.Expression("10 * (2 + 3)")
Console.WriteLine(MyExpr.Evaluate())
End Using
End Sub
End Module
50 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Basic construction and evaluation using the default uCalc instance. Using MyExpr As New uCalc.Expression("10 * (2 + 3)") Console.WriteLine(MyExpr.Evaluate()) End Using End Sub End Module
Demonstrates the basic difference between getting all matches and filtering for only 'focusable' ones.
ID: 1080
See: GetMatches
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "ID:100, Name:Admin, ID:200";
// Define two rules, but only one is marked as 'focusable'
t.Pattern("ID:{@Number}").SetFocusable(true);
t.Pattern("Name:{@Alpha}").SetFocusable(false);
t.Find();
// Get all matches using the default option
var allMatches = t.GetMatches();
Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---");
Console.WriteLine(allMatches.Text);
// Get only the focusable matches
var focusableMatches = t.GetMatches(MatchesOption.FocusableOnly);
Console.WriteLine("");
Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---");
Console.WriteLine(focusableMatches.Text);
--- All Matches (3) ---
ID:100
Name:Admin
ID:200
--- Focusable Matches Only (2) ---
ID:100
ID:200 using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.Text = "ID:100, Name:Admin, ID:200"; // Define two rules, but only one is marked as 'focusable' t.Pattern("ID:{@Number}").SetFocusable(true); t.Pattern("Name:{@Alpha}").SetFocusable(false); t.Find(); // Get all matches using the default option var allMatches = t.GetMatches(); Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---"); Console.WriteLine(allMatches.Text); // Get only the focusable matches var focusableMatches = t.GetMatches(MatchesOption.FocusableOnly); Console.WriteLine(""); Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---"); Console.WriteLine(focusableMatches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
t.Text("ID:100, Name:Admin, ID:200");
// Define two rules, but only one is marked as 'focusable'
t.Pattern("ID:{@Number}").SetFocusable(true);
t.Pattern("Name:{@Alpha}").SetFocusable(false);
t.Find();
// Get all matches using the default option
auto allMatches = t.GetMatches();
cout << "--- All Matches (" << allMatches.Count() << ") ---" << endl;
cout << allMatches.Text() << endl;
// Get only the focusable matches
auto focusableMatches = t.GetMatches(MatchesOption::FocusableOnly);
cout << "" << endl;
cout << "--- Focusable Matches Only (" << focusableMatches.Count() << ") ---" << endl;
cout << focusableMatches.Text() << endl;
}
--- All Matches (3) ---
ID:100
Name:Admin
ID:200
--- Focusable Matches Only (2) ---
ID:100
ID:200 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; t.Text("ID:100, Name:Admin, ID:200"); // Define two rules, but only one is marked as 'focusable' t.Pattern("ID:{@Number}").SetFocusable(true); t.Pattern("Name:{@Alpha}").SetFocusable(false); t.Find(); // Get all matches using the default option auto allMatches = t.GetMatches(); cout << "--- All Matches (" << allMatches.Count() << ") ---" << endl; cout << allMatches.Text() << endl; // Get only the focusable matches auto focusableMatches = t.GetMatches(MatchesOption::FocusableOnly); cout << "" << endl; cout << "--- Focusable Matches Only (" << focusableMatches.Count() << ") ---" << endl; cout << focusableMatches.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.Text = "ID:100, Name:Admin, ID:200"
'// Define two rules, but only one is marked as 'focusable'
t.Pattern("ID:{@Number}").SetFocusable(true)
t.Pattern("Name:{@Alpha}").SetFocusable(false)
t.Find()
'// Get all matches using the default option
Dim allMatches = t.GetMatches()
Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---")
Console.WriteLine(allMatches.Text)
'// Get only the focusable matches
Dim focusableMatches = t.GetMatches(MatchesOption.FocusableOnly)
Console.WriteLine("")
Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---")
Console.WriteLine(focusableMatches.Text)
End Sub
End Module
--- All Matches (3) ---
ID:100
Name:Admin
ID:200
--- Focusable Matches Only (2) ---
ID:100
ID:200 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.Text = "ID:100, Name:Admin, ID:200" '// Define two rules, but only one is marked as 'focusable' t.Pattern("ID:{@Number}").SetFocusable(true) t.Pattern("Name:{@Alpha}").SetFocusable(false) t.Find() '// Get all matches using the default option Dim allMatches = t.GetMatches() Console.WriteLine($"--- All Matches ({allMatches.Count()}) ---") Console.WriteLine(allMatches.Text) '// Get only the focusable matches Dim focusableMatches = t.GetMatches(MatchesOption.FocusableOnly) Console.WriteLine("") Console.WriteLine($"--- Focusable Matches Only ({focusableMatches.Count()}) ---") Console.WriteLine(focusableMatches.Text) End Sub End Module
Demonstrates the basic functionality of clearing default tokens and adding a single new one.
ID: 1021
See: Clear
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("is", "");
Console.WriteLine("--- With Default Tokens ---");
// By default, 'is' is a whole word (token)
Console.WriteLine(t.Transform("This is a test"));
// Clear all default token definitions
t.Tokens.Clear();
// Add a new, simple token that matches any single character
t.Tokens.Add(".");
Console.WriteLine("");
Console.WriteLine("--- After Clearing and Adding '.' Token ---");
// Now, 'i' and 's' are matched as separate characters
t.FromTo("is", ""); // The rule must be redefined
Console.WriteLine(t.Transform("This is a test"));
--- With Default Tokens ---
This <IS> a test
--- After Clearing and Adding '.' Token ---
Th<IS> <IS> a test using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.FromTo("is", "<IS>"); Console.WriteLine("--- With Default Tokens ---"); // By default, 'is' is a whole word (token) Console.WriteLine(t.Transform("This is a test")); // Clear all default token definitions t.Tokens.Clear(); // Add a new, simple token that matches any single character t.Tokens.Add("."); Console.WriteLine(""); Console.WriteLine("--- After Clearing and Adding '.' Token ---"); // Now, 'i' and 's' are matched as separate characters t.FromTo("is", "<IS>"); // The rule must be redefined Console.WriteLine(t.Transform("This is a test"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.FromTo("is", "");
cout << "--- With Default Tokens ---" << endl;
// By default, 'is' is a whole word (token)
cout << t.Transform("This is a test") << endl;
// Clear all default token definitions
t.Tokens().Clear();
// Add a new, simple token that matches any single character
t.Tokens().Add(".");
cout << "" << endl;
cout << "--- After Clearing and Adding '.' Token ---" << endl;
// Now, 'i' and 's' are matched as separate characters
t.FromTo("is", ""); // The rule must be redefined
cout << t.Transform("This is a test") << endl;
}
--- With Default Tokens ---
This <IS> a test
--- After Clearing and Adding '.' Token ---
Th<IS> <IS> a test #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.FromTo("is", "<IS>"); cout << "--- With Default Tokens ---" << endl; // By default, 'is' is a whole word (token) cout << t.Transform("This is a test") << endl; // Clear all default token definitions t.Tokens().Clear(); // Add a new, simple token that matches any single character t.Tokens().Add("."); cout << "" << endl; cout << "--- After Clearing and Adding '.' Token ---" << endl; // Now, 'i' and 's' are matched as separate characters t.FromTo("is", "<IS>"); // The rule must be redefined cout << t.Transform("This is a test") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.FromTo("is", "")
Console.WriteLine("--- With Default Tokens ---")
'// By default, 'is' is a whole word (token)
Console.WriteLine(t.Transform("This is a test"))
'// Clear all default token definitions
t.Tokens.Clear()
'// Add a new, simple token that matches any single character
t.Tokens.Add(".")
Console.WriteLine("")
Console.WriteLine("--- After Clearing and Adding '.' Token ---")
'// Now, 'i' and 's' are matched as separate characters
t.FromTo("is", "") '// The rule must be redefined
Console.WriteLine(t.Transform("This is a test"))
End Sub
End Module
--- With Default Tokens ---
This <IS> a test
--- After Clearing and Adding '.' Token ---
Th<IS> <IS> a test Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.FromTo("is", "<IS>") Console.WriteLine("--- With Default Tokens ---") '// By default, 'is' is a whole word (token) Console.WriteLine(t.Transform("This is a test")) '// Clear all default token definitions t.Tokens.Clear() '// Add a new, simple token that matches any single character t.Tokens.Add(".") Console.WriteLine("") Console.WriteLine("--- After Clearing and Adding '.' Token ---") '// Now, 'i' and 's' are matched as separate characters t.FromTo("is", "<IS>") '// The rule must be redefined Console.WriteLine(t.Transform("This is a test")) End Sub End Module
Demonstrates the basic getter and setter functionality of the Description property.
ID: 1033
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
var tokens = t.Tokens;
// Set a description
tokens.Description = "Default token set for general purpose parsing.";
// Get the description
Console.WriteLine(tokens.Description);
Default token set for general purpose parsing. using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); var tokens = t.Tokens; // Set a description tokens.Description = "Default token set for general purpose parsing."; // Get the description Console.WriteLine(tokens.Description);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
auto tokens = t.Tokens();
// Set a description
tokens.Description("Default token set for general purpose parsing.");
// Get the description
cout << tokens.Description() << endl;
}
Default token set for general purpose parsing. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; auto tokens = t.Tokens(); // Set a description tokens.Description("Default token set for general purpose parsing."); // Get the description cout << tokens.Description() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim tokens = t.Tokens
'// Set a description
tokens.Description = "Default token set for general purpose parsing."
'// Get the description
Console.WriteLine(tokens.Description)
End Sub
End Module
Default token set for general purpose parsing. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() Dim tokens = t.Tokens '// Set a description tokens.Description = "Default token set for general purpose parsing." '// Get the description Console.WriteLine(tokens.Description) End Sub End Module
Demonstrates the basic getter and setter syntax for a property
ID: 1160
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
// Set the description using the property setter syntax
t.Description = "My Transformer";
// Get the description using the property getter syntax
Console.WriteLine($"Description: {t.Description}");
Description: My Transformer using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); // Set the description using the property setter syntax t.Description = "My Transformer"; // Get the description using the property getter syntax Console.WriteLine($"Description: {t.Description}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
// Set the description using the property setter syntax
t.Description("My Transformer");
// Get the description using the property getter syntax
cout << "Description: " << t.Description() << endl;
}
Description: My Transformer #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; // Set the description using the property setter syntax t.Description("My Transformer"); // Get the description using the property getter syntax cout << "Description: " << t.Description() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
'// Set the description using the property setter syntax
t.Description = "My Transformer"
'// Get the description using the property getter syntax
Console.WriteLine($"Description: {t.Description}")
End Sub
End Module
Description: My Transformer Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() '// Set the description using the property setter syntax t.Description = "My Transformer" '// Get the description using the property getter syntax Console.WriteLine($"Description: {t.Description}") End Sub End Module
Demonstrates the basic LIFO (Last-In, First-Out) behavior of NextOverload with two simple rules.
ID: 954
See: NextOverload
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "This is a test.";
// Rule 1 (defined first, lower priority)
var rule1 = t.FromTo("is", "[IS_1]");
// Rule 2 (defined second, higher priority)
var rule2 = t.FromTo("is", "[IS_2]");
Console.WriteLine("--- Applying transform (Rule 2 has precedence) ---");
Console.WriteLine(t.Transform());
Console.WriteLine("");
Console.WriteLine("--- Using NextOverload ---");
// Get the rule that comes after rule2
var nextRule = rule2.NextOverload();
Console.WriteLine($"Rule 2 pattern: {rule2.Pattern}");
Console.WriteLine($"Next rule's pattern: {nextRule.Pattern}");
// Verify that the next rule is indeed rule1
Console.WriteLine($"Next rule is rule1: {nextRule.Handle() == rule1.Handle()}");
--- Applying transform (Rule 2 has precedence) ---
This [IS_2] a test.
--- Using NextOverload ---
Rule 2 pattern: is
Next rule's pattern: is
Next rule is rule1: True using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.Text = "This is a test."; // Rule 1 (defined first, lower priority) var rule1 = t.FromTo("is", "[IS_1]"); // Rule 2 (defined second, higher priority) var rule2 = t.FromTo("is", "[IS_2]"); Console.WriteLine("--- Applying transform (Rule 2 has precedence) ---"); Console.WriteLine(t.Transform()); Console.WriteLine(""); Console.WriteLine("--- Using NextOverload ---"); // Get the rule that comes after rule2 var nextRule = rule2.NextOverload(); Console.WriteLine($"Rule 2 pattern: {rule2.Pattern}"); Console.WriteLine($"Next rule's pattern: {nextRule.Pattern}"); // Verify that the next rule is indeed rule1 Console.WriteLine($"Next rule is rule1: {nextRule.Handle() == rule1.Handle()}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
uCalc::Transformer t;
t.Text("This is a test.");
// Rule 1 (defined first, lower priority)
auto rule1 = t.FromTo("is", "[IS_1]");
// Rule 2 (defined second, higher priority)
auto rule2 = t.FromTo("is", "[IS_2]");
cout << "--- Applying transform (Rule 2 has precedence) ---" << endl;
cout << t.Transform() << endl;
cout << "" << endl;
cout << "--- Using NextOverload ---" << endl;
// Get the rule that comes after rule2
auto nextRule = rule2.NextOverload();
cout << "Rule 2 pattern: " << rule2.Pattern() << endl;
cout << "Next rule's pattern: " << nextRule.Pattern() << endl;
// Verify that the next rule is indeed rule1
cout << "Next rule is rule1: " << tf(nextRule.Handle() == rule1.Handle()) << endl;
}
--- Applying transform (Rule 2 has precedence) ---
This [IS_2] a test.
--- Using NextOverload ---
Rule 2 pattern: is
Next rule's pattern: is
Next rule is rule1: True #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; uCalc::Transformer t; t.Text("This is a test."); // Rule 1 (defined first, lower priority) auto rule1 = t.FromTo("is", "[IS_1]"); // Rule 2 (defined second, higher priority) auto rule2 = t.FromTo("is", "[IS_2]"); cout << "--- Applying transform (Rule 2 has precedence) ---" << endl; cout << t.Transform() << endl; cout << "" << endl; cout << "--- Using NextOverload ---" << endl; // Get the rule that comes after rule2 auto nextRule = rule2.NextOverload(); cout << "Rule 2 pattern: " << rule2.Pattern() << endl; cout << "Next rule's pattern: " << nextRule.Pattern() << endl; // Verify that the next rule is indeed rule1 cout << "Next rule is rule1: " << tf(nextRule.Handle() == rule1.Handle()) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.Text = "This is a test."
'// Rule 1 (defined first, lower priority)
Dim rule1 = t.FromTo("is", "[IS_1]")
'// Rule 2 (defined second, higher priority)
Dim rule2 = t.FromTo("is", "[IS_2]")
Console.WriteLine("--- Applying transform (Rule 2 has precedence) ---")
Console.WriteLine(t.Transform())
Console.WriteLine("")
Console.WriteLine("--- Using NextOverload ---")
'// Get the rule that comes after rule2
Dim nextRule = rule2.NextOverload()
Console.WriteLine($"Rule 2 pattern: {rule2.Pattern}")
Console.WriteLine($"Next rule's pattern: {nextRule.Pattern}")
'// Verify that the next rule is indeed rule1
Console.WriteLine($"Next rule is rule1: {nextRule.Handle() = rule1.Handle()}")
End Sub
End Module
--- Applying transform (Rule 2 has precedence) ---
This [IS_2] a test.
--- Using NextOverload ---
Rule 2 pattern: is
Next rule's pattern: is
Next rule is rule1: True Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.Text = "This is a test." '// Rule 1 (defined first, lower priority) Dim rule1 = t.FromTo("is", "[IS_1]") '// Rule 2 (defined second, higher priority) Dim rule2 = t.FromTo("is", "[IS_2]") Console.WriteLine("--- Applying transform (Rule 2 has precedence) ---") Console.WriteLine(t.Transform()) Console.WriteLine("") Console.WriteLine("--- Using NextOverload ---") '// Get the rule that comes after rule2 Dim nextRule = rule2.NextOverload() Console.WriteLine($"Rule 2 pattern: {rule2.Pattern}") Console.WriteLine($"Next rule's pattern: {nextRule.Pattern}") '// Verify that the next rule is indeed rule1 Console.WriteLine($"Next rule is rule1: {nextRule.Handle() = rule1.Handle()}") End Sub End Module
Demonstrates the basic toggle functionality of the Active property.
ID: 862
See: Active = [bool]
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
string UserText = "The cat saw another cat.";
t.Text = UserText;
// Define a rule and hold its handle
var catRule = t.FromTo("cat", "dog");
Console.Write("1. Rule Active (Default): ");
Console.WriteLine(t.Transform());
// Deactivate the rule
catRule.Active = false;
// Re-run the transform to see the change
Console.Write("2. Rule Inactive: ");
t.Text = UserText;
Console.WriteLine(t.Transform());
// Reactivate the rule
catRule.Active = true;
Console.Write("3. Rule Reactivated: ");
Console.WriteLine(t.Transform());
1. Rule Active (Default): The dog saw another dog.
2. Rule Inactive: The cat saw another cat.
3. Rule Reactivated: The dog saw another dog. using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); string UserText = "The cat saw another cat."; t.Text = UserText; // Define a rule and hold its handle var catRule = t.FromTo("cat", "dog"); Console.Write("1. Rule Active (Default): "); Console.WriteLine(t.Transform()); // Deactivate the rule catRule.Active = false; // Re-run the transform to see the change Console.Write("2. Rule Inactive: "); t.Text = UserText; Console.WriteLine(t.Transform()); // Reactivate the rule catRule.Active = true; Console.Write("3. Rule Reactivated: "); Console.WriteLine(t.Transform());
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
string UserText = "The cat saw another cat.";
t.Text(UserText);
// Define a rule and hold its handle
auto catRule = t.FromTo("cat", "dog");
cout << "1. Rule Active (Default): ";
cout << t.Transform() << endl;
// Deactivate the rule
catRule.Active(false);
// Re-run the transform to see the change
cout << "2. Rule Inactive: ";
t.Text(UserText);
cout << t.Transform() << endl;
// Reactivate the rule
catRule.Active(true);
cout << "3. Rule Reactivated: ";
cout << t.Transform() << endl;
}
1. Rule Active (Default): The dog saw another dog.
2. Rule Inactive: The cat saw another cat.
3. Rule Reactivated: The dog saw another dog. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); string UserText = "The cat saw another cat."; t.Text(UserText); // Define a rule and hold its handle auto catRule = t.FromTo("cat", "dog"); cout << "1. Rule Active (Default): "; cout << t.Transform() << endl; // Deactivate the rule catRule.Active(false); // Re-run the transform to see the change cout << "2. Rule Inactive: "; t.Text(UserText); cout << t.Transform() << endl; // Reactivate the rule catRule.Active(true); cout << "3. Rule Reactivated: "; cout << t.Transform() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
Dim UserText As String = "The cat saw another cat."
t.Text = UserText
'// Define a rule and hold its handle
Dim catRule = t.FromTo("cat", "dog")
Console.Write("1. Rule Active (Default): ")
Console.WriteLine(t.Transform())
'// Deactivate the rule
catRule.Active = false
'// Re-run the transform to see the change
Console.Write("2. Rule Inactive: ")
t.Text = UserText
Console.WriteLine(t.Transform())
'// Reactivate the rule
catRule.Active = true
Console.Write("3. Rule Reactivated: ")
Console.WriteLine(t.Transform())
End Sub
End Module
1. Rule Active (Default): The dog saw another dog.
2. Rule Inactive: The cat saw another cat.
3. Rule Reactivated: The dog saw another dog. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() Dim UserText As String = "The cat saw another cat." t.Text = UserText '// Define a rule and hold its handle Dim catRule = t.FromTo("cat", "dog") Console.Write("1. Rule Active (Default): ") Console.WriteLine(t.Transform()) '// Deactivate the rule catRule.Active = false '// Re-run the transform to see the change Console.Write("2. Rule Inactive: ") t.Text = UserText Console.WriteLine(t.Transform()) '// Reactivate the rule catRule.Active = true Console.Write("3. Rule Reactivated: ") Console.WriteLine(t.Transform()) End Sub End Module
Demonstrates the basic true/false state of the WasModified flag.
ID: 1150
See: WasModified = [bool]
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.FromTo("a", "*a good*");
// Case 1: A match occurs, text is modified.
t.Text = "This is a test";
t.Transform();
Console.WriteLine($"Modified: {t.WasModified}");
// Case 2: No match occurs, text is unchanged.
t.Text = "This is another test";
t.Transform();
Console.WriteLine($"Modified: {t.WasModified}");
Modified: True
Modified: False using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.FromTo("a", "*a good*"); // Case 1: A match occurs, text is modified. t.Text = "This is a test"; t.Transform(); Console.WriteLine($"Modified: {t.WasModified}"); // Case 2: No match occurs, text is unchanged. t.Text = "This is another test"; t.Transform(); Console.WriteLine($"Modified: {t.WasModified}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
uCalc::Transformer t;
t.FromTo("a", "*a good*");
// Case 1: A match occurs, text is modified.
t.Text("This is a test");
t.Transform();
cout << "Modified: " << tf(t.WasModified()) << endl;
// Case 2: No match occurs, text is unchanged.
t.Text("This is another test");
t.Transform();
cout << "Modified: " << tf(t.WasModified()) << endl;
}
Modified: True
Modified: False #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; uCalc::Transformer t; t.FromTo("a", "*a good*"); // Case 1: A match occurs, text is modified. t.Text("This is a test"); t.Transform(); cout << "Modified: " << tf(t.WasModified()) << endl; // Case 2: No match occurs, text is unchanged. t.Text("This is another test"); t.Transform(); cout << "Modified: " << tf(t.WasModified()) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.FromTo("a", "*a good*")
'// Case 1: A match occurs, text is modified.
t.Text = "This is a test"
t.Transform()
Console.WriteLine($"Modified: {t.WasModified}")
'// Case 2: No match occurs, text is unchanged.
t.Text = "This is another test"
t.Transform()
Console.WriteLine($"Modified: {t.WasModified}")
End Sub
End Module
Modified: True
Modified: False Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.FromTo("a", "*a good*") '// Case 1: A match occurs, text is modified. t.Text = "This is a test" t.Transform() Console.WriteLine($"Modified: {t.WasModified}") '// Case 2: No match occurs, text is unchanged. t.Text = "This is another test" t.Transform() Console.WriteLine($"Modified: {t.WasModified}") End Sub End Module
Demonstrates the core C# idioms: `using` for lifetime management, property syntax for setters/getters, and implicit string conversions.
ID: 806
See: C#
using uCalcSoftware;
var uc = new uCalc();
// 1. Automatic resource management with 'using'
using (var u = new uCalc()) {
// 2. Property syntax for setting the description
u.Description = "My C# uCalc instance";
Console.WriteLine($"Description: {u.Description}");
// 3. Implicit string conversion for Transformer.Text
var t = new uCalc.Transformer();
t.Text = "Hello World"; // Standard assignment
t = "Hello Again"; // Implicit conversion assignment
Console.WriteLine($"Transformer Text: {t.Text}");
}
Description: My C# uCalc instance
Transformer Text: Hello Again using uCalcSoftware; var uc = new uCalc(); // 1. Automatic resource management with 'using' using (var u = new uCalc()) { // 2. Property syntax for setting the description u.Description = "My C# uCalc instance"; Console.WriteLine($"Description: {u.Description}"); // 3. Implicit string conversion for Transformer.Text var t = new uCalc.Transformer(); t.Text = "Hello World"; // Standard assignment t = "Hello Again"; // Implicit conversion assignment Console.WriteLine($"Transformer Text: {t.Text}"); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// This example is meant for C# only
cout << "Description: My C# uCalc instance" << endl;
cout << "Transformer Text: Hello Again" << endl;
}
Description: My C# uCalc instance
Transformer Text: Hello Again #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // This example is meant for C# only cout << "Description: My C# uCalc instance" << endl; cout << "Transformer Text: Hello Again" << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// This example is meant for C# only
Console.WriteLine("Description: My C# uCalc instance")
Console.WriteLine("Transformer Text: Hello Again")
End Sub
End Module
Description: My C# uCalc instance
Transformer Text: Hello Again Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// This example is meant for C# only Console.WriteLine("Description: My C# uCalc instance") Console.WriteLine("Transformer Text: Hello Again") End Sub End Module
Demonstrates the default `QuoteSensitive(true)` behavior, where a pattern match is ignored inside a string literal.
ID: 970
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.FromTo("fox", "CAT");
// The 'fox' inside the quotes is not replaced.
Console.WriteLine(t.Transform("The quick brown fox jumps over the 'lazy fox'."));
The quick brown CAT jumps over the 'lazy fox'. using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.FromTo("fox", "CAT"); // The 'fox' inside the quotes is not replaced. Console.WriteLine(t.Transform("The quick brown fox jumps over the 'lazy fox'."));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
t.FromTo("fox", "CAT");
// The 'fox' inside the quotes is not replaced.
cout << t.Transform("The quick brown fox jumps over the 'lazy fox'.") << endl;
}
The quick brown CAT jumps over the 'lazy fox'. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; t.FromTo("fox", "CAT"); // The 'fox' inside the quotes is not replaced. cout << t.Transform("The quick brown fox jumps over the 'lazy fox'.") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.FromTo("fox", "CAT")
'// The 'fox' inside the quotes is not replaced.
Console.WriteLine(t.Transform("The quick brown fox jumps over the 'lazy fox'."))
End Sub
End Module
The quick brown CAT jumps over the 'lazy fox'. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.FromTo("fox", "CAT") '// The 'fox' inside the quotes is not replaced. Console.WriteLine(t.Transform("The quick brown fox jumps over the 'lazy fox'.")) End Sub End Module
Demonstrates the difference in variable capture behavior when StatementSensitive is enabled versus disabled.
ID: 988
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
string txt = "start one; two end";
// Default behavior is StatementSensitive(true), so {body} stops at the semicolon
// and the 'end' anchor is never found. The transform fails.
var rule = t.FromTo("start {body} end", "[{body}]");
Console.WriteLine($"Sensitive (default): {t.Transform(txt)}");
rule.StatementSensitive = false;
// With StatementSensitive(false), {body} captures across the semicolon.
Console.WriteLine($"Insensitive: {t.Transform(txt)}");
Sensitive (default): start one; two end
Insensitive: [one; two] using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); string txt = "start one; two end"; // Default behavior is StatementSensitive(true), so {body} stops at the semicolon // and the 'end' anchor is never found. The transform fails. var rule = t.FromTo("start {body} end", "[{body}]"); Console.WriteLine($"Sensitive (default): {t.Transform(txt)}"); rule.StatementSensitive = false; // With StatementSensitive(false), {body} captures across the semicolon. Console.WriteLine($"Insensitive: {t.Transform(txt)}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
string txt = "start one; two end";
// Default behavior is StatementSensitive(true), so {body} stops at the semicolon
// and the 'end' anchor is never found. The transform fails.
auto rule = t.FromTo("start {body} end", "[{body}]");
cout << "Sensitive (default): " << t.Transform(txt) << endl;
rule.StatementSensitive(false);
// With StatementSensitive(false), {body} captures across the semicolon.
cout << "Insensitive: " << t.Transform(txt) << endl;
}
Sensitive (default): start one; two end
Insensitive: [one; two] #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; string txt = "start one; two end"; // Default behavior is StatementSensitive(true), so {body} stops at the semicolon // and the 'end' anchor is never found. The transform fails. auto rule = t.FromTo("start {body} end", "[{body}]"); cout << "Sensitive (default): " << t.Transform(txt) << endl; rule.StatementSensitive(false); // With StatementSensitive(false), {body} captures across the semicolon. cout << "Insensitive: " << t.Transform(txt) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim txt As String = "start one; two end"
'// Default behavior is StatementSensitive(true), so {body} stops at the semicolon
'// and the 'end' anchor is never found. The transform fails.
Dim rule = t.FromTo("start {body} end", "[{body}]")
Console.WriteLine($"Sensitive (default): {t.Transform(txt)}")
rule.StatementSensitive = false
'// With StatementSensitive(false), {body} captures across the semicolon.
Console.WriteLine($"Insensitive: {t.Transform(txt)}")
End Sub
End Module
Sensitive (default): start one; two end
Insensitive: [one; two] Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() Dim txt As String = "start one; two end" '// Default behavior is StatementSensitive(true), so {body} stops at the semicolon '// and the 'end' anchor is never found. The transform fails. Dim rule = t.FromTo("start {body} end", "[{body}]") Console.WriteLine($"Sensitive (default): {t.Transform(txt)}") rule.StatementSensitive = false '// With StatementSensitive(false), {body} captures across the semicolon. Console.WriteLine($"Insensitive: {t.Transform(txt)}") End Sub End Module
Demonstrates the pass/fail behavior of GlobalMinimum. If the rule doesn't find at least 3 'a's, the entire transform fails.
ID: 882
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
var ruleA = t.FromTo("a", "A");
var ruleB = t.FromTo("b", "B");
ruleA.GlobalMinimum = 3;
// Case 1: Fails (only 2 'a's)
Console.WriteLine("--- Case 1: Fails ---");
t.Text = "a b a b";
t.Transform();
Console.WriteLine($"Matches Found: {t.Matches.Count()}"); // Should be 0
Console.WriteLine($"Result: {t}");
// Case 2: Succeeds (3 'a's)
Console.WriteLine("");
Console.WriteLine("--- Case 2: Succeeds ---");
t.Text = "a b a b a";
t.Transform();
Console.WriteLine($"Matches Found: {t.Matches.Count()}"); // Should be 5 (3 'A's and 2 'B's)
Console.WriteLine($"Result: {t}");
--- Case 1: Fails ---
Matches Found: 0
Result: a b a b
--- Case 2: Succeeds ---
Matches Found: 5
Result: A B A B A using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); var ruleA = t.FromTo("a", "A"); var ruleB = t.FromTo("b", "B"); ruleA.GlobalMinimum = 3; // Case 1: Fails (only 2 'a's) Console.WriteLine("--- Case 1: Fails ---"); t.Text = "a b a b"; t.Transform(); Console.WriteLine($"Matches Found: {t.Matches.Count()}"); // Should be 0 Console.WriteLine($"Result: {t}"); // Case 2: Succeeds (3 'a's) Console.WriteLine(""); Console.WriteLine("--- Case 2: Succeeds ---"); t.Text = "a b a b a"; t.Transform(); Console.WriteLine($"Matches Found: {t.Matches.Count()}"); // Should be 5 (3 'A's and 2 'B's) Console.WriteLine($"Result: {t}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
auto ruleA = t.FromTo("a", "A");
auto ruleB = t.FromTo("b", "B");
ruleA.GlobalMinimum(3);
// Case 1: Fails (only 2 'a's)
cout << "--- Case 1: Fails ---" << endl;
t.Text("a b a b");
t.Transform();
cout << "Matches Found: " << t.Matches().Count() << endl; // Should be 0
cout << "Result: " << t << endl;
// Case 2: Succeeds (3 'a's)
cout << "" << endl;
cout << "--- Case 2: Succeeds ---" << endl;
t.Text("a b a b a");
t.Transform();
cout << "Matches Found: " << t.Matches().Count() << endl; // Should be 5 (3 'A's and 2 'B's)
cout << "Result: " << t << endl;
}
--- Case 1: Fails ---
Matches Found: 0
Result: a b a b
--- Case 2: Succeeds ---
Matches Found: 5
Result: A B A B A #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); auto ruleA = t.FromTo("a", "A"); auto ruleB = t.FromTo("b", "B"); ruleA.GlobalMinimum(3); // Case 1: Fails (only 2 'a's) cout << "--- Case 1: Fails ---" << endl; t.Text("a b a b"); t.Transform(); cout << "Matches Found: " << t.Matches().Count() << endl; // Should be 0 cout << "Result: " << t << endl; // Case 2: Succeeds (3 'a's) cout << "" << endl; cout << "--- Case 2: Succeeds ---" << endl; t.Text("a b a b a"); t.Transform(); cout << "Matches Found: " << t.Matches().Count() << endl; // Should be 5 (3 'A's and 2 'B's) cout << "Result: " << t << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
Dim ruleA = t.FromTo("a", "A")
Dim ruleB = t.FromTo("b", "B")
ruleA.GlobalMinimum = 3
'// Case 1: Fails (only 2 'a's)
Console.WriteLine("--- Case 1: Fails ---")
t.Text = "a b a b"
t.Transform()
Console.WriteLine($"Matches Found: {t.Matches.Count()}") '// Should be 0
Console.WriteLine($"Result: {t}")
'// Case 2: Succeeds (3 'a's)
Console.WriteLine("")
Console.WriteLine("--- Case 2: Succeeds ---")
t.Text = "a b a b a"
t.Transform()
Console.WriteLine($"Matches Found: {t.Matches.Count()}") '// Should be 5 (3 'A's and 2 'B's)
Console.WriteLine($"Result: {t}")
End Sub
End Module
--- Case 1: Fails ---
Matches Found: 0
Result: a b a b
--- Case 2: Succeeds ---
Matches Found: 5
Result: A B A B A Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() Dim ruleA = t.FromTo("a", "A") Dim ruleB = t.FromTo("b", "B") ruleA.GlobalMinimum = 3 '// Case 1: Fails (only 2 'a's) Console.WriteLine("--- Case 1: Fails ---") t.Text = "a b a b" t.Transform() Console.WriteLine($"Matches Found: {t.Matches.Count()}") '// Should be 0 Console.WriteLine($"Result: {t}") '// Case 2: Succeeds (3 'a's) Console.WriteLine("") Console.WriteLine("--- Case 2: Succeeds ---") t.Text = "a b a b a" t.Transform() Console.WriteLine($"Matches Found: {t.Matches.Count()}") '// Should be 5 (3 'A's and 2 'B's) Console.WriteLine($"Result: {t}") End Sub End Module
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.
ID: 1172
See: What is uCalc?
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
Demonstrates the recommended practice of using a scoped block for automatic resource management, preventing memory leaks.
ID: 602
See: Release
using uCalcSoftware;
var uc = new uCalc();
// A 'NewUsing' block ensures the expression is automatically released at the end of the scope.
// This is the safest pattern to prevent memory leaks.
using (var expr = new uCalc.Expression("5 * 10")) {
Console.WriteLine($"Result within scope: {expr.Evaluate()}");
}
// The 'expr' object is now released and its handle is invalid.
Console.WriteLine("Expression has been automatically released.");
Result within scope: 50
Expression has been automatically released. using uCalcSoftware; var uc = new uCalc(); // A 'NewUsing' block ensures the expression is automatically released at the end of the scope. // This is the safest pattern to prevent memory leaks. using (var expr = new uCalc.Expression("5 * 10")) { Console.WriteLine($"Result within scope: {expr.Evaluate()}"); } // The 'expr' object is now released and its handle is invalid. Console.WriteLine("Expression has been automatically released.");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// A 'NewUsing' block ensures the expression is automatically released at the end of the scope.
// This is the safest pattern to prevent memory leaks.
{
uCalc::Expression expr("5 * 10");
expr.Owned(); // Causes expr to be released when it goes out of scope
cout << "Result within scope: " << expr.Evaluate() << endl;
}
// The 'expr' object is now released and its handle is invalid.
cout << "Expression has been automatically released." << endl;
}
Result within scope: 50
Expression has been automatically released. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // A 'NewUsing' block ensures the expression is automatically released at the end of the scope. // This is the safest pattern to prevent memory leaks. { uCalc::Expression expr("5 * 10"); expr.Owned(); // Causes expr to be released when it goes out of scope cout << "Result within scope: " << expr.Evaluate() << endl; } // The 'expr' object is now released and its handle is invalid. cout << "Expression has been automatically released." << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// A 'NewUsing' block ensures the expression is automatically released at the end of the scope.
'// This is the safest pattern to prevent memory leaks.
Using expr As New uCalc.Expression("5 * 10")
Console.WriteLine($"Result within scope: {expr.Evaluate()}")
End Using
'// The 'expr' object is now released and its handle is invalid.
Console.WriteLine("Expression has been automatically released.")
End Sub
End Module
Result within scope: 50
Expression has been automatically released. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// A 'NewUsing' block ensures the expression is automatically released at the end of the scope. '// This is the safest pattern to prevent memory leaks. Using expr As New uCalc.Expression("5 * 10") Console.WriteLine($"Result within scope: {expr.Evaluate()}") End Using '// The 'expr' object is now released and its handle is invalid. Console.WriteLine("Expression has been automatically released.") End Sub End Module
Demonstrates the Transformer's token-aware safety by correctly renaming a variable without corrupting a string literal or comment.
ID: 1264
See: uCalc Transformer
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
// Turn single-line comments into whitespace tokens (to be ignored)
t.Tokens.Add("//.*", TokenType.Whitespace);
// Define a rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value");
var code = "x = 10; print('The max value is x.'); // x is 10 here";
// The Transformer correctly identifies that only the first 'x' is
// a token on its own. Imbedded occurrences of 'x' are left alone.
Console.WriteLine(t.Transform(code));
value = 10; print('The max value is x.'); // x is 10 here using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); // Turn single-line comments into whitespace tokens (to be ignored) t.Tokens.Add("//.*", TokenType.Whitespace); // Define a rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value"); var code = "x = 10; print('The max value is x.'); // x is 10 here"; // The Transformer correctly identifies that only the first 'x' is // a token on its own. Imbedded occurrences of 'x' are left alone. Console.WriteLine(t.Transform(code));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
// Turn single-line comments into whitespace tokens (to be ignored)
t.Tokens().Add("//.*", TokenType::Whitespace);
// Define a rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value");
auto code = "x = 10; print('The max value is x.'); // x is 10 here";
// The Transformer correctly identifies that only the first 'x' is
// a token on its own. Imbedded occurrences of 'x' are left alone.
cout << t.Transform(code) << endl;
}
value = 10; print('The max value is x.'); // x is 10 here #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; // Turn single-line comments into whitespace tokens (to be ignored) t.Tokens().Add("//.*", TokenType::Whitespace); // Define a rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value"); auto code = "x = 10; print('The max value is x.'); // x is 10 here"; // The Transformer correctly identifies that only the first 'x' is // a token on its own. Imbedded occurrences of 'x' are left alone. cout << t.Transform(code) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
'// Turn single-line comments into whitespace tokens (to be ignored)
t.Tokens.Add("//.*", TokenType.Whitespace)
'// Define a rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value")
Dim code = "x = 10; print('The max value is x.'); // x is 10 here"
'// The Transformer correctly identifies that only the first 'x' is
'// a token on its own. Imbedded occurrences of 'x' are left alone.
Console.WriteLine(t.Transform(code))
End Sub
End Module
value = 10; print('The max value is x.'); // x is 10 here Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() '// Turn single-line comments into whitespace tokens (to be ignored) t.Tokens.Add("//.*", TokenType.Whitespace) '// Define a rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value") Dim code = "x = 10; print('The max value is x.'); // x is 10 here" '// The Transformer correctly identifies that only the first 'x' is '// a token on its own. Imbedded occurrences of 'x' are left alone. Console.WriteLine(t.Transform(code)) End Sub End Module
Demonstrates type punning by interpreting an unsigned byte (`Int8u`) result as a signed byte (`Int8`) to observe how values wrap around.
ID: 431
See: ValueAt
using uCalcSoftware;
var uc = new uCalc();
// Define a variable 'x' that will be used in our expression
var variableX = uc.DefineVariable("x As Int");
// Parse an expression that will result in an unsigned 8-bit integer (0-255)
var parsedExpr = uc.Parse("x + 125", "Int8u");
Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)");
Console.WriteLine("------------------------------------------");
for (int x = 1; x <= 5; x++) {
variableX.ValueInt32(x);
// Evaluate the expression to get a pointer to the result
var resultPtr = parsedExpr.EvaluateVoid();
// Get the raw unsigned result
var unsignedResult = uc.ValueAt(resultPtr, "Int8u");
// Use ValueAt to *re-interpret* the same memory as a signed byte
var signedResult = uc.ValueAt(resultPtr, "Int8");
Console.WriteLine($"{x} | {unsignedResult} | {signedResult}");
}
// Clean up the created items
parsedExpr.Release();
variableX.Release();
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126 using uCalcSoftware; var uc = new uCalc(); // Define a variable 'x' that will be used in our expression var variableX = uc.DefineVariable("x As Int"); // Parse an expression that will result in an unsigned 8-bit integer (0-255) var parsedExpr = uc.Parse("x + 125", "Int8u"); Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)"); Console.WriteLine("------------------------------------------"); for (int x = 1; x <= 5; x++) { variableX.ValueInt32(x); // Evaluate the expression to get a pointer to the result var resultPtr = parsedExpr.EvaluateVoid(); // Get the raw unsigned result var unsignedResult = uc.ValueAt(resultPtr, "Int8u"); // Use ValueAt to *re-interpret* the same memory as a signed byte var signedResult = uc.ValueAt(resultPtr, "Int8"); Console.WriteLine($"{x} | {unsignedResult} | {signedResult}"); } // Clean up the created items parsedExpr.Release(); variableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Define a variable 'x' that will be used in our expression
auto variableX = uc.DefineVariable("x As Int");
// Parse an expression that will result in an unsigned 8-bit integer (0-255)
auto parsedExpr = uc.Parse("x + 125", "Int8u");
cout << "x | Int8u (0 to 255) | Int8 (-128 to 127)" << endl;
cout << "------------------------------------------" << endl;
for (int x = 1; x <= 5; x++) {
variableX.ValueInt32(x);
// Evaluate the expression to get a pointer to the result
auto resultPtr = parsedExpr.EvaluateVoid();
// Get the raw unsigned result
auto unsignedResult = uc.ValueAt(resultPtr, "Int8u");
// Use ValueAt to *re-interpret* the same memory as a signed byte
auto signedResult = uc.ValueAt(resultPtr, "Int8");
cout << x << " | " << unsignedResult << " | " << signedResult << endl;
}
// Clean up the created items
parsedExpr.Release();
variableX.Release();
}
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Define a variable 'x' that will be used in our expression auto variableX = uc.DefineVariable("x As Int"); // Parse an expression that will result in an unsigned 8-bit integer (0-255) auto parsedExpr = uc.Parse("x + 125", "Int8u"); cout << "x | Int8u (0 to 255) | Int8 (-128 to 127)" << endl; cout << "------------------------------------------" << endl; for (int x = 1; x <= 5; x++) { variableX.ValueInt32(x); // Evaluate the expression to get a pointer to the result auto resultPtr = parsedExpr.EvaluateVoid(); // Get the raw unsigned result auto unsignedResult = uc.ValueAt(resultPtr, "Int8u"); // Use ValueAt to *re-interpret* the same memory as a signed byte auto signedResult = uc.ValueAt(resultPtr, "Int8"); cout << x << " | " << unsignedResult << " | " << signedResult << endl; } // Clean up the created items parsedExpr.Release(); variableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Define a variable 'x' that will be used in our expression
Dim variableX = uc.DefineVariable("x As Int")
'// Parse an expression that will result in an unsigned 8-bit integer (0-255)
Dim parsedExpr = uc.Parse("x + 125", "Int8u")
Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)")
Console.WriteLine("------------------------------------------")
For x As Integer = 1 To 5
variableX.ValueInt32(x)
'// Evaluate the expression to get a pointer to the result
Dim resultPtr = parsedExpr.EvaluateVoid()
'// Get the raw unsigned result
Dim unsignedResult = uc.ValueAt(resultPtr, "Int8u")
'// Use ValueAt to *re-interpret* the same memory as a signed byte
Dim signedResult = uc.ValueAt(resultPtr, "Int8")
Console.WriteLine($"{x} | {unsignedResult} | {signedResult}")
Next
'// Clean up the created items
parsedExpr.Release()
variableX.Release()
End Sub
End Module
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Define a variable 'x' that will be used in our expression Dim variableX = uc.DefineVariable("x As Int") '// Parse an expression that will result in an unsigned 8-bit integer (0-255) Dim parsedExpr = uc.Parse("x + 125", "Int8u") Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)") Console.WriteLine("------------------------------------------") For x As Integer = 1 To 5 variableX.ValueInt32(x) '// Evaluate the expression to get a pointer to the result Dim resultPtr = parsedExpr.EvaluateVoid() '// Get the raw unsigned result Dim unsignedResult = uc.ValueAt(resultPtr, "Int8u") '// Use ValueAt to *re-interpret* the same memory as a signed byte Dim signedResult = uc.ValueAt(resultPtr, "Int8") Console.WriteLine($"{x} | {unsignedResult} | {signedResult}") Next '// Clean up the created items parsedExpr.Release() variableX.Release() End Sub End Module
Demonstrates using `RewindOnChange` to create a recursive `AddUp` function within the expression transformer.
ID: 980
using uCalcSoftware;
var uc = new uCalc();
var t = uc.ExpressionTransformer; // Transformer used for Eval() and Evaluate()
var p1 = t.FromTo("AddUp({x})", "{x}"); // Base case
var p2 = t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").SetRewindOnChange(true); // Recursive step
Console.WriteLine($"p1 RewindOnChange: {p1.RewindOnChange}");
Console.WriteLine($"p2 RewindOnChange: {p2.RewindOnChange}");
Console.WriteLine("");
Console.WriteLine($"Input: AddUp(1,2,3,4)");
Console.WriteLine($"Transform: {t.Transform("AddUp(1,2,3,4)")}");
Console.WriteLine($"Eval: {uc.Eval("AddUp(1,2,3,4)")}");
p1 RewindOnChange: False
p2 RewindOnChange: True
Input: AddUp(1,2,3,4)
Transform: (1 + (2 + (3 + 4)))
Eval: 10 using uCalcSoftware; var uc = new uCalc(); var t = uc.ExpressionTransformer; // Transformer used for Eval() and Evaluate() var p1 = t.FromTo("AddUp({x})", "{x}"); // Base case var p2 = t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").SetRewindOnChange(true); // Recursive step Console.WriteLine($"p1 RewindOnChange: {p1.RewindOnChange}"); Console.WriteLine($"p2 RewindOnChange: {p2.RewindOnChange}"); Console.WriteLine(""); Console.WriteLine($"Input: AddUp(1,2,3,4)"); Console.WriteLine($"Transform: {t.Transform("AddUp(1,2,3,4)")}"); Console.WriteLine($"Eval: {uc.Eval("AddUp(1,2,3,4)")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
auto t = uc.ExpressionTransformer(); // Transformer used for Eval() and Evaluate()
auto p1 = t.FromTo("AddUp({x})", "{x}"); // Base case
auto p2 = t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").SetRewindOnChange(true); // Recursive step
cout << "p1 RewindOnChange: " << tf(p1.RewindOnChange()) << endl;
cout << "p2 RewindOnChange: " << tf(p2.RewindOnChange()) << endl;
cout << "" << endl;
cout << "Input: " << "AddUp(1,2,3,4)" << endl;
cout << "Transform: " << t.Transform("AddUp(1,2,3,4)") << endl;
cout << "Eval: " << uc.Eval("AddUp(1,2,3,4)") << endl;
}
p1 RewindOnChange: False
p2 RewindOnChange: True
Input: AddUp(1,2,3,4)
Transform: (1 + (2 + (3 + 4)))
Eval: 10 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; auto t = uc.ExpressionTransformer(); // Transformer used for Eval() and Evaluate() auto p1 = t.FromTo("AddUp({x})", "{x}"); // Base case auto p2 = t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").SetRewindOnChange(true); // Recursive step cout << "p1 RewindOnChange: " << tf(p1.RewindOnChange()) << endl; cout << "p2 RewindOnChange: " << tf(p2.RewindOnChange()) << endl; cout << "" << endl; cout << "Input: " << "AddUp(1,2,3,4)" << endl; cout << "Transform: " << t.Transform("AddUp(1,2,3,4)") << endl; cout << "Eval: " << uc.Eval("AddUp(1,2,3,4)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.ExpressionTransformer '// Transformer used for Eval() and Evaluate()
Dim p1 = t.FromTo("AddUp({x})", "{x}") '// Base case
Dim p2 = t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").SetRewindOnChange(true) '// Recursive step
Console.WriteLine($"p1 RewindOnChange: {p1.RewindOnChange}")
Console.WriteLine($"p2 RewindOnChange: {p2.RewindOnChange}")
Console.WriteLine("")
Console.WriteLine($"Input: AddUp(1,2,3,4)")
Console.WriteLine($"Transform: {t.Transform("AddUp(1,2,3,4)")}")
Console.WriteLine($"Eval: {uc.Eval("AddUp(1,2,3,4)")}")
End Sub
End Module
p1 RewindOnChange: False
p2 RewindOnChange: True
Input: AddUp(1,2,3,4)
Transform: (1 + (2 + (3 + 4)))
Eval: 10 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.ExpressionTransformer '// Transformer used for Eval() and Evaluate() Dim p1 = t.FromTo("AddUp({x})", "{x}") '// Base case Dim p2 = t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").SetRewindOnChange(true) '// Recursive step Console.WriteLine($"p1 RewindOnChange: {p1.RewindOnChange}") Console.WriteLine($"p2 RewindOnChange: {p2.RewindOnChange}") Console.WriteLine("") Console.WriteLine($"Input: AddUp(1,2,3,4)") Console.WriteLine($"Transform: {t.Transform("AddUp(1,2,3,4)")}") Console.WriteLine($"Eval: {uc.Eval("AddUp(1,2,3,4)")}") End Sub End Module
Demonstrates using `RewindOnChange(true)` to perform recursive-style transformations, such as creating a variadic `AddUp` function.
ID: 346
using uCalcSoftware;
var uc = new uCalc();
var t = uc.ExpressionTransformer;
// Base case: a single argument
t.FromTo("AddUp({x})", "{x}");
// Recursive case: multiple arguments
// RewindOnChange(true) causes the transformer to re-scan the string after a replacement.
// This allows AddUp(1,2,3) -> (1 + AddUp(2,3)) -> (1 + (2 + AddUp(3))) -> (1 + (2 + 3))
t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").RewindOnChange = true;
Console.WriteLine("Input: AddUp(1, 2, 3, 4)");
Console.WriteLine($"Result: {uc.Eval("AddUp(1, 2, 3, 4)")}");
Input: AddUp(1, 2, 3, 4)
Result: 10 using uCalcSoftware; var uc = new uCalc(); var t = uc.ExpressionTransformer; // Base case: a single argument t.FromTo("AddUp({x})", "{x}"); // Recursive case: multiple arguments // RewindOnChange(true) causes the transformer to re-scan the string after a replacement. // This allows AddUp(1,2,3) -> (1 + AddUp(2,3)) -> (1 + (2 + AddUp(3))) -> (1 + (2 + 3)) t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").RewindOnChange = true; Console.WriteLine("Input: AddUp(1, 2, 3, 4)"); Console.WriteLine($"Result: {uc.Eval("AddUp(1, 2, 3, 4)")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.ExpressionTransformer();
// Base case: a single argument
t.FromTo("AddUp({x})", "{x}");
// Recursive case: multiple arguments
// RewindOnChange(true) causes the transformer to re-scan the string after a replacement.
// This allows AddUp(1,2,3) -> (1 + AddUp(2,3)) -> (1 + (2 + AddUp(3))) -> (1 + (2 + 3))
t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").RewindOnChange(true);
cout << "Input: AddUp(1, 2, 3, 4)" << endl;
cout << "Result: " << uc.Eval("AddUp(1, 2, 3, 4)") << endl;
}
Input: AddUp(1, 2, 3, 4)
Result: 10 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.ExpressionTransformer(); // Base case: a single argument t.FromTo("AddUp({x})", "{x}"); // Recursive case: multiple arguments // RewindOnChange(true) causes the transformer to re-scan the string after a replacement. // This allows AddUp(1,2,3) -> (1 + AddUp(2,3)) -> (1 + (2 + AddUp(3))) -> (1 + (2 + 3)) t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").RewindOnChange(true); cout << "Input: AddUp(1, 2, 3, 4)" << endl; cout << "Result: " << uc.Eval("AddUp(1, 2, 3, 4)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.ExpressionTransformer
'// Base case: a single argument
t.FromTo("AddUp({x})", "{x}")
'// Recursive case: multiple arguments
'// RewindOnChange(true) causes the transformer to re-scan the string after a replacement.
'// This allows AddUp(1,2,3) -> (1 + AddUp(2,3)) -> (1 + (2 + AddUp(3))) -> (1 + (2 + 3))
t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").RewindOnChange = true
Console.WriteLine("Input: AddUp(1, 2, 3, 4)")
Console.WriteLine($"Result: {uc.Eval("AddUp(1, 2, 3, 4)")}")
End Sub
End Module
Input: AddUp(1, 2, 3, 4)
Result: 10 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.ExpressionTransformer '// Base case: a single argument t.FromTo("AddUp({x})", "{x}") '// Recursive case: multiple arguments '// RewindOnChange(true) causes the transformer to re-scan the string after a replacement. '// This allows AddUp(1,2,3) -> (1 + AddUp(2,3)) -> (1 + (2 + AddUp(3))) -> (1 + (2 + 3)) t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))").RewindOnChange = true Console.WriteLine("Input: AddUp(1, 2, 3, 4)") Console.WriteLine($"Result: {uc.Eval("AddUp(1, 2, 3, 4)")}") End Sub End Module
Demonstrates using the Text property with implicit conversions (shortcuts) to parse a simple config string.
ID: 1133
See: Text = [string]
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
// Implicitly set the Text property by assigning a string to the object
t = "user=admin; level=9; theme=dark;";
// Define a rule to extract the user value
t.FromTo("user={name};", "Username: {name}");
t.Transform();
// Implicitly get the Text property by using the object in a string context
string result = t;
Console.WriteLine(result);
Username: admin level=9; theme=dark; using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); // Implicitly set the Text property by assigning a string to the object t = "user=admin; level=9; theme=dark;"; // Define a rule to extract the user value t.FromTo("user={name};", "Username: {name}"); t.Transform(); // Implicitly get the Text property by using the object in a string context string result = t; Console.WriteLine(result);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
// Implicitly set the Text property by assigning a string to the object
t = "user=admin; level=9; theme=dark;";
// Define a rule to extract the user value
t.FromTo("user={name};", "Username: {name}");
t.Transform();
// Implicitly get the Text property by using the object in a string context
string result = t;
cout << result << endl;
}
Username: admin level=9; theme=dark; #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; // Implicitly set the Text property by assigning a string to the object t = "user=admin; level=9; theme=dark;"; // Define a rule to extract the user value t.FromTo("user={name};", "Username: {name}"); t.Transform(); // Implicitly get the Text property by using the object in a string context string result = t; cout << result << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
'// Implicitly set the Text property by assigning a string to the object
t = "user=admin; level=9; theme=dark;"
'// Define a rule to extract the user value
t.FromTo("user={name};", "Username: {name}")
t.Transform()
'// Implicitly get the Text property by using the object in a string context
Dim result As String = t
Console.WriteLine(result)
End Sub
End Module
Username: admin level=9; theme=dark; Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() '// Implicitly set the Text property by assigning a string to the object t = "user=admin; level=9; theme=dark;" '// Define a rule to extract the user value t.FromTo("user={name};", "Username: {name}") t.Transform() '// Implicitly get the Text property by using the object in a string context Dim result As String = t Console.WriteLine(result) End Sub End Module
Demonstrating in-place modification with uCalc.String.Replace
ID: 227
See: Replace
using uCalcSoftware;
var uc = new uCalc();
uCalc.String text = "This is foo 1, foo 2, Foo 3, foo 4";
text.After("1").Before("3").Replace("foo", "bar"); // 'text' is now modified
Console.WriteLine(text);
This is foo 1, bar 2, bar 3, foo 4 using uCalcSoftware; var uc = new uCalc(); uCalc.String text = "This is foo 1, foo 2, Foo 3, foo 4"; text.After("1").Before("3").Replace("foo", "bar"); // 'text' is now modified Console.WriteLine(text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::String text = "This is foo 1, foo 2, Foo 3, foo 4";
text.After("1").Before("3").Replace("foo", "bar"); // 'text' is now modified
cout << text << endl;
}
This is foo 1, bar 2, bar 3, foo 4 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::String text = "This is foo 1, foo 2, Foo 3, foo 4"; text.After("1").Before("3").Replace("foo", "bar"); // 'text' is now modified cout << text << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim text As uCalc.String = "This is foo 1, foo 2, Foo 3, foo 4"
text.After("1").Before("3").Replace("foo", "bar") '// 'text' is now modified
Console.WriteLine(text)
End Sub
End Module
This is foo 1, bar 2, bar 3, foo 4 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim text As uCalc.String = "This is foo 1, foo 2, Foo 3, foo 4" text.After("1").Before("3").Replace("foo", "bar") '// 'text' is now modified Console.WriteLine(text) End Sub End Module
Demonstrating that a clone is independent and that modifying it does not affect the original.
ID: 1054
See: Clone
using uCalcSoftware;
var uc = new uCalc();
// 1. Create and configure the original transformer
var t1 = new uCalc.Transformer();
t1.FromTo("A", "B");
Console.WriteLine($"Original Transform: {t1.Transform("A C A")}");
// 2. Clone it
var t2 = t1.Clone();
// 3. Modify the clone. This does not affect the original.
t2.FromTo("C", "D");
Console.WriteLine($"Cloned Transform: {t2.Transform("A C A")}");
// 4. Verify original is unchanged by re-running its transform
Console.WriteLine($"Original is Unchanged: {t1.Transform("A C A")}");
t2.Release();
t1.Release();
Original Transform: B C B
Cloned Transform: B D B
Original is Unchanged: B C B using uCalcSoftware; var uc = new uCalc(); // 1. Create and configure the original transformer var t1 = new uCalc.Transformer(); t1.FromTo("A", "B"); Console.WriteLine($"Original Transform: {t1.Transform("A C A")}"); // 2. Clone it var t2 = t1.Clone(); // 3. Modify the clone. This does not affect the original. t2.FromTo("C", "D"); Console.WriteLine($"Cloned Transform: {t2.Transform("A C A")}"); // 4. Verify original is unchanged by re-running its transform Console.WriteLine($"Original is Unchanged: {t1.Transform("A C A")}"); t2.Release(); t1.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// 1. Create and configure the original transformer
uCalc::Transformer t1;
t1.FromTo("A", "B");
cout << "Original Transform: " << t1.Transform("A C A") << endl;
// 2. Clone it
auto t2 = t1.Clone();
// 3. Modify the clone. This does not affect the original.
t2.FromTo("C", "D");
cout << "Cloned Transform: " << t2.Transform("A C A") << endl;
// 4. Verify original is unchanged by re-running its transform
cout << "Original is Unchanged: " << t1.Transform("A C A") << endl;
t2.Release();
t1.Release();
}
Original Transform: B C B
Cloned Transform: B D B
Original is Unchanged: B C B #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // 1. Create and configure the original transformer uCalc::Transformer t1; t1.FromTo("A", "B"); cout << "Original Transform: " << t1.Transform("A C A") << endl; // 2. Clone it auto t2 = t1.Clone(); // 3. Modify the clone. This does not affect the original. t2.FromTo("C", "D"); cout << "Cloned Transform: " << t2.Transform("A C A") << endl; // 4. Verify original is unchanged by re-running its transform cout << "Original is Unchanged: " << t1.Transform("A C A") << endl; t2.Release(); t1.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// 1. Create and configure the original transformer
Dim t1 As New uCalc.Transformer()
t1.FromTo("A", "B")
Console.WriteLine($"Original Transform: {t1.Transform("A C A")}")
'// 2. Clone it
Dim t2 = t1.Clone()
'// 3. Modify the clone. This does not affect the original.
t2.FromTo("C", "D")
Console.WriteLine($"Cloned Transform: {t2.Transform("A C A")}")
'// 4. Verify original is unchanged by re-running its transform
Console.WriteLine($"Original is Unchanged: {t1.Transform("A C A")}")
t2.Release()
t1.Release()
End Sub
End Module
Original Transform: B C B
Cloned Transform: B D B
Original is Unchanged: B C B Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// 1. Create and configure the original transformer Dim t1 As New uCalc.Transformer() t1.FromTo("A", "B") Console.WriteLine($"Original Transform: {t1.Transform("A C A")}") '// 2. Clone it Dim t2 = t1.Clone() '// 3. Modify the clone. This does not affect the original. t2.FromTo("C", "D") Console.WriteLine($"Cloned Transform: {t2.Transform("A C A")}") '// 4. Verify original is unchanged by re-running its transform Console.WriteLine($"Original is Unchanged: {t1.Transform("A C A")}") t2.Release() t1.Release() End Sub End Module