# Rosetta Stone: uCalc Pseudocode Translation Rules

Use the following explicit rules and examples to translate the uCalc documentation pseudocode into C++, C#, and VB, or to generate a pseudocode example when requested.

## 1. Syntax Tags

* **[verbatim]...[/verbatim] (Raw string literals)**
Do NOT use escapes such as `\n`, `\"` or `""` in a string.  Instead, raw strings spanning multiple lines, or which include double quotes should be wrapped within `verbatim` tags.
  * C#: `"""..."""`
  * C++: `R"(...)";`
  * VB: `"..."` (`"` within raw text is rendered as `""` when translated to VB)

* Use the following tags in the pseudocode to conditionally include or exclude lines based on the target language. These tags are case-insensitive.
  * `[cpp]...[/cpp]` : Render only in C++
  * `[cs]...[/cs]` : Render only in C#
  * `[vb]...[/vb]` : Render only in VB
  * `[NotCpp]...[/NotCpp]` : Render in C# and VB, but not C++
  * `[c]...[/c]` : Same as `[NotVb]`. Render in C++ and C# only.

## 2. Print Commands
* **`w(arg1, arg2...)` (Write):**
  * C#: `Console.Write(arg1 + arg2...);`
  * C++: `cout << arg1 << arg2...;`
  * VB: `Console.Write(arg1 & arg2...)`
* **`wl(arg1, arg2...)` (Write Line):**
  * C#: `Console.WriteLine(arg1 + arg2...);`
  * C++: `cout << arg1 << arg2... << endl;`
  * VB: `Console.WriteLine(arg1 & arg2...)`

## 3. Variable Declaration
* **`var name = value;` (non-uCalc types like `int`, `double`, `string`)**
  * C#: `var name = value;`
  * C++: `auto name = value;`
  * VB: `Dim name = value`
* **`var(uCalc::Type, name)` (uCalc types)**
  * C#: `uCalc.Type name;`
  * C++: `uCalc::Type name;`
  * VB: `Dim name As uCalc.Type`
* **`New(uCalc::Type, name(arg1, arg2...))` (uCalc types with arguments passed for the constructor)**
  * C#: `var name = new uCalc.Type(arg1, arg2...);`
  * C++: `uCalc::Type name(arg1, arg2...);`
  * VB: `Dim name As New uCalc.Type(arg1, arg2...)`
* **RAII (Defining uCalc variables that are auto-released when they go out of scope)**
```
NewUsing(uCalc::Type, name)
...
End Using
```
C#:
```
using (var name = new uCalc.Type()) {
...
}
```
C++:
```
{
   uCalc::Type name;
   name.Owned();
   ...
}
```
VB:
```
Using name As New uCalc.Type()
...
End Using
```

## 4. Arrays & Collections
When declaring arrays, accessing elements, or getting the length, the pseudocode maps to std::vector in C++ and standard arrays in C#/VB.

* **Declaration:** `var(type[], name) = {val1, val2};`
  * C++: `vector<type> name = {val1, val2};`
  * C#: `type[] name = {val1, val2}; (or var name = new[] {val1, val2};)`
  * VB: `Dim name() As type = {val1, val2}`
* **Element Access:** `name[index]`
  * C# / C++: `name[index]`
  * VB: `name(index)` (Note: VB uses parentheses instead of brackets)
* **Array Size:** `name.size()`
  * C++: `name.size()`
  * C# / VB: `name.Length`

## 5. Properties
* **`val = t.@Text();` (Getter):**
  * C#: `val = t.Text;`
  * C++: `val = t.Text();`
  * VB: `val t.Text`
* **`t.@Text("Hello");` (Setter):**
  * C#: `t.Text = "Hello";`
  * C++: `t.Text("Hello");`
  * VB: `t.Text = "Hello"`

In all 3 languages, Getters have an alternative notation as a function, using the `Get` prefix.

`t.@Text()` ==> `t.GetText()`

In all 3 languages, Setters have an alternative notation as a function, using the `Set` prefix.  This is particularly useful when chaining.

`t.@Description("abc"); t.@Text("xyz");` ==> `t.SetDescription("abc").SetText("xyz");`

## 6. Callbacks
* **uCalc Callbacks for function/operator definitions:**
  * C#: `static void MyFunc(uCalc.Callback cb) { ... }`
  * C++: `void ucalc_call MyFunc(uCalcBase::Callback cb) { ... }` (`ucalc_call` resolves to `__stdcall` when compiling for Windows x86, but is ignored otherwise)
  * VB: `Public Sub MyFunc(ByVal cb As uCalc.Callback) ... End Sub`
* **uCalc Callbacks for error handlers:**
  * C#: `static void MyErrorHandler(Handle_uCalc h) { ... }`
  * C++: `void ucalc_call MyErrorHandler(Handle_uCalc h) { ... }`
  * VB: `Public Sub MyErrorHandler(ByVal h As Handle_uCalc) ... End Sub`
* **Passing Callbacks as Arguments:**
  * When passing a defined callback function to a method (such as `DefineFunction` or `AddHandler`), Visual Basic requires the `AddressOf` operator.
  * C# / C++: `uc.DefineFunction("Area(x, y)", MyArea);`
  * VB: `uc.DefineFunction("Area(x, y)", AddressOf MyArea)`

## 7. Misc

* **`to_string(...)` (Convert numeric value to string):**
  * C++: `to_string(...)`
  * C#/VB: `(...).ToString()`

* Always use `::` as a scope resolution operator.  This remains the same in C++ code, but is translated to `.` in C#/VB.  The pseudocode translator is not capable of translating `.` to `::` for C++.

* When translated to VB, semicolon statement separators `;` found in the pseudocode are removed, and square brackets are changed to parentheses.

---

## Examples

### Example 1
Translation of pseudocode to C++, C#, and VB for Gemini prompt

**Pseudocode**

```pseudocode
// Rosetta Stone
// Pseudocode translation to C++, C#, or VB
[cpp]// This shows only in C++[/cpp]
[cs]// This shows only in C#[/cs]
[vb]// This shows only in vb[/vb]
[NotCpp]//This shows in C# and VB, not C++[/NotCpp]
[NotCs]//This shows in C++ and VB, not C#[/NotCs]
[NotVb]//This shows in C++ and C#, not Vb[/NotVb]
[c]//The c tag is the same as the NotVB tag[/c]
// Tags (c, cpp, cs, vb, NotCpp, NotCs, NotVb, etc.,) are not case-sensitive

w("w() prints text without ")
w("a new line at the end.")
wl() // Moves to a new line
wl("wl() prints a line, ending with a newline.")
wl("Line 2")
wl("Line 3")
wl(123, " multiple args ", "for wl()")
w("multiple ", "args ", "for w() too")
wl("")

var t = uc.NewTransformer();
// Property setter syntax: @ followed by property name and value in parenthesis
t.@Description("Some description goes here");

// Property getter sytanx: @ followed by property name, and empty parenthesis
wl(t.@Description())

// Each property has an alternative getter and setter function syntax
// with the Get or Set prefix like this:
t.SetDescription("A new description");
wl(t.GetDescription())

// Using the alternative function syntax for a property can be useful when chaining calls
// I use the c tag for the sake of VB that wants everything on the same line.
t.SetText("Some Text").SetDescription("Some description")[c]
 [/c].FromTo("Text", "String").SetCaseSensitive(true).SetMinimum(1).SetMaximum(5)[c]
 [/c].GetParentTransformer().Transform();
wl(t.@Text())

// For compatibility across C++, C#, and VB, use the Verbatim tag for multi-line
// strings.  Do not use escapes or specialized double-quote syntax in a string.
var MyString = [Verbatim]Here is some "quoted" text on one line
And some random text on another line[/Verbatim];
wl(MyString)

// Use this syntax to define a variable with a uCalc-related type
// Either with or without an initial value
var(uCalc::String, MyStringA)
var(uCalc::String, MyStringB) = "This is some text.";
MyStringA = MyStringB.@Text() + " Some more text";
wl(MyStringA.@Text())

// For simple types not belonging to uCalc, use this C#-like notation instead:

var OtherString = "Some other string ";
var MyNumber = 12345;
wl(OtherString, MyNumber)

// Another way to define a new variable (with a uCalc type) is with the more
// flexible New.  Use this especially if you need to use arguments:

New(uCalc::Item, MyVar("Variable: x = 123"))
New(uCalc::Item, MyFunc(uc, "Function: f(x) = x^2"))
wl(uCalc::@DefaultInstance().Eval("x"))
wl(uc.Eval("f(5)"))

// To define a uCalc object that gets released when the object goes out of scope, do:
NewUsing(uCalc::Transformer, tr)
tr.FromTo("This", "That");
wl(tr.Transform("This car").@Text())
// To accomodate other languages besides C#, you must explicitely end the using block
End Using

// Use the C++ style to_string to convert a value to a string
wl("Value: " + to_string(100 + 25))

// Always use the C++ double colon, ::, for scope resolution
// (it gets translated to a dot, ., in C# and VB
var MyTokens = t.@Tokens();
wl(uc.DataTypeOf(BuiltInType::Float_Double).@Name())

// Other supported constructs
for(double x = 1 to 10)
   wl(x)
end for

for(double x = 1 to 10, 2)
   wl(x)
end for

foreach(var dType in uc.@DataTypes())
   wl(dType.@Name())
end foreach

var count = 0;

while(count <= 5)
  wl(count)
  count += 1;
end while

do
   wl(count)
   count = count + 1;
loop while (count <= 10)

if (count < 100)
  wl("count is less than 100")
end if

if (count < 5)
  // Some lines of code
  wl("count is less than 5")
else if (count <= 50)
  // . . .
  wl("count is less than or equal to 50")
else
  // More lines of code
  wl("count is greater than 50")
end if

// Declare and initialize a string array
var(string[], items) = {"Apple", "Banana", "Cherry"};

// Get the size of the array
count = items.size();
wl("Total items: ", count)

// Access and modify elements
wl("First item: ", items[0])
items[1] = "Blueberry";

// Iterate through the array
var i = 0;
do
   wl(items[i])
   i = i + 1;
loop while (i < items.size())

// For proper translation into the 3 supported languages, wrap Boolean values with
// bool.  When pseudocode contains the bool function, a helper function named tf is
// inserted towards to the top of the code

wl(uc.EvalStr("'Cos is a function? '"), bool(uc.ItemOf("Cos").IsProperty(ItemIs::Function)))
wl(uc.EvalStr("'Cos is a variable? '"), bool(uc.ItemOf("Cos").IsProperty(ItemIs::Variable)))
```


**C++**

```cpp
#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

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

int main() {
   uCalc uc;
   // Rosetta Stone
   // Pseudocode translation to C++, C#, or VB
   // This shows only in C++



   //This shows in C++ and VB, not C#
   //This shows in C++ and C#, not Vb
   //The c tag is the same as the NotVB tag
   // Tags (c, cpp, cs, vb, NotCpp, NotCs, NotVb, etc.,) are not case-sensitive

   cout << "w() prints text without ";
   cout << "a new line at the end.";
   cout << endl; // Moves to a new line
   cout << "wl() prints a line, ending with a newline." << endl;
   cout << "Line 2" << endl;
   cout << "Line 3" << endl;
   cout << 123 << " multiple args " << "for wl()" << endl;
   cout << "multiple " << "args " << "for w() too";
   cout << "" << endl;

   auto t = uc.NewTransformer();
   // Property setter syntax: @ followed by property name and value in parenthesis
   t.Description("Some description goes here");

   // Property getter sytanx: @ followed by property name, and empty parenthesis
   cout << t.Description() << endl;

   // Each property has an alternative getter and setter function syntax
   // with the Get or Set prefix like this:
   t.SetDescription("A new description");
   cout << t.GetDescription() << endl;

   // Using the alternative function syntax for a property can be useful when chaining calls
   // I use the c tag for the sake of VB that wants everything on the same line.
   t.SetText("Some Text").SetDescription("Some description")
   .FromTo("Text", "String").SetCaseSensitive(true).SetMinimum(1).SetMaximum(5)
   .GetParentTransformer().Transform();
   cout << t.Text() << endl;

   // For compatibility across C++, C#, and VB, use the Verbatim tag for multi-line
   // strings.  Do not use escapes or specialized double-quote syntax in a string.
   auto MyString = R"(Here is some "quoted" text on one line
And some random text on another line)";
   cout << MyString << endl;

   // Use this syntax to define a variable with a uCalc-related type
   // Either with or without an initial value
   uCalc::String MyStringA;
   uCalc::String MyStringB = "This is some text.";
   MyStringA = MyStringB.Text() + " Some more text";
   cout << MyStringA.Text() << endl;

   // For simple types not belonging to uCalc, use this C#-like notation instead:

   auto OtherString = "Some other string ";
   auto MyNumber = 12345;
   cout << OtherString << MyNumber << endl;

   // Another way to define a new variable (with a uCalc type) is with the more
   // flexible New.  Use this especially if you need to use arguments:

   uCalc::Item MyVar("Variable: x = 123");
   uCalc::Item MyFunc(uc, "Function: f(x) = x^2");
   cout << uCalc::DefaultInstance().Eval("x") << endl;
   cout << uc.Eval("f(5)") << endl;

   // To define a uCalc object that gets released when the object goes out of scope, do:
   {
      uCalc::Transformer tr;
      tr.Owned(); // Causes tr to be released when it goes out of scope
      tr.FromTo("This", "That");
      cout << tr.Transform("This car").Text() << endl;
      // To accomodate other languages besides C#, you must explicitely end the using block
   }

   // Use the C++ style to_string to convert a value to a string
   cout << "Value: " + to_string(100 + 25) << endl;

   // Always use the C++ double colon, ::, for scope resolution
   // (it gets translated to a dot, ., in C# and VB
   auto MyTokens = t.Tokens();
   cout << uc.DataTypeOf(BuiltInType::Float_Double).Name() << endl;

   // Other supported constructs
   for (double x = 1; x <= 10; x++) {
      cout << x << endl;
   }

   for (double x = 1; x <= 10; x = x + 2) {
      cout << x << endl;
   }

   for(auto dType : uc.DataTypes()) {
      cout << dType.Name() << endl;
   }

   auto count = 0;

   while (count <= 5) {
      cout << count << endl;
      count += 1;
   }

   do {
      cout << count << endl;
      count = count + 1;
   } while (count <= 10);

   if (count < 100) {
      cout << "count is less than 100" << endl;
   }

   if (count < 5) {
      // Some lines of code
      cout << "count is less than 5" << endl;
   } else if (count <= 50) {
      // . . .
      cout << "count is less than or equal to 50" << endl;
   } else {
      // More lines of code
      cout << "count is greater than 50" << endl;
   }

   // Declare and initialize a string array
   vector<string> items = {"Apple", "Banana", "Cherry"};

   // Get the size of the array
   count = items.size();
   cout << "Total items: " << count << endl;

   // Access and modify elements
   cout << "First item: " << items[0] << endl;
   items[1] = "Blueberry";

   // Iterate through the array
   auto i = 0;
   do {
      cout << items[i] << endl;
      i = i + 1;
   } while (i < items.size());

   // For proper translation into the 3 supported languages, wrap Boolean values with
   // bool.  When pseudocode contains the bool function, a helper function named tf is
   // inserted towards to the top of the code

   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;
}
```


**C#**

```csharp
using uCalcSoftware;

var uc = new uCalc();
// Rosetta Stone
// Pseudocode translation to C++, C#, or VB

// This shows only in C#

//This shows in C# and VB, not C++

//This shows in C++ and C#, not Vb
//The c tag is the same as the NotVB tag
// Tags (c, cpp, cs, vb, NotCpp, NotCs, NotVb, etc.,) are not case-sensitive

Console.Write("w() prints text without ");
Console.Write("a new line at the end.");
Console.WriteLine(); // Moves to a new line
Console.WriteLine("wl() prints a line, ending with a newline.");
Console.WriteLine("Line 2");
Console.WriteLine("Line 3");
Console.WriteLine($"{123} multiple args for wl()");
Console.Write("multiple "); Console.Write("args "); Console.Write("for w() too");
Console.WriteLine("");

var t = uc.NewTransformer();
// Property setter syntax: @ followed by property name and value in parenthesis
t.Description = "Some description goes here";

// Property getter sytanx: @ followed by property name, and empty parenthesis
Console.WriteLine(t.Description);

// Each property has an alternative getter and setter function syntax
// with the Get or Set prefix like this:
t.SetDescription("A new description");
Console.WriteLine(t.GetDescription());

// Using the alternative function syntax for a property can be useful when chaining calls
// I use the c tag for the sake of VB that wants everything on the same line.
t.SetText("Some Text").SetDescription("Some description")
.FromTo("Text", "String").SetCaseSensitive(true).SetMinimum(1).SetMaximum(5)
.GetParentTransformer().Transform();
Console.WriteLine(t.Text);

// For compatibility across C++, C#, and VB, use the Verbatim tag for multi-line
// strings.  Do not use escapes or specialized double-quote syntax in a string.
var MyString = """
Here is some "quoted" text on one line
And some random text on another line
""";
Console.WriteLine(MyString);

// Use this syntax to define a variable with a uCalc-related type
// Either with or without an initial value
uCalc.String MyStringA;
uCalc.String MyStringB = "This is some text.";
MyStringA = MyStringB.Text + " Some more text";
Console.WriteLine(MyStringA.Text);

// For simple types not belonging to uCalc, use this C#-like notation instead:

var OtherString = "Some other string ";
var MyNumber = 12345;
Console.WriteLine($"{OtherString}{MyNumber}");

// Another way to define a new variable (with a uCalc type) is with the more
// flexible New.  Use this especially if you need to use arguments:

var MyVar = new uCalc.Item("Variable: x = 123");
var MyFunc = new uCalc.Item(uc, "Function: f(x) = x^2");
Console.WriteLine(uCalc.DefaultInstance.Eval("x"));
Console.WriteLine(uc.Eval("f(5)"));

// To define a uCalc object that gets released when the object goes out of scope, do:
using (var tr = new uCalc.Transformer()) {
   tr.FromTo("This", "That");
   Console.WriteLine(tr.Transform("This car").Text);
   // To accomodate other languages besides C#, you must explicitely end the using block
}

// Use the C++ style to_string to convert a value to a string
Console.WriteLine("Value: " + (100 + 25).ToString());

// Always use the C++ double colon, ::, for scope resolution
// (it gets translated to a dot, ., in C# and VB
var MyTokens = t.Tokens;
Console.WriteLine(uc.DataTypeOf(BuiltInType.Float_Double).Name);

// Other supported constructs
for (double x = 1; x <= 10; x++) {
   Console.WriteLine(x);
}

for (double x = 1; x <= 10; x = x + 2) {
   Console.WriteLine(x);
}

foreach(var dType in uc.DataTypes) {
   Console.WriteLine(dType.Name);
}

var count = 0;

while (count <= 5) {
   Console.WriteLine(count);
   count += 1;
}

do {
   Console.WriteLine(count);
   count = count + 1;
} while (count <= 10);

if (count < 100) {
   Console.WriteLine("count is less than 100");
}

if (count < 5) {
   // Some lines of code
   Console.WriteLine("count is less than 5");
} else if (count <= 50) {
   // . . .
   Console.WriteLine("count is less than or equal to 50");
} else {
   // More lines of code
   Console.WriteLine("count is greater than 50");
}

// Declare and initialize a string array
string[] items = {"Apple", "Banana", "Cherry"};

// Get the size of the array
count = items.Length;
Console.WriteLine($"Total items: {count}");

// Access and modify elements
Console.WriteLine($"First item: {items[0]}");
items[1] = "Blueberry";

// Iterate through the array
var i = 0;
do {
   Console.WriteLine(items[i]);
   i = i + 1;
} while (i < items.Length);

// For proper translation into the 3 supported languages, wrap Boolean values with
// bool.  When pseudocode contains the bool function, a helper function named tf is
// inserted towards to the top of the code

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)}");
```


**VB**

```vb
Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Rosetta Stone
      '// Pseudocode translation to C++, C#, or VB
      
      
      '// This shows only in vb
      '//This shows in C# and VB, not C++
      '//This shows in C++ and VB, not C#
      
      
      '// Tags (c, cpp, cs, vb, NotCpp, NotCs, NotVb, etc.,) are not case-sensitive
      
      Console.Write("w() prints text without ")
      Console.Write("a new line at the end.")
      Console.WriteLine() '// Moves to a new line
      Console.WriteLine("wl() prints a line, ending with a newline.")
      Console.WriteLine("Line 2")
      Console.WriteLine("Line 3")
      Console.WriteLine($"{123} multiple args for wl()")
      Console.Write("multiple ")
      Console.Write("args ")
      Console.Write("for w() too")
      Console.WriteLine("")
      
      Dim t = uc.NewTransformer()
      '// Property setter syntax: @ followed by property name and value in parenthesis
      t.Description = "Some description goes here"
      
      '// Property getter sytanx: @ followed by property name, and empty parenthesis
      Console.WriteLine(t.Description)
      
      '// Each property has an alternative getter and setter function syntax
      '// with the Get or Set prefix like this:
      t.SetDescription("A new description")
      Console.WriteLine(t.GetDescription())
      
      '// Using the alternative function syntax for a property can be useful when chaining calls
      '// I use the c tag for the sake of VB that wants everything on the same line.
      t.SetText("Some Text").SetDescription("Some description").FromTo("Text", "String").SetCaseSensitive(true).SetMinimum(1).SetMaximum(5).GetParentTransformer().Transform()
      Console.WriteLine(t.Text)
      
      '// For compatibility across C++, C#, and VB, use the Verbatim tag for multi-line
      '// strings.  Do not use escapes or specialized double-quote syntax in a string.
      Dim MyString = "Here is some ""quoted"" text on one line
And some random text on another line"
      Console.WriteLine(MyString)
      
      '// Use this syntax to define a variable with a uCalc-related type
      '// Either with or without an initial value
      Dim MyStringA As uCalc.String
      Dim MyStringB As uCalc.String = "This is some text."
      MyStringA = MyStringB.Text + " Some more text"
      Console.WriteLine(MyStringA.Text)
      
      '// For simple types not belonging to uCalc, use this C#-like notation instead:
      
      Dim OtherString = "Some other string "
      Dim MyNumber = 12345
      Console.WriteLine($"{OtherString}{MyNumber}")
      
      '// Another way to define a new variable (with a uCalc type) is with the more
      '// flexible New.  Use this especially if you need to use arguments:
      
      Dim MyVar As New uCalc.Item("Variable: x = 123")
      Dim MyFunc As New uCalc.Item(uc, "Function: f(x) = x^2")
      Console.WriteLine(uCalc.DefaultInstance.Eval("x"))
      Console.WriteLine(uc.Eval("f(5)"))
      
      '// To define a uCalc object that gets released when the object goes out of scope, do:
      Using tr As New uCalc.Transformer()
         tr.FromTo("This", "That")
         Console.WriteLine(tr.Transform("This car").Text)
         '// To accomodate other languages besides C#, you must explicitely end the using block
      End Using
      
      '// Use the C++ style to_string to convert a value to a string
      Console.WriteLine("Value: " + (100 + 25).ToString())
      
      '// Always use the C++ double colon, ::, for scope resolution
      '// (it gets translated to a dot, ., in C# and VB
      Dim MyTokens = t.Tokens
      Console.WriteLine(uc.DataTypeOf(BuiltInType.Float_Double).Name)
      
      '// Other supported constructs
      For x  As Double = 1 To 10
         Console.WriteLine(x)
      Next
      
      For x  As Double = 1 To 10  Step 2
         Console.WriteLine(x)
      Next
      
      For Each dType In uc.DataTypes
         Console.WriteLine(dType.Name)
      Next
      
      Dim count = 0
      
      While count <= 5
         Console.WriteLine(count)
         count += 1
      End While
      
      Do
         Console.WriteLine(count)
         count = count + 1
      Loop While count <= 10
      
      If count < 100 Then
         Console.WriteLine("count is less than 100")
      End If
      
      If count < 5 Then
         '// Some lines of code
         Console.WriteLine("count is less than 5")
         ElseIf count <= 50 Then
         '// . . .
         Console.WriteLine("count is less than or equal to 50")
      Else
         '// More lines of code
         Console.WriteLine("count is greater than 50")
      End If
      
      '// Declare and initialize a string array
      Dim items() As String = {"Apple", "Banana", "Cherry"}
      
      '// Get the size of the array
      count = items.Length
      Console.WriteLine($"Total items: {count}")
      
      '// Access and modify elements
      Console.WriteLine($"First item: {items(0)}")
      items(1) = "Blueberry"
      
      '// Iterate through the array
      Dim i = 0
      Do
         Console.WriteLine(items(i))
         i = i + 1
      Loop While i < items.Length
      
      '// For proper translation into the 3 supported languages, wrap Boolean values with
      '// bool.  When pseudocode contains the bool function, a helper function named tf is
      '// inserted towards to the top of the code
      
      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)}")
   End Sub
End Module
```


**Output**

```
w() prints text without a new line at the end.
wl() prints a line, ending with a newline.
Line 2
Line 3
123 multiple args for wl()
multiple args for w() too
Some description goes here
A new description
Some String
Here is some "quoted" text on one line
And some random text on another line
This is some text. Some more text
Some other string 12345
123
25
That car
Value: 125
double
1
2
3
4
5
6
7
8
9
10
1
3
5
7
9
anytype
bool
bool
int8u
complex
double
single
int
int16
int16u
int
int32u
int64
int64u
int8
int8u
int
omnitype
pointer
sametypeas
single
size_t
string
void
0
1
2
3
4
5
6
7
8
9
10
count is less than 100
count is less than or equal to 50
Total items: 3
First item: Apple
Apple
Blueberry
Cherry
Cos is a function? True
Cos is a variable? False
```

---
### Example 2
How to define an error handler callback

**Pseudocode**

```pseudocode
[head]
// The head, body, callback, and callback:u tags should only be used when the code contains a callback.
// There are two types of callbacks.  callback:u is for error handling, while callback is for expression
// functions and operators.  They both close with /callback.
[callback:u MyErrorHandler]
wl("An error has occurred!")
wl("Error #: ", [c](int)uc.@Error().@Code()[/c][vb]CInt(uc.@Error().@Code())[/vb])
wl("Error Message: ", uc.@Error().@Message())
wl("Error Symbol: ", uc.@Error().@Symbol())
wl("Error Location: ", uc.@Error().@Location())
wl("Error Expression: ", uc.@Error().@Expression())
[/callback]

[body]
uc.@Error().AddHandler(MyErrorHandler);
wl(uc.EvalStr("123+"))
wl("")

uc.@Error().@TrapOnDivideByZero(true);
wl(uc.EvalStr("5/0"))
// Note: The head and body tags do NOT come in pairs. Those tags separate sections of code.
```


**C++**

```cpp
#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

// The head, body, callback, and callback:u tags should only be used when the code contains a callback.
// There are two types of callbacks.  callback:u is for error handling, while callback is for expression
// functions and operators.  They both close with /callback.
void ucalc_call MyErrorHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "An error has occurred!" << endl;
   cout << "Error #: " << (int)uc.Error().Code() << endl;
   cout << "Error Message: " << uc.Error().Message() << endl;
   cout << "Error Symbol: " << uc.Error().Symbol() << endl;
   cout << "Error Location: " << uc.Error().Location() << endl;
   cout << "Error Expression: " << uc.Error().Expression() << endl;
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(MyErrorHandler);
   cout << uc.EvalStr("123+") << endl;
   cout << "" << endl;

   uc.Error().TrapOnDivideByZero(true);
   cout << uc.EvalStr("5/0") << endl;
   // Note: The head and body tags do NOT come in pairs. Those tags separate sections of code.
}
```


**C#**

```csharp
using uCalcSoftware;

var uc = new uCalc();

// The head, body, callback, and callback:u tags should only be used when the code contains a callback.
// There are two types of callbacks.  callback:u is for error handling, while callback is for expression
// functions and operators.  They both close with /callback.
static void MyErrorHandler(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("An error has occurred!");
   Console.WriteLine($"Error #: {(int)uc.Error.Code}");
   Console.WriteLine($"Error Message: {uc.Error.Message}");
   Console.WriteLine($"Error Symbol: {uc.Error.Symbol}");
   Console.WriteLine($"Error Location: {uc.Error.Location}");
   Console.WriteLine($"Error Expression: {uc.Error.Expression}");
}


uc.Error.AddHandler(MyErrorHandler);
Console.WriteLine(uc.EvalStr("123+"));
Console.WriteLine("");

uc.Error.TrapOnDivideByZero = true;
Console.WriteLine(uc.EvalStr("5/0"));
// Note: The head and body tags do NOT come in pairs. Those tags separate sections of code.
```


**VB**

```vb
Imports System
Imports uCalcSoftware
Public Module Program
   
   '// The head, body, callback, and callback:u tags should only be used when the code contains a callback.
   '// There are two types of callbacks.  callback:u is for error handling, while callback is for expression
   '// functions and operators.  They both close with /callback.
   Public Sub MyErrorHandler(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("An error has occurred!")
      Console.WriteLine($"Error #: {CInt(uc.Error.Code)}")
      Console.WriteLine($"Error Message: {uc.Error.Message}")
      Console.WriteLine($"Error Symbol: {uc.Error.Symbol}")
      Console.WriteLine($"Error Location: {uc.Error.Location}")
      Console.WriteLine($"Error Expression: {uc.Error.Expression}")
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf MyErrorHandler)
      Console.WriteLine(uc.EvalStr("123+"))
      Console.WriteLine("")
      
      uc.Error.TrapOnDivideByZero = true
      Console.WriteLine(uc.EvalStr("5/0"))
      '// Note: The head and body tags do NOT come in pairs. Those tags separate sections of code.
   End Sub
End Module
```


**Output**

```
An error has occurred!
Error #: 257
Error Message: Syntax error
Error Symbol: +
Error Location: 3
Error Expression: 123+
Syntax error

An error has occurred!
Error #: 8
Error Message: Division by 0
Error Symbol: 
Error Location: 0
Error Expression: 
Division by 0
```

---
### Example 3
How to define a custom function using a native callback.

**Pseudocode**

```pseudocode
[head]
[callback MyArea]
// Retrieve the 1st and 2nd arguments passed to the function
var Length = cb.Arg(1); 
var Width = cb.Arg(2);

// Calculate the area and return the result to the uCalc engine.
// This logic pattern translates seamlessly across languages.
cb.Return(Length * Width); // Same as cb.ReturnDbl
[/callback]
[body]
uc.DefineFunction("Area(x, y)", MyArea);
wl(uc.Eval("Area(3, 4)"))
```


**C++**

```cpp
#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call MyArea(uCalcBase::Callback cb) {
   // Retrieve the 1st and 2nd arguments passed to the function
   auto Length = cb.Arg(1);
   auto Width = cb.Arg(2);

   // Calculate the area and return the result to the uCalc engine.
   // This logic pattern translates seamlessly across languages.
   cb.Return(Length * Width); // Same as cb.ReturnDbl
}
int main() {
   uCalc uc;
   uc.DefineFunction("Area(x, y)", MyArea);
   cout << uc.Eval("Area(3, 4)") << endl;
}
```


**C#**

```csharp
using uCalcSoftware;

var uc = new uCalc();

static void MyArea(uCalc.Callback cb) {
   // Retrieve the 1st and 2nd arguments passed to the function
   var Length = cb.Arg(1);
   var Width = cb.Arg(2);

   // Calculate the area and return the result to the uCalc engine.
   // This logic pattern translates seamlessly across languages.
   cb.Return(Length * Width); // Same as cb.ReturnDbl
}

uc.DefineFunction("Area(x, y)", MyArea);
Console.WriteLine(uc.Eval("Area(3, 4)"));
```


**VB**

```vb
Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyArea(ByVal cb As uCalc.Callback)
      '// Retrieve the 1st and 2nd arguments passed to the function
      Dim Length = cb.Arg(1)
      Dim Width = cb.Arg(2)
      
      '// Calculate the area and return the result to the uCalc engine.
      '// This logic pattern translates seamlessly across languages.
      cb.Return(Length * Width) '// Same as cb.ReturnDbl
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineFunction("Area(x, y)", AddressOf MyArea)
      Console.WriteLine(uc.Eval("Area(3, 4)"))
   End Sub
End Module
```


**Output**

```
12
```

---
