uCalc SDK Interactive Examples
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
Demonstrating that each parsed expression is owned by the uCalc instance that created it.
ID: 604
See: uCalc = [uCalc]
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 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}");
#include
#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 #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; }
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 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
Demonstrating the difference between the `(0)` and `(1)` index.
ID: 894
See: {@String}, Introduction
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 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'"));
#include
#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 #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; }
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 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
Demonstration of TraceTrancform with formatting argument and IndexBase
ID: 1464
See: TraceTransform
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))) 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));
#include
#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))) #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; }
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))) 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
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))) 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));
#include
#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))) #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; }
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))) 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
Determining if a data type is compound or not with IsCompound
ID: 87
See: IsCompound = [bool]
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 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);
#include
#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 #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; }
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 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
Determining properties of an expression part
ID: 40
See: Count = [Int64], DataType = [DataType], DefineFunction, Description = [string], Description(string), IsProperty(ItemIs), Item = [Item], Name = [string], Text = [string]
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
--- 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");
#include
#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
--- #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"); }
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
--- 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
Determining whether items are functions, or arrays, etc.
ID: 47
See: IsProperty(ItemIs)
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 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)}");
#include
#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 #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; }
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 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
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 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"));
#include
#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 #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; }
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 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
Disambiguates which function or operator triggered a shared callback.
ID: 486
See: Item = [Item]
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 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");
#include
#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 #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"); }
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 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
Dispaying the number of elements in an array
ID: 46
See: Count = [Int64]
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 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}");
#include
#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 #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; }
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 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
Displaying an expression of unsigned byte as a signed byte by using a Pointer
ID: 44
See: EvaluateA, EvaluateVoid
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 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();
#include
#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 #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(); }
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 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
Displaying complex number outputs with EvaluateStr()
ID: 43
See: EvaluateStr
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 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();
#include
#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 #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(); }
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 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
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 using uCalcSoftware; var uc = new uCalc(); var VariableX = uc.DefineVariable("x"); var ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer // NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer // (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer // (such as evaluating a variable that was explicitly defined as integer; // other arithmetic operators typically evaluate to Double floating point). for (double x = 1; x <= 10; x++) { VariableX.Value(x); Console.WriteLine("x = " + VariableX.ValueStr() + " Result = " + (ParsedExpr.EvaluateInt32()).ToString()); } ParsedExpr.Release(); VariableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto VariableX = uc.DefineVariable("x");
auto ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer
// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
// (such as evaluating a variable that was explicitly defined as integer;
// other arithmetic operators typically evaluate to Double floating point).
for (double x = 1; x <= 10; x++) {
VariableX.Value(x);
cout << "x = " + VariableX.ValueStr() + " Result = " + to_string(ParsedExpr.EvaluateInt32()) << endl;
}
ParsedExpr.Release();
VariableX.Release();
}
x = 1 Result = 0
x = 2 Result = 1
x = 3 Result = 1
x = 4 Result = 2
x = 5 Result = 2
x = 6 Result = 3
x = 7 Result = 3
x = 8 Result = 4
x = 9 Result = 4
x = 10 Result = 5 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto VariableX = uc.DefineVariable("x"); auto ParsedExpr = uc.Parse("x / 2", "Integer"); // Causes output of "x / 2" to convert to an integer // NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer // (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer // (such as evaluating a variable that was explicitly defined as integer; // other arithmetic operators typically evaluate to Double floating point). for (double x = 1; x <= 10; x++) { VariableX.Value(x); cout << "x = " + VariableX.ValueStr() + " Result = " + to_string(ParsedExpr.EvaluateInt32()) << endl; } ParsedExpr.Release(); VariableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim VariableX = uc.DefineVariable("x")
Dim ParsedExpr = uc.Parse("x / 2", "Integer") '// Causes output of "x / 2" to convert to an integer
'// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer
'// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer
'// (such as evaluating a variable that was explicitly defined as integer;
'// other arithmetic operators typically evaluate to Double floating point).
For x As Double = 1 To 10
VariableX.Value(x)
Console.WriteLine("x = " + VariableX.ValueStr() + " Result = " + (ParsedExpr.EvaluateInt32()).ToString())
Next
ParsedExpr.Release()
VariableX.Release()
End Sub
End Module
x = 1 Result = 0
x = 2 Result = 1
x = 3 Result = 1
x = 4 Result = 2
x = 5 Result = 2
x = 6 Result = 3
x = 7 Result = 3
x = 8 Result = 4
x = 9 Result = 4
x = 10 Result = 5 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim VariableX = uc.DefineVariable("x") Dim ParsedExpr = uc.Parse("x / 2", "Integer") '// Causes output of "x / 2" to convert to an integer '// NOTE: EvaluateInt32 should only be used when Parse() explicitly specifies Integer '// (Or Int, or Int32) as the second argument, or if the expression evaluates to an integer '// (such as evaluating a variable that was explicitly defined as integer; '// other arithmetic operators typically evaluate to Double floating point). For x As Double = 1 To 10 VariableX.Value(x) Console.WriteLine("x = " + VariableX.ValueStr() + " Result = " + (ParsedExpr.EvaluateInt32()).ToString()) Next ParsedExpr.Release() VariableX.Release() End Sub End Module
Displaying strings with EvaluateStr()
ID: 42
See: EvaluateStr
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. 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() + "."); }
#include
#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. #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() + "."; } }
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. 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
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 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);
#include
#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 #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; }
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 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
Displays the complete list of default token definitions, showing their type, internal name, and regex pattern.
ID: 70
See: Count = [int], ExpressionTokens = [Tokens], IndexOf, Introduction, Matching by token name ({@Token}), Name = [string], Regex = [string], At, Tokens
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: \$['"] 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.
#include
#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: \$['"] #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. }
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: \$['"] 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
Doing an Eval in the same uCalc instance a variable belongs to
ID: 33
See: Release, uCalc = [uCalc]
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 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");
#include
#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 #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"); }
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 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
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 = """
content spans
multiple lines
""";
t.FromTo("{body}", "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] 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));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
auto source = R"(
content spans
multiple lines
)";
t.FromTo("{body}", "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] #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; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim source = "
content spans
multiple lines
"
t.FromTo("{body}", "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] 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
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 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 / "));
#include
#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 #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; }
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 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
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 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"));
#include
#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 #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; }
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 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
Evaluate() auto-conversion
ID: 96
See: Evaluate, EvaluateDbl
using uCalcSoftware;
var uc = new uCalc();
// The int return value type in MyExprB is converted to
// Double with .Evaluate(), but not with .EvaluateDbl()
var MyExprA = uc.Parse("3.2 + 5.2");
var MyExprB = uc.Parse("int(3.2 + 5.2)");
Console.WriteLine(MyExprA.Evaluate());
Console.WriteLine(MyExprA.EvaluateDbl() == 8.4);
Console.WriteLine(MyExprB.Evaluate());
Console.WriteLine(MyExprB.EvaluateDbl() == 8);
8.4
True
8
False using uCalcSoftware; var uc = new uCalc(); // The int return value type in MyExprB is converted to // Double with .Evaluate(), but not with .EvaluateDbl() var MyExprA = uc.Parse("3.2 + 5.2"); var MyExprB = uc.Parse("int(3.2 + 5.2)"); Console.WriteLine(MyExprA.Evaluate()); Console.WriteLine(MyExprA.EvaluateDbl() == 8.4); Console.WriteLine(MyExprB.Evaluate()); Console.WriteLine(MyExprB.EvaluateDbl() == 8);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
// The int return value type in MyExprB is converted to
// Double with .Evaluate(), but not with .EvaluateDbl()
auto MyExprA = uc.Parse("3.2 + 5.2");
auto MyExprB = uc.Parse("int(3.2 + 5.2)");
cout << MyExprA.Evaluate() << endl;
cout << tf(MyExprA.EvaluateDbl() == 8.4) << endl;
cout << MyExprB.Evaluate() << endl;
cout << tf(MyExprB.EvaluateDbl() == 8) << endl;
}
8.4
True
8
False #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; // The int return value type in MyExprB is converted to // Double with .Evaluate(), but not with .EvaluateDbl() auto MyExprA = uc.Parse("3.2 + 5.2"); auto MyExprB = uc.Parse("int(3.2 + 5.2)"); cout << MyExprA.Evaluate() << endl; cout << tf(MyExprA.EvaluateDbl() == 8.4) << endl; cout << MyExprB.Evaluate() << endl; cout << tf(MyExprB.EvaluateDbl() == 8) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// The int return value type in MyExprB is converted to
'// Double with .Evaluate(), but not with .EvaluateDbl()
Dim MyExprA = uc.Parse("3.2 + 5.2")
Dim MyExprB = uc.Parse("int(3.2 + 5.2)")
Console.WriteLine(MyExprA.Evaluate())
Console.WriteLine(MyExprA.EvaluateDbl() = 8.4)
Console.WriteLine(MyExprB.Evaluate())
Console.WriteLine(MyExprB.EvaluateDbl() = 8)
End Sub
End Module
8.4
True
8
False Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// The int return value type in MyExprB is converted to '// Double with .Evaluate(), but not with .EvaluateDbl() Dim MyExprA = uc.Parse("3.2 + 5.2") Dim MyExprB = uc.Parse("int(3.2 + 5.2)") Console.WriteLine(MyExprA.Evaluate()) Console.WriteLine(MyExprA.EvaluateDbl() = 8.4) Console.WriteLine(MyExprB.Evaluate()) Console.WriteLine(MyExprB.EvaluateDbl() = 8) End Sub End Module
EvaluateBool, also ValueStr which converts numeric value to string
ID: 93
See: EvaluateBool, ValueStr(bool)
using uCalcSoftware;
var uc = new uCalc();
var VariableX = uc.DefineVariable("x");
var ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point
for (double x = 1; x <= 5; x++) {
VariableX.Value(x);
Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}");
}
ParsedExpr.Release();
VariableX.Release();
x = 1 x > 3 is False
x = 2 x > 3 is False
x = 3 x > 3 is False
x = 4 x > 3 is True
x = 5 x > 3 is True using uCalcSoftware; var uc = new uCalc(); var VariableX = uc.DefineVariable("x"); var ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point for (double x = 1; x <= 5; x++) { VariableX.Value(x); Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}"); } ParsedExpr.Release(); VariableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
auto VariableX = uc.DefineVariable("x");
auto ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point
for (double x = 1; x <= 5; x++) {
VariableX.Value(x);
cout << "x = " << VariableX.ValueStr() << " x > 3 is " << tf(ParsedExpr.EvaluateBool()) << endl;
}
ParsedExpr.Release();
VariableX.Release();
}
x = 1 x > 3 is False
x = 2 x > 3 is False
x = 3 x > 3 is False
x = 4 x > 3 is True
x = 5 x > 3 is True #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; auto VariableX = uc.DefineVariable("x"); auto ParsedExpr = uc.Parse("x > 3"); // The > operation returns a Boolean instead of the default floating point for (double x = 1; x <= 5; x++) { VariableX.Value(x); cout << "x = " << VariableX.ValueStr() << " x > 3 is " << tf(ParsedExpr.EvaluateBool()) << endl; } ParsedExpr.Release(); VariableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim VariableX = uc.DefineVariable("x")
Dim ParsedExpr = uc.Parse("x > 3") '// The > operation returns a Boolean instead of the default floating point
For x As Double = 1 To 5
VariableX.Value(x)
Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}")
Next
ParsedExpr.Release()
VariableX.Release()
End Sub
End Module
x = 1 x > 3 is False
x = 2 x > 3 is False
x = 3 x > 3 is False
x = 4 x > 3 is True
x = 5 x > 3 is True 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 > 3") '// The > operation returns a Boolean instead of the default floating point For x As Double = 1 To 5 VariableX.Value(x) Console.WriteLine($"x = {VariableX.ValueStr()} x > 3 is {ParsedExpr.EvaluateBool()}") Next ParsedExpr.Release() VariableX.Release() End Sub End Module
Evaluates a complex boolean expression using uCalc's built-in operators.
ID: 1391
using uCalcSoftware;
var uc = new uCalc();
uc.DefineVariable("status = 'Active'");
uc.DefineVariable("login_attempts = 2");
uc.DefineVariable("is_admin = false");
var rule = "(status == 'Active' AND login_attempts < 3) OR is_admin == true";
Console.WriteLine($"Evaluating rule: {rule}");
Console.Write("Result: ");
Console.WriteLine(uc.EvalStr(rule));
Evaluating rule: (status == 'Active' AND login_attempts < 3) OR is_admin == true
Result: true using uCalcSoftware; var uc = new uCalc(); uc.DefineVariable("status = 'Active'"); uc.DefineVariable("login_attempts = 2"); uc.DefineVariable("is_admin = false"); var rule = "(status == 'Active' AND login_attempts < 3) OR is_admin == true"; Console.WriteLine($"Evaluating rule: {rule}"); Console.Write("Result: "); Console.WriteLine(uc.EvalStr(rule));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineVariable("status = 'Active'");
uc.DefineVariable("login_attempts = 2");
uc.DefineVariable("is_admin = false");
auto rule = "(status == 'Active' AND login_attempts < 3) OR is_admin == true";
cout << "Evaluating rule: " << rule << endl;
cout << "Result: ";
cout << uc.EvalStr(rule) << endl;
}
Evaluating rule: (status == 'Active' AND login_attempts < 3) OR is_admin == true
Result: true #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("status = 'Active'"); uc.DefineVariable("login_attempts = 2"); uc.DefineVariable("is_admin = false"); auto rule = "(status == 'Active' AND login_attempts < 3) OR is_admin == true"; cout << "Evaluating rule: " << rule << endl; cout << "Result: "; cout << uc.EvalStr(rule) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("status = 'Active'")
uc.DefineVariable("login_attempts = 2")
uc.DefineVariable("is_admin = false")
Dim rule = "(status == 'Active' AND login_attempts < 3) OR is_admin == true"
Console.WriteLine($"Evaluating rule: {rule}")
Console.Write("Result: ")
Console.WriteLine(uc.EvalStr(rule))
End Sub
End Module
Evaluating rule: (status == 'Active' AND login_attempts < 3) OR is_admin == true
Result: true Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("status = 'Active'") uc.DefineVariable("login_attempts = 2") uc.DefineVariable("is_admin = false") Dim rule = "(status == 'Active' AND login_attempts < 3) OR is_admin == true" Console.WriteLine($"Evaluating rule: {rule}") Console.Write("Result: ") Console.WriteLine(uc.EvalStr(rule)) End Sub End Module
Evaluating a basic arithmetic expression with multiple operators.
ID: 1177
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.EvalStr("10 * 5 + 3"));
53 using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.EvalStr("10 * 5 + 3"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.EvalStr("10 * 5 + 3") << endl;
}
53 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.EvalStr("10 * 5 + 3") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.EvalStr("10 * 5 + 3"))
End Sub
End Module
53 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.EvalStr("10 * 5 + 3")) End Sub End Module
Evaluating expressions
ID: 21
using uCalcSoftware;
var uc = new uCalc();
// See EvalStr for more examples.
Console.WriteLine(uc.Eval("1+1"));
Console.WriteLine(uc.Eval("5*(3+9)^2"));
Console.WriteLine(uc.Eval("Length('This is a test')"));
2
720
14 using uCalcSoftware; var uc = new uCalc(); // See EvalStr for more examples. Console.WriteLine(uc.Eval("1+1")); Console.WriteLine(uc.Eval("5*(3+9)^2")); Console.WriteLine(uc.Eval("Length('This is a test')"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// See EvalStr for more examples.
cout << uc.Eval("1+1") << endl;
cout << uc.Eval("5*(3+9)^2") << endl;
cout << uc.Eval("Length('This is a test')") << endl;
}
2
720
14 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // See EvalStr for more examples. cout << uc.Eval("1+1") << endl; cout << uc.Eval("5*(3+9)^2") << endl; cout << uc.Eval("Length('This is a test')") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// See EvalStr for more examples.
Console.WriteLine(uc.Eval("1+1"))
Console.WriteLine(uc.Eval("5*(3+9)^2"))
Console.WriteLine(uc.Eval("Length('This is a test')"))
End Sub
End Module
2
720
14 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// See EvalStr for more examples. Console.WriteLine(uc.Eval("1+1")) Console.WriteLine(uc.Eval("5*(3+9)^2")) Console.WriteLine(uc.Eval("Length('This is a test')")) End Sub End Module