uCalc SDK Interactive Examples

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.
				
					#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;
}
				
			
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
				
			
Result within scope: 50
Expression has been automatically released.
Demonstrates the Transformer's token-aware safety by correctly renaming a variable without corrupting a string literal or comment.

ID: 1264

				
					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
				
					#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;
}
				
			
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
				
			
value = 10; print('The max value is x.'); // x is 10 here
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
				
					#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();
}
				
			
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
				
			
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126
Demonstrates type punning by interpreting an unsigned byte (Int8u) result for 255 as a signed byte (Int8) to observe how it wraps around to -1

ID: 1480

See: ValueAt
				
					using uCalcSoftware;

var uc = new uCalc();
var myVar = uc.DefineVariable("counter As Int8u = 255");
var ptr = myVar.ValueAddr();

// Read natively as unsigned byte
Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8u")));

// Read the exact same memory address, but interpret as signed byte
Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8")));
				
			
255
-1
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto myVar = uc.DefineVariable("counter As Int8u = 255");
   auto ptr = myVar.ValueAddr();

   // Read natively as unsigned byte
   cout << uc.ValueAt(ptr, uc.DataTypeOf("Int8u")) << endl;

   // Read the exact same memory address, but interpret as signed byte
   cout << uc.ValueAt(ptr, uc.DataTypeOf("Int8")) << endl;
}
				
			
255
-1
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim myVar = uc.DefineVariable("counter As Int8u = 255")
      Dim ptr = myVar.ValueAddr()
      
      '// Read natively as unsigned byte
      Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8u")))
      
      '// Read the exact same memory address, but interpret as signed byte
      Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8")))
   End Sub
End Module
				
			
255
-1
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
				
					#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;
}
				
			
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
				
			
p1 RewindOnChange: False
p2 RewindOnChange: True

Input: AddUp(1,2,3,4)
Transform: (1 + (2 + (3 + 4)))
Eval: 10
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
				
					#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;
}
				
			
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
				
			
Input: AddUp(1, 2, 3, 4)
Result: 10
Demonstrates using the Text property with implicit conversions (shortcuts) to parse a simple config string.

ID: 1133

				
					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;
				
					#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;
}
				
			
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
				
			
Username: admin level=9; theme=dark;
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
				
					#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;
}
				
			
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
				
			
This is foo 1, bar 2, bar 3, foo 4
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
				
					#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();
}
				
			
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
				
			
Original Transform: B C B
Cloned Transform:   B D B
Original is Unchanged: B C B
Demonstrating that each parsed expression is owned by the uCalc instance that created it.

ID: 604

				
					using uCalcSoftware;

var uc = new uCalc();
// Create two separate uCalc instances
var uc1 = new uCalc();
var uc2 = new uCalc();

// Parse the same expression string in both instances
var expr1 = uc1.Parse("1 + 1");
var expr2 = uc2.Parse("1 + 1");

// Use the .uCalc() method and MemoryIndex to verify ownership
Console.WriteLine($"expr1 belongs to uc1: {expr1.uCalc.MemoryIndex == uc1.MemoryIndex}");
Console.WriteLine($"expr2 belongs to uc2: {expr2.uCalc.MemoryIndex == uc2.MemoryIndex}");
Console.WriteLine($"expr1 does not belong to uc2: {expr1.uCalc.MemoryIndex != uc2.MemoryIndex}");
				
			
expr1 belongs to uc1: True
expr2 belongs to uc2: True
expr1 does not belong to uc2: True
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   // Create two separate uCalc instances
   uCalc uc1;
   uCalc uc2;

   // Parse the same expression string in both instances
   auto expr1 = uc1.Parse("1 + 1");
   auto expr2 = uc2.Parse("1 + 1");

   // Use the .uCalc() method and MemoryIndex to verify ownership
   cout << "expr1 belongs to uc1: " << tf(expr1.uCalc().MemoryIndex() == uc1.MemoryIndex()) << endl;
   cout << "expr2 belongs to uc2: " << tf(expr2.uCalc().MemoryIndex() == uc2.MemoryIndex()) << endl;
   cout << "expr1 does not belong to uc2: " << tf(expr1.uCalc().MemoryIndex() != uc2.MemoryIndex()) << endl;
}
				
			
expr1 belongs to uc1: True
expr2 belongs to uc2: True
expr1 does not belong to uc2: True
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Create two separate uCalc instances
      Dim uc1 As New uCalc()
      Dim uc2 As New uCalc()
      
      '// Parse the same expression string in both instances
      Dim expr1 = uc1.Parse("1 + 1")
      Dim expr2 = uc2.Parse("1 + 1")
      
      '// Use the .uCalc() method and MemoryIndex to verify ownership
      Console.WriteLine($"expr1 belongs to uc1: {expr1.uCalc.MemoryIndex = uc1.MemoryIndex}")
      Console.WriteLine($"expr2 belongs to uc2: {expr2.uCalc.MemoryIndex = uc2.MemoryIndex}")
      Console.WriteLine($"expr1 does not belong to uc2: {expr1.uCalc.MemoryIndex <> uc2.MemoryIndex}")
   End Sub
End Module
				
			
expr1 belongs to uc1: True
expr2 belongs to uc2: True
expr1 does not belong to uc2: True
Demonstrating the difference between the `(0)` and `(1)` index.

ID: 894

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// Capture the string and show both versions in the replacement
t.FromTo("{@String:txt}", "With: {txt(0)}, Without: {txt(1)}, Default: {txt}");

Console.WriteLine(t.Transform("'uCalc'"));
				
			
With: 'uCalc', Without: uCalc, Default: uCalc
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // Capture the string and show both versions in the replacement
   t.FromTo("{@String:txt}", "With: {txt(0)}, Without: {txt(1)}, Default: {txt}");

   cout << t.Transform("'uCalc'") << endl;
}
				
			
With: 'uCalc', Without: uCalc, Default: uCalc
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// Capture the string and show both versions in the replacement
      t.FromTo("{@String:txt}", "With: {txt(0)}, Without: {txt(1)}, Default: {txt}")
      
      Console.WriteLine(t.Transform("'uCalc'"))
   End Sub
End Module
				
			
With: 'uCalc', Without: uCalc, Default: uCalc
Demonstrating the different FormatStyle options on a floating-point calculation.

ID: 1475

				
					using uCalcSoftware;

var uc = new uCalc();
var expr = uc.Parse("12345.6789");

// Default (General with up to 15 digits)
Console.WriteLine(expr.EvaluateStr(FormatStyle.Default));

// Fixed notation with 2 decimal places
Console.WriteLine(expr.EvaluateStr(FormatStyle.Fixed, 2));

// Scientific notation with 3 decimal places
Console.WriteLine(expr.EvaluateStr(FormatStyle.Scientific, 3));

// General notation constrained to 4 significant digits
Console.WriteLine(expr.EvaluateStr(FormatStyle.General, 4));

// Hexadecimal floating-point notation
Console.WriteLine(expr.EvaluateStr(FormatStyle.Hex));
				
			
12345.6789
12345.68
1.235e+04
1.235e+04
1.81cd6e631f8a1p+13
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto expr = uc.Parse("12345.6789");

   // Default (General with up to 15 digits)
   cout << expr.EvaluateStr(FormatStyle::Default) << endl;

   // Fixed notation with 2 decimal places
   cout << expr.EvaluateStr(FormatStyle::Fixed, 2) << endl;

   // Scientific notation with 3 decimal places
   cout << expr.EvaluateStr(FormatStyle::Scientific, 3) << endl;

   // General notation constrained to 4 significant digits
   cout << expr.EvaluateStr(FormatStyle::General, 4) << endl;

   // Hexadecimal floating-point notation
   cout << expr.EvaluateStr(FormatStyle::Hex) << endl;
}
				
			
12345.6789
12345.68
1.235e+04
1.235e+04
1.81cd6e631f8a1p+13
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim expr = uc.Parse("12345.6789")
      
      '// Default (General with up to 15 digits)
      Console.WriteLine(expr.EvaluateStr(FormatStyle.Default))
      
      '// Fixed notation with 2 decimal places
      Console.WriteLine(expr.EvaluateStr(FormatStyle.Fixed, 2))
      
      '// Scientific notation with 3 decimal places
      Console.WriteLine(expr.EvaluateStr(FormatStyle.Scientific, 3))
      
      '// General notation constrained to 4 significant digits
      Console.WriteLine(expr.EvaluateStr(FormatStyle.General, 4))
      
      '// Hexadecimal floating-point notation
      Console.WriteLine(expr.EvaluateStr(FormatStyle.Hex))
   End Sub
End Module
				
			
12345.6789
12345.68
1.235e+04
1.235e+04
1.81cd6e631f8a1p+13
Demonstration of TraceTrancform with formatting argument and IndexBase

ID: 1464

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.DefaultRuleSet.RewindOnChange = true;
t.FromTo("AddUp({x})", "{x}");
t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))");

Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)", "", "$'Step {Index}: {x}\n'"));

// 0 is the default IndexBase.  Now we use 1 instead.
// So it will now start with "Step: 1" instead of "Step: 0"
Console.WriteLine("--- Now with IndexBase = 1 ---");
Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)", "", "$'Step {Index} of {Count}: {x}\n'").IndexBase(1));
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.DefaultRuleSet().RewindOnChange(true);
   t.FromTo("AddUp({x})", "{x}");
   t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))");

   cout << t.TraceTransform("AddUp(1, 2, 3, 4)", "", "$'Step {Index}: {x}\n'") << endl;

   // 0 is the default IndexBase.  Now we use 1 instead.
   // So it will now start with "Step: 1" instead of "Step: 0"
   cout << "--- Now with IndexBase = 1 ---" << endl;
   cout << t.TraceTransform("AddUp(1, 2, 3, 4)", "", "$'Step {Index} of {Count}: {x}\n'").IndexBase(1) << endl;
}
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.DefaultRuleSet.RewindOnChange = true
      t.FromTo("AddUp({x})", "{x}")
      t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))")
      
      Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)", "", "$'Step {Index}: {x}"+vbCrLf+"'"))
      
      '// 0 is the default IndexBase.  Now we use 1 instead.
      '// So it will now start with "Step: 1" instead of "Step: 0"
      Console.WriteLine("--- Now with IndexBase = 1 ---")
      Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)", "", "$'Step {Index} of {Count}: {x}"+vbCrLf+"'").IndexBase(1))
   End Sub
End Module
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
Demonstration of TraceTrancform, ListFunction, and IndexBase

ID: 147

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.DefaultRuleSet.RewindOnChange = true;
t.FromTo("AddUp({x})", "{x}");
t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))");

Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index}: {x}\n'"));

// 0 is the default IndexBase.  Here we will use 1 instead.
// So it will now start with "Step: 1" instead of "Step: 0"
Console.WriteLine("--- Now with IndexBase = 1 ---");
Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index} of {Count}: {x}\n'").IndexBase(1));
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.DefaultRuleSet().RewindOnChange(true);
   t.FromTo("AddUp({x})", "{x}");
   t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))");

   cout << t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index}: {x}\n'") << endl;

   // 0 is the default IndexBase.  Here we will use 1 instead.
   // So it will now start with "Step: 1" instead of "Step: 0"
   cout << "--- Now with IndexBase = 1 ---" << endl;
   cout << t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index} of {Count}: {x}\n'").IndexBase(1) << endl;
}
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.DefaultRuleSet.RewindOnChange = true
      t.FromTo("AddUp({x})", "{x}")
      t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))")
      
      Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index}: {x}"+vbCrLf+"'"))
      
      '// 0 is the default IndexBase.  Here we will use 1 instead.
      '// So it will now start with "Step: 1" instead of "Step: 0"
      Console.WriteLine("--- Now with IndexBase = 1 ---")
      Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index} of {Count}: {x}"+vbCrLf+"'").IndexBase(1))
   End Sub
End Module
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
Determining if a data type is compound or not with IsCompound

ID: 87

				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine(uc.DataTypeOf("2 * (3 + 4)").IsCompound);
Console.WriteLine(uc.DataTypeOf(" 'Hello ' + 'world!' ").IsCompound);
Console.WriteLine(uc.DataTypeOf("3 + 4 * #i").IsCompound);
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).IsCompound);
Console.WriteLine(uc.DataTypeOf("Bool").IsCompound);
				
			
False
True
True
True
False
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   cout << tf(uc.DataTypeOf("2 * (3 + 4)").IsCompound()) << endl;
   cout << tf(uc.DataTypeOf(" 'Hello ' + 'world!' ").IsCompound()) << endl;
   cout << tf(uc.DataTypeOf("3 + 4 * #i").IsCompound()) << endl;
   cout << tf(uc.DataTypeOf(BuiltInType::String).IsCompound()) << endl;
   cout << tf(uc.DataTypeOf("Bool").IsCompound()) << endl;
}
				
			
False
True
True
True
False
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine(uc.DataTypeOf("2 * (3 + 4)").IsCompound)
      Console.WriteLine(uc.DataTypeOf(" 'Hello ' + 'world!' ").IsCompound)
      Console.WriteLine(uc.DataTypeOf("3 + 4 * #i").IsCompound)
      Console.WriteLine(uc.DataTypeOf(BuiltInType.String).IsCompound)
      Console.WriteLine(uc.DataTypeOf("Bool").IsCompound)
   End Sub
End Module
				
			
False
True
True
True
False
Determining properties of an expression part

ID: 40

				
					using uCalcSoftware;

var uc = new uCalc();

static void ItemCallback(uCalc.Callback cb) {
   Console.WriteLine($"Name: {cb.Item.Name}");
   Console.WriteLine($"Data type: {cb.Item.DataType.Name}");
   Console.WriteLine($"Param count: {cb.Item.Count}");
   Console.Write("Procedure type: ");
   if (cb.Item.IsProperty(ItemIs.Operator)) {
      Console.WriteLine("Operator");
   } else if (cb.Item.IsProperty(ItemIs.Function)) {
      Console.WriteLine("Function");
   }
   Console.WriteLine(cb.Item.Text);
   Console.WriteLine(cb.Item.Description);
   Console.WriteLine("---");
}


uc.DefineFunction("AAA() As Double", ItemCallback).Description = "Does this and that";
uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description = "Does something else";
uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, ItemCallback);

uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");

				
			
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32

---
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call ItemCallback(uCalcBase::Callback cb) {
   cout << "Name: " << cb.Item().Name() << endl;
   cout << "Data type: " << cb.Item().DataType().Name() << endl;
   cout << "Param count: " << cb.Item().Count() << endl;
   cout << "Procedure type: ";
   if (cb.Item().IsProperty(ItemIs::Operator)) {
      cout << "Operator" << endl;
   } else if (cb.Item().IsProperty(ItemIs::Function)) {
      cout << "Function" << endl;
   }
   cout << cb.Item().Text() << endl;
   cout << cb.Item().Description() << endl;
   cout << "---" << endl;
}
int main() {
   uCalc uc;

   uc.DefineFunction("AAA() As Double", ItemCallback).Description("Does this and that");
   uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description("Does something else");
   uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity::LeftToRight, ItemCallback);

   uc.EvalStr("AAA()");
   uc.EvalStr("BBB(9, 8, 7)");
   uc.EvalStr("5 CCC 4");

}
				
			
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32

---
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub ItemCallback(ByVal cb As uCalc.Callback)
      Console.WriteLine($"Name: {cb.Item.Name}")
      Console.WriteLine($"Data type: {cb.Item.DataType.Name}")
      Console.WriteLine($"Param count: {cb.Item.Count}")
      Console.Write("Procedure type: ")
      If cb.Item.IsProperty(ItemIs.Operator) Then
         Console.WriteLine("Operator")
         ElseIf cb.Item.IsProperty(ItemIs.Function ) Then
            Console.WriteLine("Function")
         End If
         Console.WriteLine(cb.Item.Text)
         Console.WriteLine(cb.Item.Description)
         Console.WriteLine("---")
      End Sub
      Public Sub Main()
         Dim uc As New uCalc()
         
         uc.DefineFunction("AAA() As Double", AddressOf ItemCallback).Description = "Does this and that"
         uc.DefineFunction("BBB(x, y, z) As String", AddressOf ItemCallback).Description = "Does something else"
         uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, AddressOf ItemCallback)
         
         uc.EvalStr("AAA()")
         uc.EvalStr("BBB(9, 8, 7)")
         uc.EvalStr("5 CCC 4")
         
      End Sub
   End Module
				
			
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32

---
Determining whether items are functions, or arrays, etc.

ID: 47

				
					using uCalcSoftware;

var uc = new uCalc();
uc.DefineVariable("MyVar");

Console.WriteLine($"{uc.EvalStr("'Cos is a function? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Function)}");
Console.WriteLine($"{uc.EvalStr("'Cos is a variable? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Variable)}");
Console.WriteLine($"{uc.EvalStr("'Cos is an operator? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Operator)}");
Console.WriteLine($"{uc.EvalStr("'MyVar is a function? '")}{uc.ItemOf("MyVar").IsProperty(ItemIs.Function)}");
Console.WriteLine($"{uc.EvalStr("'MyVar is a variable? '")}{uc.ItemOf("MyVar").IsProperty(ItemIs.Variable)}");
Console.WriteLine($"{uc.EvalStr("'MyVar is an operator? '")}{uc.ItemOf("MyVar").IsProperty(ItemIs.Operator)}");
Console.WriteLine($"{uc.EvalStr("'+ is a function? '")}{uc.ItemOf("+").IsProperty(ItemIs.Function)}");
Console.WriteLine($"{uc.EvalStr("'+ is a variable? '")}{uc.ItemOf("+").IsProperty(ItemIs.Variable)}");
Console.WriteLine($"{uc.EvalStr("'+ is an operator? '")}{uc.ItemOf("+").IsProperty(ItemIs.Operator)}");
Console.WriteLine($"{uc.EvalStr("'Cos not found? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.NotFound)}");
Console.WriteLine($"{uc.EvalStr("'XYZABC not found? '")}{uc.ItemOf("XYZABC").IsProperty(ItemIs.NotFound)}");
				
			
Cos is a function? True
Cos is a variable? False
Cos is an operator? False
MyVar is a function? False
MyVar is a variable? True
MyVar is an operator? False
+ is a function? False
+ is a variable? False
+ is an operator? True
Cos not found? False
XYZABC not found? True
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   uc.DefineVariable("MyVar");

   cout << uc.EvalStr("'Cos is a function? '") << tf(uc.ItemOf("Cos").IsProperty(ItemIs::Function)) << endl;
   cout << uc.EvalStr("'Cos is a variable? '") << tf(uc.ItemOf("Cos").IsProperty(ItemIs::Variable)) << endl;
   cout << uc.EvalStr("'Cos is an operator? '") << tf(uc.ItemOf("Cos").IsProperty(ItemIs::Operator)) << endl;
   cout << uc.EvalStr("'MyVar is a function? '") << tf(uc.ItemOf("MyVar").IsProperty(ItemIs::Function)) << endl;
   cout << uc.EvalStr("'MyVar is a variable? '") << tf(uc.ItemOf("MyVar").IsProperty(ItemIs::Variable)) << endl;
   cout << uc.EvalStr("'MyVar is an operator? '") << tf(uc.ItemOf("MyVar").IsProperty(ItemIs::Operator)) << endl;
   cout << uc.EvalStr("'+ is a function? '") << tf(uc.ItemOf("+").IsProperty(ItemIs::Function)) << endl;
   cout << uc.EvalStr("'+ is a variable? '") << tf(uc.ItemOf("+").IsProperty(ItemIs::Variable)) << endl;
   cout << uc.EvalStr("'+ is an operator? '") << tf(uc.ItemOf("+").IsProperty(ItemIs::Operator)) << endl;
   cout << uc.EvalStr("'Cos not found? '") << tf(uc.ItemOf("Cos").IsProperty(ItemIs::NotFound)) << endl;
   cout << uc.EvalStr("'XYZABC not found? '") << tf(uc.ItemOf("XYZABC").IsProperty(ItemIs::NotFound)) << endl;
}
				
			
Cos is a function? True
Cos is a variable? False
Cos is an operator? False
MyVar is a function? False
MyVar is a variable? True
MyVar is an operator? False
+ is a function? False
+ is a variable? False
+ is an operator? True
Cos not found? False
XYZABC not found? True
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineVariable("MyVar")
      
      Console.WriteLine($"{uc.EvalStr("'Cos is a function? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Function)}")
      Console.WriteLine($"{uc.EvalStr("'Cos is a variable? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Variable)}")
      Console.WriteLine($"{uc.EvalStr("'Cos is an operator? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.Operator)}")
      Console.WriteLine($"{uc.EvalStr("'MyVar is a function? '")}{uc.ItemOf("MyVar").IsProperty(ItemIs.Function)}")
      Console.WriteLine($"{uc.EvalStr("'MyVar is a variable? '")}{uc.ItemOf("MyVar").IsProperty(ItemIs.Variable)}")
      Console.WriteLine($"{uc.EvalStr("'MyVar is an operator? '")}{uc.ItemOf("MyVar").IsProperty(ItemIs.Operator)}")
      Console.WriteLine($"{uc.EvalStr("'+ is a function? '")}{uc.ItemOf("+").IsProperty(ItemIs.Function)}")
      Console.WriteLine($"{uc.EvalStr("'+ is a variable? '")}{uc.ItemOf("+").IsProperty(ItemIs.Variable)}")
      Console.WriteLine($"{uc.EvalStr("'+ is an operator? '")}{uc.ItemOf("+").IsProperty(ItemIs.Operator)}")
      Console.WriteLine($"{uc.EvalStr("'Cos not found? '")}{uc.ItemOf("Cos").IsProperty(ItemIs.NotFound)}")
      Console.WriteLine($"{uc.EvalStr("'XYZABC not found? '")}{uc.ItemOf("XYZABC").IsProperty(ItemIs.NotFound)}")
   End Sub
End Module
				
			
Cos is a function? True
Cos is a variable? False
Cos is an operator? False
MyVar is a function? False
MyVar is a variable? True
MyVar is an operator? False
+ is a function? False
+ is a variable? False
+ is an operator? True
Cos not found? False
XYZABC not found? True
Different output formats for different data types

ID: 28

				
					using uCalcSoftware;

var uc = new uCalc();
// String results will be surrounded by << and >>, while Boolean will be surrounded by [[ and ]]
uc.Format("DataType: String, Def: val = '<<' + val + '>>' ");
uc.Format("Bool, val = '[[' + val + ']]'"); // Shortcut notation without "DataType" or "Def"

Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine(uc.EvalStr("5 < 10"));

uc.FormatRemove();
Console.WriteLine("---");
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine(uc.EvalStr("5 < 10"));
				
			
30
<<Hello world>>
[[false]]
[[true]]
---
30
Hello world
false
true
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // String results will be surrounded by << and >>, while Boolean will be surrounded by [[ and ]]
   uc.Format("DataType: String, Def: val = '<<' + val + '>>' ");
   uc.Format("Bool, val = '[[' + val + ']]'"); // Shortcut notation without "DataType" or "Def"

   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << uc.EvalStr("5 < 10") << endl;

   uc.FormatRemove();
   cout << "---" << endl;
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << uc.EvalStr("5 < 10") << endl;
}
				
			
30
<<Hello world>>
[[false]]
[[true]]
---
30
Hello world
false
true
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// String results will be surrounded by << and >>, while Boolean will be surrounded by [[ and ]]
      uc.Format("DataType: String, Def: val = '<<' + val + '>>' ")
      uc.Format("Bool, val = '[[' + val + ']]'") '// Shortcut notation without "DataType" or "Def"
      
      Console.WriteLine(uc.EvalStr("10+20"))
      Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
      Console.WriteLine(uc.EvalStr("5 > 10"))
      Console.WriteLine(uc.EvalStr("5 < 10"))
      
      uc.FormatRemove()
      Console.WriteLine("---")
      Console.WriteLine(uc.EvalStr("10+20"))
      Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
      Console.WriteLine(uc.EvalStr("5 > 10"))
      Console.WriteLine(uc.EvalStr("5 < 10"))
   End Sub
End Module
				
			
30
<<Hello world>>
[[false]]
[[true]]
---
30
Hello world
false
true
Disambiguates which function or operator triggered a shared callback.

ID: 486

				
					using uCalcSoftware;

var uc = new uCalc();

static void SharedCallback(uCalc.Callback cb) {
   Console.WriteLine($"Callback triggered by: {cb.Item.Name}");
}

// Define two different symbols that use the same callback
uc.DefineFunction("FuncA(x, y)", SharedCallback);
uc.DefineOperator("{x} OpB {y}", 100, Associativity.LeftToRight, SharedCallback);

// Call both symbols
uc.EvalStr("FuncA(1, 2)");
uc.EvalStr("1 OpB 2");

				
			
Callback triggered by: funca
Callback triggered by: opb
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call SharedCallback(uCalcBase::Callback cb) {
   cout << "Callback triggered by: " << cb.Item().Name() << endl;
}
int main() {
   uCalc uc;
   // Define two different symbols that use the same callback
   uc.DefineFunction("FuncA(x, y)", SharedCallback);
   uc.DefineOperator("{x} OpB {y}", 100, Associativity::LeftToRight, SharedCallback);

   // Call both symbols
   uc.EvalStr("FuncA(1, 2)");
   uc.EvalStr("1 OpB 2");

}
				
			
Callback triggered by: funca
Callback triggered by: opb
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub SharedCallback(ByVal cb As uCalc.Callback)
      Console.WriteLine($"Callback triggered by: {cb.Item.Name}")
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define two different symbols that use the same callback
      uc.DefineFunction("FuncA(x, y)", AddressOf SharedCallback)
      uc.DefineOperator("{x} OpB {y}", 100, Associativity.LeftToRight, AddressOf SharedCallback)
      
      '// Call both symbols
      uc.EvalStr("FuncA(1, 2)")
      uc.EvalStr("1 OpB 2")
      
   End Sub
End Module
				
			
Callback triggered by: funca
Callback triggered by: opb
Dispaying the number of elements in an array

ID: 46

				
					using uCalcSoftware;

var uc = new uCalc();

static void MyAverage(uCalc.Callback cb) {
   double Total = 0;
   for (int x = 1; x <= cb.ArgCount(); x++) {
      Total = Total + cb.Arg(x);
   }
   cb.Return(Total / cb.ArgCount());
}

var MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
var MyArrayB = uc.DefineVariable("MyArrayB[15]");
var FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
var FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
var FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage);
var FunctionD = uc.DefineFunction("FuncD() = 1+1");

Console.WriteLine($"Elements in MyArrayA: {MyArrayA.Count}");
Console.WriteLine($"Elements in MyArrayB: {MyArrayB.Count}");
Console.WriteLine($"Params in FuncA(): {FunctionA.Count}");
Console.WriteLine($"Params in FuncB(): {FunctionB.Count}");
Console.WriteLine($"Params in FuncC(): {FunctionC.Count}"); // -1 or 2^n-1 (n=32 or 64)
Console.WriteLine($"Params in FuncD(): {FunctionD.Count}");
Console.WriteLine($"Operands in ! operator: {uc.ItemOf("!").Count}");
Console.WriteLine($"Operands in > operator: {uc.ItemOf(">").Count}");
				
			
Elements in MyArrayA: 5
Elements in MyArrayB: 15
Params in FuncA(): 3
Params in FuncB(): 4
Params in FuncC(): -1
Params in FuncD(): 0
Operands in ! operator: 1
Operands in > operator: 2
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call MyAverage(uCalcBase::Callback cb) {
   double Total = 0;
   for (int x = 1; x <= cb.ArgCount(); x++) {
      Total = Total + cb.Arg(x);
   }
   cb.Return(Total / cb.ArgCount());
}
int main() {
   uCalc uc;
   auto MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
   auto MyArrayB = uc.DefineVariable("MyArrayB[15]");
   auto FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
   auto FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
   auto FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage);
   auto FunctionD = uc.DefineFunction("FuncD() = 1+1");

   cout << "Elements in MyArrayA: " << MyArrayA.Count() << endl;
   cout << "Elements in MyArrayB: " << MyArrayB.Count() << endl;
   cout << "Params in FuncA(): " << FunctionA.Count() << endl;
   cout << "Params in FuncB(): " << FunctionB.Count() << endl;
   cout << "Params in FuncC(): " << FunctionC.Count() << endl; // -1 or 2^n-1 (n=32 or 64)
   cout << "Params in FuncD(): " << FunctionD.Count() << endl;
   cout << "Operands in ! operator: " << uc.ItemOf("!").Count() << endl;
   cout << "Operands in > operator: " << uc.ItemOf(">").Count() << endl;
}
				
			
Elements in MyArrayA: 5
Elements in MyArrayB: 15
Params in FuncA(): 3
Params in FuncB(): 4
Params in FuncC(): -1
Params in FuncD(): 0
Operands in ! operator: 1
Operands in > operator: 2
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyAverage(ByVal cb As uCalc.Callback)
      Dim Total As Double = 0
      For x  As Integer = 1 To cb.ArgCount()
         Total = Total + cb.Arg(x)
      Next
      cb.Return(Total / cb.ArgCount())
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      Dim MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}")
      Dim MyArrayB = uc.DefineVariable("MyArrayB[15]")
      Dim FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z")
      Dim FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b")
      Dim FunctionC = uc.DefineFunction("FuncC(x, y ...)", AddressOf MyAverage)
      Dim FunctionD = uc.DefineFunction("FuncD() = 1+1")
      
      Console.WriteLine($"Elements in MyArrayA: {MyArrayA.Count}")
      Console.WriteLine($"Elements in MyArrayB: {MyArrayB.Count}")
      Console.WriteLine($"Params in FuncA(): {FunctionA.Count}")
      Console.WriteLine($"Params in FuncB(): {FunctionB.Count}")
      Console.WriteLine($"Params in FuncC(): {FunctionC.Count}") '// -1 or 2^n-1 (n=32 or 64)
      Console.WriteLine($"Params in FuncD(): {FunctionD.Count}")
      Console.WriteLine($"Operands in ! operator: {uc.ItemOf("!").Count}")
      Console.WriteLine($"Operands in > operator: {uc.ItemOf(">").Count}")
   End Sub
End Module
				
			
Elements in MyArrayA: 5
Elements in MyArrayB: 15
Params in FuncA(): 3
Params in FuncB(): 4
Params in FuncC(): -1
Params in FuncD(): 0
Operands in ! operator: 1
Operands in > operator: 2
Displaying an expression of unsigned byte as a signed byte by using a Pointer

ID: 44

				
					using uCalcSoftware;

var uc = new uCalc();
var VariableX = uc.DefineVariable("x As Int");
var ParsedExpr = uc.Parse("x + 125", "Int8u");

for (int x = 1; x <= 10; x++) {
   VariableX.ValueInt32(x);
   Console.WriteLine($"x = {x}  Int8 result = {uc.ValueAt(ParsedExpr.EvaluateVoid(), "Int8")}");
}

ParsedExpr.Release();
VariableX.Release();
				
			
x = 1  Int8 result = 126
x = 2  Int8 result = 127
x = 3  Int8 result = -128
x = 4  Int8 result = -127
x = 5  Int8 result = -126
x = 6  Int8 result = -125
x = 7  Int8 result = -124
x = 8  Int8 result = -123
x = 9  Int8 result = -122
x = 10  Int8 result = -121
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto VariableX = uc.DefineVariable("x As Int");
   auto ParsedExpr = uc.Parse("x + 125", "Int8u");

   for (int x = 1; x <= 10; x++) {
      VariableX.ValueInt32(x);
      cout << "x = " << x << "  Int8 result = " << uc.ValueAt(ParsedExpr.EvaluateVoid(), "Int8") << endl;
   }

   ParsedExpr.Release();
   VariableX.Release();
}
				
			
x = 1  Int8 result = 126
x = 2  Int8 result = 127
x = 3  Int8 result = -128
x = 4  Int8 result = -127
x = 5  Int8 result = -126
x = 6  Int8 result = -125
x = 7  Int8 result = -124
x = 8  Int8 result = -123
x = 9  Int8 result = -122
x = 10  Int8 result = -121
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim VariableX = uc.DefineVariable("x As Int")
      Dim ParsedExpr = uc.Parse("x + 125", "Int8u")
      
      For x  As Integer = 1 To 10
         VariableX.ValueInt32(x)
         Console.WriteLine($"x = {x}  Int8 result = {uc.ValueAt(ParsedExpr.EvaluateVoid(), "Int8")}")
      Next
      
      ParsedExpr.Release()
      VariableX.Release()
   End Sub
End Module
				
			
x = 1  Int8 result = 126
x = 2  Int8 result = 127
x = 3  Int8 result = -128
x = 4  Int8 result = -127
x = 5  Int8 result = -126
x = 6  Int8 result = -125
x = 7  Int8 result = -124
x = 8  Int8 result = -123
x = 9  Int8 result = -122
x = 10  Int8 result = -121
Displaying complex number outputs with EvaluateStr()

ID: 43

				
					using uCalcSoftware;

var uc = new uCalc();
var VariableX = uc.DefineVariable("x");
var ParsedExpr = uc.Parse("x * #i + 5", "Complex");

for (double x = 1; x <= 10; x++) {
   VariableX.Value(x);
   // Note: EvaluateStr works with any data type;
   Console.WriteLine(uc.EvalStr("$'x = {x}  Result = '") + ParsedExpr.EvaluateStr());
}

ParsedExpr.Release();
VariableX.Release();
				
			
x = 1  Result = 5+1i
x = 2  Result = 5+2i
x = 3  Result = 5+3i
x = 4  Result = 5+4i
x = 5  Result = 5+5i
x = 6  Result = 5+6i
x = 7  Result = 5+7i
x = 8  Result = 5+8i
x = 9  Result = 5+9i
x = 10  Result = 5+10i
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto VariableX = uc.DefineVariable("x");
   auto ParsedExpr = uc.Parse("x * #i + 5", "Complex");

   for (double x = 1; x <= 10; x++) {
      VariableX.Value(x);
      // Note: EvaluateStr works with any data type;
      cout << uc.EvalStr("$'x = {x}  Result = '") + ParsedExpr.EvaluateStr() << endl;
   }

   ParsedExpr.Release();
   VariableX.Release();
}
				
			
x = 1  Result = 5+1i
x = 2  Result = 5+2i
x = 3  Result = 5+3i
x = 4  Result = 5+4i
x = 5  Result = 5+5i
x = 6  Result = 5+6i
x = 7  Result = 5+7i
x = 8  Result = 5+8i
x = 9  Result = 5+9i
x = 10  Result = 5+10i
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim VariableX = uc.DefineVariable("x")
      Dim ParsedExpr = uc.Parse("x * #i + 5", "Complex")
      
      For x  As Double = 1 To 10
         VariableX.Value(x)
         '// Note: EvaluateStr works with any data type;
         Console.WriteLine(uc.EvalStr("$'x = {x}  Result = '") + ParsedExpr.EvaluateStr())
      Next
      
      ParsedExpr.Release()
      VariableX.Release()
   End Sub
End Module
				
			
x = 1  Result = 5+1i
x = 2  Result = 5+2i
x = 3  Result = 5+3i
x = 4  Result = 5+4i
x = 5  Result = 5+5i
x = 6  Result = 5+6i
x = 7  Result = 5+7i
x = 8  Result = 5+8i
x = 9  Result = 5+9i
x = 10  Result = 5+10i
Displaying Integer (Int32) results with Evaluate32

ID: 32

				
					using uCalcSoftware;

var uc = new uCalc();
var VariableX = uc.DefineVariable("x");

var ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer

// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
// (such as evaluating a variable that was explicitly defined as integer;
// other arithmetic operators typically evaluate to Double floating point).

for (double x = 1; x <= 10; x++) {
   VariableX.Value(x);
   Console.WriteLine("x = " + VariableX.ValueStr() + "  Result = " + (ParsedExpr.EvaluateInt32()).ToString());
}

ParsedExpr.Release();
VariableX.Release();
				
			
x = 1  Result = 0
x = 2  Result = 1
x = 3  Result = 1
x = 4  Result = 2
x = 5  Result = 2
x = 6  Result = 3
x = 7  Result = 3
x = 8  Result = 4
x = 9  Result = 4
x = 10  Result = 5
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto VariableX = uc.DefineVariable("x");

   auto ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer

   // NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
   // (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
   // (such as evaluating a variable that was explicitly defined as integer;
   // other arithmetic operators typically evaluate to Double floating point).

   for (double x = 1; x <= 10; x++) {
      VariableX.Value(x);
      cout << "x = " + VariableX.ValueStr() + "  Result = " + to_string(ParsedExpr.EvaluateInt32()) << endl;
   }

   ParsedExpr.Release();
   VariableX.Release();
}
				
			
x = 1  Result = 0
x = 2  Result = 1
x = 3  Result = 1
x = 4  Result = 2
x = 5  Result = 2
x = 6  Result = 3
x = 7  Result = 3
x = 8  Result = 4
x = 9  Result = 4
x = 10  Result = 5
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim VariableX = uc.DefineVariable("x")
      
      Dim ParsedExpr = uc.Parse("x / 2", "Integer") '// Causes output of "x / 2" to convert to an integer
      
      '// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
      '// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
      '// (such as evaluating a variable that was explicitly defined as integer;
      '// other arithmetic operators typically evaluate to Double floating point).
      
      For x  As Double = 1 To 10
         VariableX.Value(x)
         Console.WriteLine("x = " + VariableX.ValueStr() + "  Result = " + (ParsedExpr.EvaluateInt32()).ToString())
      Next
      
      ParsedExpr.Release()
      VariableX.Release()
   End Sub
End Module
				
			
x = 1  Result = 0
x = 2  Result = 1
x = 3  Result = 1
x = 4  Result = 2
x = 5  Result = 2
x = 6  Result = 3
x = 7  Result = 3
x = 8  Result = 4
x = 9  Result = 4
x = 10  Result = 5
Displaying strings with EvaluateStr()

ID: 42

				
					using uCalcSoftware;

var uc = new uCalc();
var VariableX = uc.DefineVariable("x As Int32");
var MyStringVar = uc.DefineVariable("MyString = 'Hello world'");
var ParsedExpr = uc.Parse("SubStr(MyString, x, 1)");
var StrLength = uc.Eval("Length(MyString)");

for (int x = 0; x <= uc.Eval("Length(MyString) - 1"); x++) {
   VariableX.ValueInt32(x);
   Console.Write(ParsedExpr.EvaluateStr() + ".");
}
				
			
H.e.l.l.o. .w.o.r.l.d.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto VariableX = uc.DefineVariable("x As Int32");
   auto MyStringVar = uc.DefineVariable("MyString = 'Hello world'");
   auto ParsedExpr = uc.Parse("SubStr(MyString, x, 1)");
   auto StrLength = uc.Eval("Length(MyString)");

   for (int x = 0; x <= uc.Eval("Length(MyString) - 1"); x++) {
      VariableX.ValueInt32(x);
      cout << ParsedExpr.EvaluateStr() + ".";
   }
}
				
			
H.e.l.l.o. .w.o.r.l.d.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim VariableX = uc.DefineVariable("x As Int32")
      Dim MyStringVar = uc.DefineVariable("MyString = 'Hello world'")
      Dim ParsedExpr = uc.Parse("SubStr(MyString, x, 1)")
      Dim StrLength = uc.Eval("Length(MyString)")
      
      For x  As Integer = 0 To uc.Eval("Length(MyString) - 1")
         VariableX.ValueInt32(x)
         Console.Write(ParsedExpr.EvaluateStr() + ".")
      Next
   End Sub
End Module
				
			
H.e.l.l.o. .w.o.r.l.d.
Displaying the data type of a parsed expression

ID: 41

				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name);
Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name);
Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name);
Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name);
				
			
double
string
complex
bool
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << uc.Parse(" 3 + 6 * 10 ").DataType().Name() << endl;
   cout << uc.Parse(" 'This ' + 'is a string' ").DataType().Name() << endl;
   cout << uc.Parse(" 2 + 8 * #i / 2").DataType().Name() << endl;
   cout << uc.Parse(" 10 + 2 > 3").DataType().Name() << endl;
}
				
			
double
string
complex
bool
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name)
      Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name)
      Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name)
      Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name)
   End Sub
End Module
				
			
double
string
complex
bool
Displays the complete list of default token definitions, showing their type, internal name, and regex pattern.

ID: 70

				
					using uCalcSoftware;

var uc = new uCalc();
// Lists all tokens currently defined for the expression evaluator.

Console.WriteLine($"Token Count: {uc.ExpressionTokens.Count}");
Console.WriteLine("");
Console.WriteLine("Index  Type  Name: regex");
Console.WriteLine("========================");
var Tokens = uc.ExpressionTokens;
foreach(var token in Tokens) {
   Console.Write(Tokens.IndexOf(token));
   Console.WriteLine($"  {token.Description}  {token.Name}: {token.Regex}");
}

// Note that the expression evaluator token list has a few extra tokens,
// related to hex/bin/oct notation, string interpolation, and imaginary number
// notation, which are not found in the default Transformer token list.
				
			
Token Count: 30

Index  Type  Name: regex
========================
0  generic  _token_line: .*
1  generic  _token_catchall: .
2  generic  _token_catchall_utf8_other: [\xf0-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]|[\xc0-\xdf][\x80-\xbf]
3  generic  _token_punctuation: (--|\.{3}|\xE2\x80\xA6|[!"#$%&'()*+,\-./:;<=>?@\[\\\]^_`{|}~]|\xE2\x80[\x90-\x95])
4  generic  _token_quotechar: ("){3}|"|'
5  generic  _token_quotechar_single: '
6  generic  _token_quotechar_double: "
7  generic  _token_quotechar_tripledouble: """
8  memberaccess  _token_memberaccess: \.
9  generic  _token_variableargs: \.\.\.
10  reducible  _token_reducible2: [-:|+/*^&=%@!`\\<>?#$~]+
11  bracket  _token_parenthesis: \(
12  bracketclose  _token_parenthesis_close: \)
13  bracket  _token_curlybrace: \{
14  bracketclose  _token_curlybrace_close: \}
15  bracket  _token_squarebracket: \[
16  bracketclose  _token_squarebracket_close: \]
17  argseparator  _token_argseparator: ,
18  statementseparator  _token_newline: (?:\r?\n)|\r
19  statementseparator  _token_semicolon: ;
20  literal  _token_string_singlequoted: '([^']*(?:''[^']*)*)'
21  literal  _token_string_doublequoted: "([^"]*(?:""[^"]*)*)"
22  literal  _token_string_tripledoublequoted: """([\s\S]*?)"""
23  whitespace  _token_whitespace: [\t\v ]+
24  reducible  _token_reducible: [-:|+/*^&=%@!`\\<>?]+
25  literal  _token_floatnumber: [0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?
26  alphanumeric  _token_alphanumeric: [a-zA-Z_][a-zA-Z0-9_]*
27  literal  _token_imaginaryunit: #i
28  tokentransform  _token_binaryhexoctalnotation: #[bho][0-9A-F]+
29  tokentransform  _token_stringinterpolationquote: \$['"]
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Lists all tokens currently defined for the expression evaluator.

   cout << "Token Count: " << uc.ExpressionTokens().Count() << endl;
   cout << "" << endl;
   cout << "Index  Type  Name: regex" << endl;
   cout << "========================" << endl;
   auto Tokens = uc.ExpressionTokens();
   for(auto token : Tokens) {
      cout << Tokens.IndexOf(token);
      cout << "  " << token.Description() << "  " << token.Name() << ": " << token.Regex() << endl;
   }

   // Note that the expression evaluator token list has a few extra tokens,
   // related to hex/bin/oct notation, string interpolation, and imaginary number
   // notation, which are not found in the default Transformer token list.
}
				
			
Token Count: 30

Index  Type  Name: regex
========================
0  generic  _token_line: .*
1  generic  _token_catchall: .
2  generic  _token_catchall_utf8_other: [\xf0-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]|[\xc0-\xdf][\x80-\xbf]
3  generic  _token_punctuation: (--|\.{3}|\xE2\x80\xA6|[!"#$%&'()*+,\-./:;<=>?@\[\\\]^_`{|}~]|\xE2\x80[\x90-\x95])
4  generic  _token_quotechar: ("){3}|"|'
5  generic  _token_quotechar_single: '
6  generic  _token_quotechar_double: "
7  generic  _token_quotechar_tripledouble: """
8  memberaccess  _token_memberaccess: \.
9  generic  _token_variableargs: \.\.\.
10  reducible  _token_reducible2: [-:|+/*^&=%@!`\\<>?#$~]+
11  bracket  _token_parenthesis: \(
12  bracketclose  _token_parenthesis_close: \)
13  bracket  _token_curlybrace: \{
14  bracketclose  _token_curlybrace_close: \}
15  bracket  _token_squarebracket: \[
16  bracketclose  _token_squarebracket_close: \]
17  argseparator  _token_argseparator: ,
18  statementseparator  _token_newline: (?:\r?\n)|\r
19  statementseparator  _token_semicolon: ;
20  literal  _token_string_singlequoted: '([^']*(?:''[^']*)*)'
21  literal  _token_string_doublequoted: "([^"]*(?:""[^"]*)*)"
22  literal  _token_string_tripledoublequoted: """([\s\S]*?)"""
23  whitespace  _token_whitespace: [\t\v ]+
24  reducible  _token_reducible: [-:|+/*^&=%@!`\\<>?]+
25  literal  _token_floatnumber: [0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?
26  alphanumeric  _token_alphanumeric: [a-zA-Z_][a-zA-Z0-9_]*
27  literal  _token_imaginaryunit: #i
28  tokentransform  _token_binaryhexoctalnotation: #[bho][0-9A-F]+
29  tokentransform  _token_stringinterpolationquote: \$['"]
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Lists all tokens currently defined for the expression evaluator.
      
      Console.WriteLine($"Token Count: {uc.ExpressionTokens.Count}")
      Console.WriteLine("")
      Console.WriteLine("Index  Type  Name: regex")
      Console.WriteLine("========================")
      Dim Tokens = uc.ExpressionTokens
      For Each token In Tokens
         Console.Write(Tokens.IndexOf(token))
         Console.WriteLine($"  {token.Description}  {token.Name}: {token.Regex}")
      Next
      
      '// Note that the expression evaluator token list has a few extra tokens,
      '// related to hex/bin/oct notation, string interpolation, and imaginary number
      '// notation, which are not found in the default Transformer token list.
   End Sub
End Module
				
			
Token Count: 30

Index  Type  Name: regex
========================
0  generic  _token_line: .*
1  generic  _token_catchall: .
2  generic  _token_catchall_utf8_other: [\xf0-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]|[\xc0-\xdf][\x80-\xbf]
3  generic  _token_punctuation: (--|\.{3}|\xE2\x80\xA6|[!"#$%&'()*+,\-./:;<=>?@\[\\\]^_`{|}~]|\xE2\x80[\x90-\x95])
4  generic  _token_quotechar: ("){3}|"|'
5  generic  _token_quotechar_single: '
6  generic  _token_quotechar_double: "
7  generic  _token_quotechar_tripledouble: """
8  memberaccess  _token_memberaccess: \.
9  generic  _token_variableargs: \.\.\.
10  reducible  _token_reducible2: [-:|+/*^&=%@!`\\<>?#$~]+
11  bracket  _token_parenthesis: \(
12  bracketclose  _token_parenthesis_close: \)
13  bracket  _token_curlybrace: \{
14  bracketclose  _token_curlybrace_close: \}
15  bracket  _token_squarebracket: \[
16  bracketclose  _token_squarebracket_close: \]
17  argseparator  _token_argseparator: ,
18  statementseparator  _token_newline: (?:\r?\n)|\r
19  statementseparator  _token_semicolon: ;
20  literal  _token_string_singlequoted: '([^']*(?:''[^']*)*)'
21  literal  _token_string_doublequoted: "([^"]*(?:""[^"]*)*)"
22  literal  _token_string_tripledoublequoted: """([\s\S]*?)"""
23  whitespace  _token_whitespace: [\t\v ]+
24  reducible  _token_reducible: [-:|+/*^&=%@!`\\<>?]+
25  literal  _token_floatnumber: [0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?
26  alphanumeric  _token_alphanumeric: [a-zA-Z_][a-zA-Z0-9_]*
27  literal  _token_imaginaryunit: #i
28  tokentransform  _token_binaryhexoctalnotation: #[bho][0-9A-F]+
29  tokentransform  _token_stringinterpolationquote: \$['"]
Doing an Eval in the same uCalc instance a variable belongs to

ID: 33

				
					using uCalcSoftware;

var uc = new uCalc();
var uc1 = new uCalc();
var uc2 = new uCalc();

var x1 = uc1.DefineVariable("x = 5");
var x2 = uc2.DefineVariable("x = 6");

Console.WriteLine(x1.uCalc.Eval("x*10")); // Same as uc1.Eval("x*10")
Console.WriteLine(x2.uCalc.Eval("x*10")); // Same as uc2.Eval("x*10")

uc1.Release();  // Since x1 is part of uc1, x1 is automatically released as well
uc2.Release();  // Since x2 is part of uc2, x2 is automatically released as well

// You should no longer use x1 or x2 because they were part of uc1 & uc2
// Don not try x1.uCalc().Eval("x*10"); or x2.uCalc().Eval("x*10");
				
			
50
60
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc uc1;
   uCalc uc2;

   auto x1 = uc1.DefineVariable("x = 5");
   auto x2 = uc2.DefineVariable("x = 6");

   cout << x1.uCalc().Eval("x*10") << endl; // Same as uc1.Eval("x*10")
   cout << x2.uCalc().Eval("x*10") << endl; // Same as uc2.Eval("x*10")

   uc1.Release();  // Since x1 is part of uc1, x1 is automatically released as well
   uc2.Release();  // Since x2 is part of uc2, x2 is automatically released as well

   // You should no longer use x1 or x2 because they were part of uc1 & uc2
   // Don not try x1.uCalc().Eval("x*10"); or x2.uCalc().Eval("x*10");
}
				
			
50
60
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim uc1 As New uCalc()
      Dim uc2 As New uCalc()
      
      Dim x1 = uc1.DefineVariable("x = 5")
      Dim x2 = uc2.DefineVariable("x = 6")
      
      Console.WriteLine(x1.uCalc.Eval("x*10")) '// Same as uc1.Eval("x*10")
      Console.WriteLine(x2.uCalc.Eval("x*10")) '// Same as uc2.Eval("x*10")
      
      uc1.Release()  '// Since x1 is part of uc1, x1 is automatically released as well
      uc2.Release()  '// Since x2 is part of uc2, x2 is automatically released as well
      
      '// You should no longer use x1 or x2 because they were part of uc1 & uc2
      '// Don not try x1.uCalc().Eval("x*10"); or x2.uCalc().Eval("x*10");
   End Sub
End Module
				
			
50
60
Dynamically re-categorizes the newline token to treat it as whitespace, allowing a pattern to match across multiple lines.

ID: 1013

See: ByName
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
var source = """
<data>
  content spans
  multiple lines
</data>
""";
t.FromTo("<data>{body}</data>", "Body: [{body}]");

Console.WriteLine("--- Before: Newline is a Separator ---");
Console.WriteLine(t.Transform(source));

// Use ByName to find the newline token and change its type.
t.Tokens.ByName("_token_newline", TokenType.Whitespace);

Console.WriteLine("");
Console.WriteLine("--- After: Newline is Whitespace ---");
Console.WriteLine(t.Transform(source));
				
			
--- Before: Newline is a Separator ---
<data>
  content spans
  multiple lines
</data>

--- After: Newline is Whitespace ---
Body: [content spans
  multiple lines]
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   auto source = R"(<data>
  content spans
  multiple lines
</data>)";
   t.FromTo("<data>{body}</data>", "Body: [{body}]");

   cout << "--- Before: Newline is a Separator ---" << endl;
   cout << t.Transform(source) << endl;

   // Use ByName to find the newline token and change its type.
   t.Tokens().ByName("_token_newline", TokenType::Whitespace);

   cout << "" << endl;
   cout << "--- After: Newline is Whitespace ---" << endl;
   cout << t.Transform(source) << endl;
}
				
			
--- Before: Newline is a Separator ---
<data>
  content spans
  multiple lines
</data>

--- After: Newline is Whitespace ---
Body: [content spans
  multiple lines]
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      Dim source = "<data>
  content spans
  multiple lines
</data>"
      t.FromTo("<data>{body}</data>", "Body: [{body}]")
      
      Console.WriteLine("--- Before: Newline is a Separator ---")
      Console.WriteLine(t.Transform(source))
      
      '// Use ByName to find the newline token and change its type.
      t.Tokens.ByName("_token_newline", TokenType.Whitespace)
      
      Console.WriteLine("")
      Console.WriteLine("--- After: Newline is Whitespace ---")
      Console.WriteLine(t.Transform(source))
   End Sub
End Module
				
			
--- Before: Newline is a Separator ---
<data>
  content spans
  multiple lines
</data>

--- After: Newline is Whitespace ---
Body: [content spans
  multiple lines]
Error handler order

ID: 55

				
					using uCalcSoftware;

var uc = new uCalc();

static void ErrorHandlerA(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("Handler A called");
}

static void ErrorHandlerB(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("Handler B called");
}

static void ErrorHandlerC(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("Handler C called");
}

static void ErrorHandlerD(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("Handler D called");
}

static void ErrorHandlerE(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("Handler E called");
}


uc.Error.AddHandler(ErrorHandlerA);
uc.Error.AddHandler(ErrorHandlerB);
uc.Error.AddHandler(ErrorHandlerC);
uc.Error.AddHandler(ErrorHandlerD, -1);
uc.Error.AddHandler(ErrorHandlerE, 3);

Console.WriteLine(uc.EvalStr("10 / "));
				
			
Handler C called
Handler B called
Handler A called
Handler E called
Handler D called
Syntax error
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call ErrorHandlerA(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "Handler A called" << endl;
}

void ucalc_call ErrorHandlerB(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "Handler B called" << endl;
}

void ucalc_call ErrorHandlerC(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "Handler C called" << endl;
}

void ucalc_call ErrorHandlerD(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "Handler D called" << endl;
}

void ucalc_call ErrorHandlerE(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "Handler E called" << endl;
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(ErrorHandlerA);
   uc.Error().AddHandler(ErrorHandlerB);
   uc.Error().AddHandler(ErrorHandlerC);
   uc.Error().AddHandler(ErrorHandlerD, -1);
   uc.Error().AddHandler(ErrorHandlerE, 3);

   cout << uc.EvalStr("10 / ") << endl;
}
				
			
Handler C called
Handler B called
Handler A called
Handler E called
Handler D called
Syntax error
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub ErrorHandlerA(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("Handler A called")
   End Sub
   
   Public Sub ErrorHandlerB(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("Handler B called")
   End Sub
   
   Public Sub ErrorHandlerC(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("Handler C called")
   End Sub
   
   Public Sub ErrorHandlerD(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("Handler D called")
   End Sub
   
   Public Sub ErrorHandlerE(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("Handler E called")
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf ErrorHandlerA)
      uc.Error.AddHandler(AddressOf ErrorHandlerB)
      uc.Error.AddHandler(AddressOf ErrorHandlerC)
      uc.Error.AddHandler(AddressOf ErrorHandlerD, -1)
      uc.Error.AddHandler(AddressOf ErrorHandlerE, 3)
      
      Console.WriteLine(uc.EvalStr("10 / "))
   End Sub
End Module
				
			
Handler C called
Handler B called
Handler A called
Handler E called
Handler D called
Syntax error
Error handler to auto-define variables

ID: 54

				
					using uCalcSoftware;

var uc = new uCalc();

// This error handler allows you to use variables that were not
// explicitly defined previously, by defining the unrecognized identifiers
// as variables instead of returning an error
static void AutoVariableDef(Handle_uCalc h) {
   var uc = new uCalc(h);
   if (uc.Error.Code == ErrorCode.Undefined_Identifier) {
      uc.DefineVariable(uc.Error.Symbol);
      uc.Error.Response = ErrorHandlerResponse.Resume;
   }
}


uc.Error.AddHandler(AutoVariableDef);
Console.WriteLine(uc.Eval("AutoTest = 123"));
Console.WriteLine(uc.Eval("AutoTest * 1000"));
				
			
123
123000
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

// This error handler allows you to use variables that were not
// explicitly defined previously, by defining the unrecognized identifiers
// as variables instead of returning an error
void ucalc_call AutoVariableDef(Handle_uCalc h) {
   auto uc = uCalc(h);
   if (uc.Error().Code() == ErrorCode::Undefined_Identifier) {
      uc.DefineVariable(uc.Error().Symbol());
      uc.Error().Response(ErrorHandlerResponse::Resume);
   }
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(AutoVariableDef);
   cout << uc.Eval("AutoTest = 123") << endl;
   cout << uc.Eval("AutoTest * 1000") << endl;
}
				
			
123
123000
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   '// This error handler allows you to use variables that were not
   '// explicitly defined previously, by defining the unrecognized identifiers
   '// as variables instead of returning an error
   Public Sub AutoVariableDef(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      If uc.Error.Code = ErrorCode.Undefined_Identifier Then
         uc.DefineVariable(uc.Error.Symbol)
         uc.Error.Response = ErrorHandlerResponse.Resume
      End If
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf AutoVariableDef)
      Console.WriteLine(uc.Eval("AutoTest = 123"))
      Console.WriteLine(uc.Eval("AutoTest * 1000"))
   End Sub
End Module
				
			
123
123000