uCalc SDK Interactive Examples
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
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
Evaluating expressions returned as string
ID: 23
See: EvalStr
using uCalcSoftware;
var uc = new uCalc();
uc.DefineVariable("x = 123");
uc.DefineVariable("y");
Console.WriteLine(uc.EvalStr("1 + 1"));
Console.WriteLine(uc.EvalStr("UCase('Hello ' + 'world!')"));
Console.WriteLine(uc.EvalStr("$'Interpolation: {2+3}'"));
Console.WriteLine(uc.EvalStr("#b101 + #hAE"));
Console.WriteLine(uc.EvalStr("Hex(1234)"));
Console.WriteLine(uc.EvalStr("(3+5*#i)^2"));
Console.WriteLine(uc.EvalStr("3 > 4"));
Console.WriteLine(uc.EvalStr("Max(5, 10, 3, -5)"));
Console.WriteLine(uc.EvalStr("x * 10"));
uc.EvalStr("x = 456");
Console.WriteLine(uc.EvalStr("x"));
Console.WriteLine(uc.EvalStr("2+4, 5+4, 10+20"));
Console.WriteLine(uc.EvalStr("y=100; ForLoop(x, 1, 10, 1, y = y + x); y"));
Console.WriteLine(uc.EvalStr("10 / "));
2
HELLO WORLD!
Interpolation: 5
179
4d2
-16+30i
false
10
1230
456
30
155
Syntax error using uCalcSoftware; var uc = new uCalc(); uc.DefineVariable("x = 123"); uc.DefineVariable("y"); Console.WriteLine(uc.EvalStr("1 + 1")); Console.WriteLine(uc.EvalStr("UCase('Hello ' + 'world!')")); Console.WriteLine(uc.EvalStr("$'Interpolation: {2+3}'")); Console.WriteLine(uc.EvalStr("#b101 + #hAE")); Console.WriteLine(uc.EvalStr("Hex(1234)")); Console.WriteLine(uc.EvalStr("(3+5*#i)^2")); Console.WriteLine(uc.EvalStr("3 > 4")); Console.WriteLine(uc.EvalStr("Max(5, 10, 3, -5)")); Console.WriteLine(uc.EvalStr("x * 10")); uc.EvalStr("x = 456"); Console.WriteLine(uc.EvalStr("x")); Console.WriteLine(uc.EvalStr("2+4, 5+4, 10+20")); Console.WriteLine(uc.EvalStr("y=100; ForLoop(x, 1, 10, 1, y = y + x); y")); Console.WriteLine(uc.EvalStr("10 / "));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineVariable("x = 123");
uc.DefineVariable("y");
cout << uc.EvalStr("1 + 1") << endl;
cout << uc.EvalStr("UCase('Hello ' + 'world!')") << endl;
cout << uc.EvalStr("$'Interpolation: {2+3}'") << endl;
cout << uc.EvalStr("#b101 + #hAE") << endl;
cout << uc.EvalStr("Hex(1234)") << endl;
cout << uc.EvalStr("(3+5*#i)^2") << endl;
cout << uc.EvalStr("3 > 4") << endl;
cout << uc.EvalStr("Max(5, 10, 3, -5)") << endl;
cout << uc.EvalStr("x * 10") << endl;
uc.EvalStr("x = 456");
cout << uc.EvalStr("x") << endl;
cout << uc.EvalStr("2+4, 5+4, 10+20") << endl;
cout << uc.EvalStr("y=100; ForLoop(x, 1, 10, 1, y = y + x); y") << endl;
cout << uc.EvalStr("10 / ") << endl;
}
2
HELLO WORLD!
Interpolation: 5
179
4d2
-16+30i
false
10
1230
456
30
155
Syntax error #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("x = 123"); uc.DefineVariable("y"); cout << uc.EvalStr("1 + 1") << endl; cout << uc.EvalStr("UCase('Hello ' + 'world!')") << endl; cout << uc.EvalStr("$'Interpolation: {2+3}'") << endl; cout << uc.EvalStr("#b101 + #hAE") << endl; cout << uc.EvalStr("Hex(1234)") << endl; cout << uc.EvalStr("(3+5*#i)^2") << endl; cout << uc.EvalStr("3 > 4") << endl; cout << uc.EvalStr("Max(5, 10, 3, -5)") << endl; cout << uc.EvalStr("x * 10") << endl; uc.EvalStr("x = 456"); cout << uc.EvalStr("x") << endl; cout << uc.EvalStr("2+4, 5+4, 10+20") << endl; cout << uc.EvalStr("y=100; ForLoop(x, 1, 10, 1, y = y + x); y") << endl; cout << uc.EvalStr("10 / ") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x = 123")
uc.DefineVariable("y")
Console.WriteLine(uc.EvalStr("1 + 1"))
Console.WriteLine(uc.EvalStr("UCase('Hello ' + 'world!')"))
Console.WriteLine(uc.EvalStr("$'Interpolation: {2+3}'"))
Console.WriteLine(uc.EvalStr("#b101 + #hAE"))
Console.WriteLine(uc.EvalStr("Hex(1234)"))
Console.WriteLine(uc.EvalStr("(3+5*#i)^2"))
Console.WriteLine(uc.EvalStr("3 > 4"))
Console.WriteLine(uc.EvalStr("Max(5, 10, 3, -5)"))
Console.WriteLine(uc.EvalStr("x * 10"))
uc.EvalStr("x = 456")
Console.WriteLine(uc.EvalStr("x"))
Console.WriteLine(uc.EvalStr("2+4, 5+4, 10+20"))
Console.WriteLine(uc.EvalStr("y=100; ForLoop(x, 1, 10, 1, y = y + x); y"))
Console.WriteLine(uc.EvalStr("10 / "))
End Sub
End Module
2
HELLO WORLD!
Interpolation: 5
179
4d2
-16+30i
false
10
1230
456
30
155
Syntax error Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x = 123") uc.DefineVariable("y") Console.WriteLine(uc.EvalStr("1 + 1")) Console.WriteLine(uc.EvalStr("UCase('Hello ' + 'world!')")) Console.WriteLine(uc.EvalStr("$'Interpolation: {2+3}'")) Console.WriteLine(uc.EvalStr("#b101 + #hAE")) Console.WriteLine(uc.EvalStr("Hex(1234)")) Console.WriteLine(uc.EvalStr("(3+5*#i)^2")) Console.WriteLine(uc.EvalStr("3 > 4")) Console.WriteLine(uc.EvalStr("Max(5, 10, 3, -5)")) Console.WriteLine(uc.EvalStr("x * 10")) uc.EvalStr("x = 456") Console.WriteLine(uc.EvalStr("x")) Console.WriteLine(uc.EvalStr("2+4, 5+4, 10+20")) Console.WriteLine(uc.EvalStr("y=100; ForLoop(x, 1, 10, 1, y = y + x); y")) Console.WriteLine(uc.EvalStr("10 / ")) End Sub End Module
Expression constructor
ID: 94
See: (Constructor), Release
using uCalcSoftware;
var uc = new uCalc();
uCalc.DefaultInstance.DefineVariable("x = 1.2");
uc.DefineVariable("x = 3.2");
var MyExprA = new uCalc.Expression();
var MyExprB = new uCalc.Expression("x+4.25");
var MyExprC = new uCalc.Expression("x+4.25", uCalc.DefaultInstance.DataTypeOf("int"));
var MyExprD = new uCalc.Expression(uc, "x+4.25");
MyExprA.Parse("x*100");
Console.WriteLine(MyExprA.Evaluate());
Console.WriteLine(MyExprB.Evaluate());
Console.WriteLine(MyExprC.Evaluate());
Console.WriteLine(MyExprD.Evaluate());
// Release expressions when no longer needed (see other example for auto-release)
MyExprA.Release();
MyExprB.Release();
MyExprC.Release();
MyExprD.Release();
120
5.45
5
7.45 using uCalcSoftware; var uc = new uCalc(); uCalc.DefaultInstance.DefineVariable("x = 1.2"); uc.DefineVariable("x = 3.2"); var MyExprA = new uCalc.Expression(); var MyExprB = new uCalc.Expression("x+4.25"); var MyExprC = new uCalc.Expression("x+4.25", uCalc.DefaultInstance.DataTypeOf("int")); var MyExprD = new uCalc.Expression(uc, "x+4.25"); MyExprA.Parse("x*100"); Console.WriteLine(MyExprA.Evaluate()); Console.WriteLine(MyExprB.Evaluate()); Console.WriteLine(MyExprC.Evaluate()); Console.WriteLine(MyExprD.Evaluate()); // Release expressions when no longer needed (see other example for auto-release) MyExprA.Release(); MyExprB.Release(); MyExprC.Release(); MyExprD.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::DefaultInstance().DefineVariable("x = 1.2");
uc.DefineVariable("x = 3.2");
uCalc::Expression MyExprA;
uCalc::Expression MyExprB("x+4.25");
uCalc::Expression MyExprC("x+4.25", uCalc::DefaultInstance().DataTypeOf("int"));
uCalc::Expression MyExprD(uc, "x+4.25");
MyExprA.Parse("x*100");
cout << MyExprA.Evaluate() << endl;
cout << MyExprB.Evaluate() << endl;
cout << MyExprC.Evaluate() << endl;
cout << MyExprD.Evaluate() << endl;
// Release expressions when no longer needed (see other example for auto-release)
MyExprA.Release();
MyExprB.Release();
MyExprC.Release();
MyExprD.Release();
}
120
5.45
5
7.45 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::DefaultInstance().DefineVariable("x = 1.2"); uc.DefineVariable("x = 3.2"); uCalc::Expression MyExprA; uCalc::Expression MyExprB("x+4.25"); uCalc::Expression MyExprC("x+4.25", uCalc::DefaultInstance().DataTypeOf("int")); uCalc::Expression MyExprD(uc, "x+4.25"); MyExprA.Parse("x*100"); cout << MyExprA.Evaluate() << endl; cout << MyExprB.Evaluate() << endl; cout << MyExprC.Evaluate() << endl; cout << MyExprD.Evaluate() << endl; // Release expressions when no longer needed (see other example for auto-release) MyExprA.Release(); MyExprB.Release(); MyExprC.Release(); MyExprD.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uCalc.DefaultInstance.DefineVariable("x = 1.2")
uc.DefineVariable("x = 3.2")
Dim MyExprA As New uCalc.Expression()
Dim MyExprB As New uCalc.Expression("x+4.25")
Dim MyExprC As New uCalc.Expression("x+4.25", uCalc.DefaultInstance.DataTypeOf("int"))
Dim MyExprD As New uCalc.Expression(uc, "x+4.25")
MyExprA.Parse("x*100")
Console.WriteLine(MyExprA.Evaluate())
Console.WriteLine(MyExprB.Evaluate())
Console.WriteLine(MyExprC.Evaluate())
Console.WriteLine(MyExprD.Evaluate())
'// Release expressions when no longer needed (see other example for auto-release)
MyExprA.Release()
MyExprB.Release()
MyExprC.Release()
MyExprD.Release()
End Sub
End Module
120
5.45
5
7.45 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uCalc.DefaultInstance.DefineVariable("x = 1.2") uc.DefineVariable("x = 3.2") Dim MyExprA As New uCalc.Expression() Dim MyExprB As New uCalc.Expression("x+4.25") Dim MyExprC As New uCalc.Expression("x+4.25", uCalc.DefaultInstance.DataTypeOf("int")) Dim MyExprD As New uCalc.Expression(uc, "x+4.25") MyExprA.Parse("x*100") Console.WriteLine(MyExprA.Evaluate()) Console.WriteLine(MyExprB.Evaluate()) Console.WriteLine(MyExprC.Evaluate()) Console.WriteLine(MyExprD.Evaluate()) '// Release expressions when no longer needed (see other example for auto-release) MyExprA.Release() MyExprB.Release() MyExprC.Release() MyExprD.Release() End Sub End Module
Extends the parser to support C-style `0x` hex and `0b` binary notations using a token transformer.
ID: 342
See: Add(string, TokenType, string, int, RegExGrammar, int), ExpressionTokens = [Tokens], TokenTransformer = [Transformer]
using uCalcSoftware;
var uc = new uCalc();
// Define a token for C-like 0x hex notation
uc.ExpressionTokens.Add("0x[0-9A-Fa-f]+", TokenType.TokenTransform);
uc.TokenTransformer.FromTo("{'0x'}{Num:'[0-9A-Fa-f]+'}", "BaseConvert('{Num}', 16)");
Console.WriteLine($"0xFF is evaluated as: {uc.EvalStr("0xFF")}");
// Define a token for C++-style 0b binary notation
uc.ExpressionTokens.Add("0b[01]+", TokenType.TokenTransform);
// Using {@Eval} is more efficient as the conversion happens once during the token transform pass.
uc.TokenTransformer.FromTo("{'0b'}{Num:'[01]+'}", "{@Eval: BaseConvert(Num, 2)}");
Console.WriteLine($"0b1011 is evaluated as: {uc.EvalStr("0b1011")}");
// Note: uCalc has built-in support for hex/binary using # notation (e.g., #hFF, #b1011)
Console.WriteLine($"uCalc's built-in #hFF is: {uc.EvalStr("#hFF")}");
0xFF is evaluated as: 255
0b1011 is evaluated as: 11
uCalc's built-in #hFF is: 255 using uCalcSoftware; var uc = new uCalc(); // Define a token for C-like 0x hex notation uc.ExpressionTokens.Add("0x[0-9A-Fa-f]+", TokenType.TokenTransform); uc.TokenTransformer.FromTo("{'0x'}{Num:'[0-9A-Fa-f]+'}", "BaseConvert('{Num}', 16)"); Console.WriteLine($"0xFF is evaluated as: {uc.EvalStr("0xFF")}"); // Define a token for C++-style 0b binary notation uc.ExpressionTokens.Add("0b[01]+", TokenType.TokenTransform); // Using {@Eval} is more efficient as the conversion happens once during the token transform pass. uc.TokenTransformer.FromTo("{'0b'}{Num:'[01]+'}", "{@Eval: BaseConvert(Num, 2)}"); Console.WriteLine($"0b1011 is evaluated as: {uc.EvalStr("0b1011")}"); // Note: uCalc has built-in support for hex/binary using # notation (e.g., #hFF, #b1011) Console.WriteLine($"uCalc's built-in #hFF is: {uc.EvalStr("#hFF")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Define a token for C-like 0x hex notation
uc.ExpressionTokens().Add("0x[0-9A-Fa-f]+", TokenType::TokenTransform);
uc.TokenTransformer().FromTo("{'0x'}{Num:'[0-9A-Fa-f]+'}", "BaseConvert('{Num}', 16)");
cout << "0xFF is evaluated as: " << uc.EvalStr("0xFF") << endl;
// Define a token for C++-style 0b binary notation
uc.ExpressionTokens().Add("0b[01]+", TokenType::TokenTransform);
// Using {@Eval} is more efficient as the conversion happens once during the token transform pass.
uc.TokenTransformer().FromTo("{'0b'}{Num:'[01]+'}", "{@Eval: BaseConvert(Num, 2)}");
cout << "0b1011 is evaluated as: " << uc.EvalStr("0b1011") << endl;
// Note: uCalc has built-in support for hex/binary using # notation (e.g., #hFF, #b1011)
cout << "uCalc's built-in #hFF is: " << uc.EvalStr("#hFF") << endl;
}
0xFF is evaluated as: 255
0b1011 is evaluated as: 11
uCalc's built-in #hFF is: 255 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Define a token for C-like 0x hex notation uc.ExpressionTokens().Add("0x[0-9A-Fa-f]+", TokenType::TokenTransform); uc.TokenTransformer().FromTo("{'0x'}{Num:'[0-9A-Fa-f]+'}", "BaseConvert('{Num}', 16)"); cout << "0xFF is evaluated as: " << uc.EvalStr("0xFF") << endl; // Define a token for C++-style 0b binary notation uc.ExpressionTokens().Add("0b[01]+", TokenType::TokenTransform); // Using {@Eval} is more efficient as the conversion happens once during the token transform pass. uc.TokenTransformer().FromTo("{'0b'}{Num:'[01]+'}", "{@Eval: BaseConvert(Num, 2)}"); cout << "0b1011 is evaluated as: " << uc.EvalStr("0b1011") << endl; // Note: uCalc has built-in support for hex/binary using # notation (e.g., #hFF, #b1011) cout << "uCalc's built-in #hFF is: " << uc.EvalStr("#hFF") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Define a token for C-like 0x hex notation
uc.ExpressionTokens.Add("0x[0-9A-Fa-f]+", TokenType.TokenTransform)
uc.TokenTransformer.FromTo("{'0x'}{Num:'[0-9A-Fa-f]+'}", "BaseConvert('{Num}', 16)")
Console.WriteLine($"0xFF is evaluated as: {uc.EvalStr("0xFF")}")
'// Define a token for C++-style 0b binary notation
uc.ExpressionTokens.Add("0b[01]+", TokenType.TokenTransform)
'// Using {@Eval} is more efficient as the conversion happens once during the token transform pass.
uc.TokenTransformer.FromTo("{'0b'}{Num:'[01]+'}", "{@Eval: BaseConvert(Num, 2)}")
Console.WriteLine($"0b1011 is evaluated as: {uc.EvalStr("0b1011")}")
'// Note: uCalc has built-in support for hex/binary using # notation (e.g., #hFF, #b1011)
Console.WriteLine($"uCalc's built-in #hFF is: {uc.EvalStr("#hFF")}")
End Sub
End Module
0xFF is evaluated as: 255
0b1011 is evaluated as: 11
uCalc's built-in #hFF is: 255 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Define a token for C-like 0x hex notation uc.ExpressionTokens.Add("0x[0-9A-Fa-f]+", TokenType.TokenTransform) uc.TokenTransformer.FromTo("{'0x'}{Num:'[0-9A-Fa-f]+'}", "BaseConvert('{Num}', 16)") Console.WriteLine($"0xFF is evaluated as: {uc.EvalStr("0xFF")}") '// Define a token for C++-style 0b binary notation uc.ExpressionTokens.Add("0b[01]+", TokenType.TokenTransform) '// Using {@Eval} is more efficient as the conversion happens once during the token transform pass. uc.TokenTransformer.FromTo("{'0b'}{Num:'[01]+'}", "{@Eval: BaseConvert(Num, 2)}") Console.WriteLine($"0b1011 is evaluated as: {uc.EvalStr("0b1011")}") '// Note: uCalc has built-in support for hex/binary using # notation (e.g., #hFF, #b1011) Console.WriteLine($"uCalc's built-in #hFF is: {uc.EvalStr("#hFF")}") End Sub End Module
Extracting a parenthetical expression, including the parentheses.
ID: 1275
See: BetweenInclusive
using uCalcSoftware;
var uc = new uCalc();
using (var s = new uCalc.String("Calculate (10 * 5) and ignore this.")) {
// Get the text from the opening parenthesis to the closing one.
var expression = s.BetweenInclusive("(", ")");
Console.WriteLine(expression);
}
(10 * 5) using uCalcSoftware; var uc = new uCalc(); using (var s = new uCalc.String("Calculate (10 * 5) and ignore this.")) { // Get the text from the opening parenthesis to the closing one. var expression = s.BetweenInclusive("(", ")"); Console.WriteLine(expression); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::String s("Calculate (10 * 5) and ignore this.");
s.Owned(); // Causes s to be released when it goes out of scope
// Get the text from the opening parenthesis to the closing one.
auto expression = s.BetweenInclusive("(", ")");
cout << expression << endl;
}
}
(10 * 5) #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::String s("Calculate (10 * 5) and ignore this."); s.Owned(); // Causes s to be released when it goes out of scope // Get the text from the opening parenthesis to the closing one. auto expression = s.BetweenInclusive("(", ")"); cout << expression << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using s As New uCalc.String("Calculate (10 * 5) and ignore this.")
'// Get the text from the opening parenthesis to the closing one.
Dim expression = s.BetweenInclusive("(", ")")
Console.WriteLine(expression)
End Using
End Sub
End Module
(10 * 5) Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using s As New uCalc.String("Calculate (10 * 5) and ignore this.") '// Get the text from the opening parenthesis to the closing one. Dim expression = s.BetweenInclusive("(", ")") Console.WriteLine(expression) End Using End Sub End Module
Extracting a single key-value pair from a query string.
ID: 1398
using uCalcSoftware;
var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
// Define a rule to find a key-value pair
t.FromTo("{@Alphanumeric:key}={@Alphanumeric:val}", "Key: {key}, Value: {val}");
// Process a simple query string
Console.WriteLine(t.Transform("user=admin"));
}
Key: user, Value: admin using uCalcSoftware; var uc = new uCalc(); using (var t = new uCalc.Transformer()) { // Define a rule to find a key-value pair t.FromTo("{@Alphanumeric:key}={@Alphanumeric:val}", "Key: {key}, Value: {val}"); // Process a simple query string Console.WriteLine(t.Transform("user=admin")); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::Transformer t;
t.Owned(); // Causes t to be released when it goes out of scope
// Define a rule to find a key-value pair
t.FromTo("{@Alphanumeric:key}={@Alphanumeric:val}", "Key: {key}, Value: {val}");
// Process a simple query string
cout << t.Transform("user=admin") << endl;
}
}
Key: user, Value: admin #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::Transformer t; t.Owned(); // Causes t to be released when it goes out of scope // Define a rule to find a key-value pair t.FromTo("{@Alphanumeric:key}={@Alphanumeric:val}", "Key: {key}, Value: {val}"); // Process a simple query string cout << t.Transform("user=admin") << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using t As New uCalc.Transformer()
'// Define a rule to find a key-value pair
t.FromTo("{@Alphanumeric:key}={@Alphanumeric:val}", "Key: {key}, Value: {val}")
'// Process a simple query string
Console.WriteLine(t.Transform("user=admin"))
End Using
End Sub
End Module
Key: user, Value: admin Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using t As New uCalc.Transformer() '// Define a rule to find a key-value pair t.FromTo("{@Alphanumeric:key}={@Alphanumeric:val}", "Key: {key}, Value: {val}") '// Process a simple query string Console.WriteLine(t.Transform("user=admin")) End Using End Sub End Module
Extracting a value from a simple key-value pair.
ID: 1163
See: After
using uCalcSoftware;
var uc = new uCalc();
using (var s = new uCalc.String("ID: 12345")) {
// Get the text after the "ID: " prefix
var value = s.After("ID: ");
Console.WriteLine(value);
}
12345 using uCalcSoftware; var uc = new uCalc(); using (var s = new uCalc.String("ID: 12345")) { // Get the text after the "ID: " prefix var value = s.After("ID: "); Console.WriteLine(value); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::String s("ID: 12345");
s.Owned(); // Causes s to be released when it goes out of scope
// Get the text after the "ID: " prefix
auto value = s.After("ID: ");
cout << value << endl;
}
}
12345 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::String s("ID: 12345"); s.Owned(); // Causes s to be released when it goes out of scope // Get the text after the "ID: " prefix auto value = s.After("ID: "); cout << value << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using s As New uCalc.String("ID: 12345")
'// Get the text after the "ID: " prefix
Dim value = s.After("ID: ")
Console.WriteLine(value)
End Using
End Sub
End Module
12345 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using s As New uCalc.String("ID: 12345") '// Get the text after the "ID: " prefix Dim value = s.After("ID: ") Console.WriteLine(value) End Using End Sub End Module
Extracting keys from a key-value list where keys must be identifiers.
ID: 250
See: {@Alphanumeric}, Introduction
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// Capture the alphanumeric key and any literal value
t.FromTo("{@Alpha:key} = {@Literal:val}", "KEY:[{key}] VAL:[{val}]");
var input = "Timeout = 100; User = 'Admin'";
Console.WriteLine(t.Transform(input));
KEY:[Timeout] VAL:[100]; KEY:[User] VAL:['Admin'] using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // Capture the alphanumeric key and any literal value t.FromTo("{@Alpha:key} = {@Literal:val}", "KEY:[{key}] VAL:[{val}]"); var input = "Timeout = 100; User = 'Admin'"; Console.WriteLine(t.Transform(input));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// Capture the alphanumeric key and any literal value
t.FromTo("{@Alpha:key} = {@Literal:val}", "KEY:[{key}] VAL:[{val}]");
auto input = "Timeout = 100; User = 'Admin'";
cout << t.Transform(input) << endl;
}
KEY:[Timeout] VAL:[100]; KEY:[User] VAL:['Admin'] #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // Capture the alphanumeric key and any literal value t.FromTo("{@Alpha:key} = {@Literal:val}", "KEY:[{key}] VAL:[{val}]"); auto input = "Timeout = 100; User = 'Admin'"; cout << t.Transform(input) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// Capture the alphanumeric key and any literal value
t.FromTo("{@Alpha:key} = {@Literal:val}", "KEY:[{key}] VAL:[{val}]")
Dim input = "Timeout = 100; User = 'Admin'"
Console.WriteLine(t.Transform(input))
End Sub
End Module
KEY:[Timeout] VAL:[100]; KEY:[User] VAL:['Admin'] Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// Capture the alphanumeric key and any literal value t.FromTo("{@Alpha:key} = {@Literal:val}", "KEY:[{key}] VAL:[{val}]") Dim input = "Timeout = 100; User = 'Admin'" Console.WriteLine(t.Transform(input)) End Sub End Module