uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
ExpressionTokens = [Tokens]
Property
Product:
Class:
Retrieves the token definition collection used by the expression parser, allowing for inspection and customization.
Remarks
The ExpressionTokens() property is your gateway to uCalc's lexical analysis engine. It returns the Tokens object that defines how input strings are broken down into fundamental units (tokens) before being parsed.
🏷️ What Are Tokens?
Before uCalc can evaluate an expression like My_Var + 10, it must first break it down into meaningful pieces called tokens. For that expression, the tokenizer would produce:
My_Var- AnAlphaNumerictoken (an identifier).+- AReducibletoken (an operator symbol).10- ALiteraltoken (a number).
This method gives you direct access to the regular expressions (regex) that define these token types.
🛠️ Why Customize Tokens?
Modifying the default token set allows you to extend uCalc's syntax to support new language constructs. Common use cases include:
- New Number Formats: Add support for C-style hexadecimal (
0x...) or binary (0b...) literals. - Custom Identifiers: Change the rules for variable and function names, for example, to allow characters like
$or#. - Domain-Specific Literals: Define tokens for concepts unique to your application, such as date formats (
dd-mm-yyyy) or version strings (v1.2.3). - New Comment Styles: Implement single-line (
//...) or multi-line (/*...*/) comments.
See the Tokens class for all available methods to Add, Remove, or Modify token definitions.
Comparative Analysis: Why uCalc?
vs. Manual String Parsing/Regex: Manually parsing input with string functions and regular expressions is complex and error-prone. Standard regex struggles with nested structures (like parentheses) and context (distinguishing unary minus from subtraction). uCalc's tokenizer is structured, context-aware, and handles these challenges automatically.
vs. Lexer Generators (e.g., ANTLR, Lex/Flex): Traditional compiler tools are extremely powerful but require an external toolchain, a separate definition language (like
.g4files), and a code generation/build step. This process is static. uCalc's key advantage is that its token engine is fully dynamic and programmatic. You can add, remove, or modify token definitions at runtime, from within your code, without any external tools or recompilation. This provides unparalleled flexibility for creating adaptable and user-extendable DSLs.
Examples
Quick Start: Inspects the regex pattern for a single, common token type (alphanumeric identifiers).
using uCalcSoftware;
var uc = new uCalc();
var tokens = uc.ExpressionTokens;
var alphanumericToken = tokens[TokenType.AlphaNumeric];
Console.WriteLine("The regex for alphanumeric tokens is:");
Console.WriteLine(alphanumericToken.Regex);
The regex for alphanumeric tokens is:
[a-zA-Z_][a-zA-Z0-9_]* using uCalcSoftware; var uc = new uCalc(); var tokens = uc.ExpressionTokens; var alphanumericToken = tokens[TokenType.AlphaNumeric]; Console.WriteLine("The regex for alphanumeric tokens is:"); Console.WriteLine(alphanumericToken.Regex);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto tokens = uc.ExpressionTokens();
auto alphanumericToken = tokens[TokenType::AlphaNumeric];
cout << "The regex for alphanumeric tokens is:" << endl;
cout << alphanumericToken.Regex() << endl;
}
The regex for alphanumeric tokens is:
[a-zA-Z_][a-zA-Z0-9_]* #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto tokens = uc.ExpressionTokens(); auto alphanumericToken = tokens[TokenType::AlphaNumeric]; cout << "The regex for alphanumeric tokens is:" << endl; cout << alphanumericToken.Regex() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim tokens = uc.ExpressionTokens
Dim alphanumericToken = tokens(TokenType.AlphaNumeric)
Console.WriteLine("The regex for alphanumeric tokens is:")
Console.WriteLine(alphanumericToken.Regex)
End Sub
End Module
The regex for alphanumeric tokens is:
[a-zA-Z_][a-zA-Z0-9_]* Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim tokens = uc.ExpressionTokens Dim alphanumericToken = tokens(TokenType.AlphaNumeric) Console.WriteLine("The regex for alphanumeric tokens is:") Console.WriteLine(alphanumericToken.Regex) End Sub End Module
Extends the parser to support C-style `0x` hex and `0b` binary notations using a token 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
Displays the complete list of default token definitions, showing their type, internal name, and regex pattern.
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
Token(TokenType)
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Name);
Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Regex);
Console.WriteLine("");
// Note: In C# or VB you can simply use [TokenType::Literal, n]
// instead of ByType(TokenType::Literal, n)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name);
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name);
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name);
_token_alphanumeric
[a-zA-Z_][a-zA-Z0-9_]*
_token_string_singlequoted
_token_string_doublequoted
_token_string_tripledoublequoted using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Name); Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Regex); Console.WriteLine(""); // Note: In C# or VB you can simply use [TokenType::Literal, n] // instead of ByType(TokenType::Literal, n) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name); Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name); Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Name() << endl;
cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex() << endl;
cout << "" << endl;
// Note: In C# or VB you can simply use [TokenType::Literal, n]
// instead of ByType(TokenType::Literal, n)
cout << uc.ExpressionTokens().ByType(TokenType::Literal, 0).Name() << endl;
cout << uc.ExpressionTokens().ByType(TokenType::Literal, 1).Name() << endl;
cout << uc.ExpressionTokens().ByType(TokenType::Literal, 2).Name() << endl;
}
_token_alphanumeric
[a-zA-Z_][a-zA-Z0-9_]*
_token_string_singlequoted
_token_string_doublequoted
_token_string_tripledoublequoted #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Name() << endl; cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex() << endl; cout << "" << endl; // Note: In C# or VB you can simply use [TokenType::Literal, n] // instead of ByType(TokenType::Literal, n) cout << uc.ExpressionTokens().ByType(TokenType::Literal, 0).Name() << endl; cout << uc.ExpressionTokens().ByType(TokenType::Literal, 1).Name() << endl; cout << uc.ExpressionTokens().ByType(TokenType::Literal, 2).Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Name)
Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Regex)
Console.WriteLine("")
'// Note: In C# or VB you can simply use [TokenType::Literal, n]
'// instead of ByType(TokenType::Literal, n)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name)
End Sub
End Module
_token_alphanumeric
[a-zA-Z_][a-zA-Z0-9_]*
_token_string_singlequoted
_token_string_doublequoted
_token_string_tripledoublequoted Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Name) Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Regex) Console.WriteLine("") '// Note: In C# or VB you can simply use [TokenType::Literal, n] '// instead of ByType(TokenType::Literal, n) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name) End Sub End Module
Change characters accepted as alphanumeric in expressions using ExpressionTokens() & Token()
using uCalcSoftware;
var uc = new uCalc();
// (See alternate version of this example using ItemOf instead of ExpressionTokens)
// In this section underscore, _, and numeric digits
// are accepted as part of alphanumeric tokens
uc.DefineVariable("My_Variable = 111");
Console.WriteLine(uc.Error.Message);
uc.DefineVariable("Variable123 = 222");
Console.WriteLine(uc.Error.Message);
Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Regex);
Console.WriteLine(uc.EvalStr("My_Variable"));
Console.WriteLine(uc.EvalStr("Variable123"));
Console.WriteLine("---");
// Now we no longer want underscore, _, or numeric digits
// to be accepted in alphanumeric tokens; only A-Z
uc.ExpressionTokens[TokenType.AlphaNumeric].Regex = "[a-zA-Z]+";
uc.DefineVariable("Other_Variable = 333");
Console.WriteLine(uc.Error.Message);
uc.DefineVariable("OtherVariable123 = 444");
Console.WriteLine(uc.Error.Message);
Console.WriteLine(uc.EvalStr("Other_Variable"));
Console.WriteLine(uc.EvalStr("OtherVariable123 "));
Console.WriteLine(uc.EvalStr("My_Variable"));
Console.WriteLine(uc.EvalStr("Variable123"));
Console.WriteLine("---");
// We restore the alphanumeric regex to support _ and numbers again
// Note: My_Variable and Variable123 remained; they were simply inaccessible
uc.ExpressionTokens[TokenType.AlphaNumeric].Regex = "[a-zA-Z_][a-zA-Z0-9_]*";
Console.WriteLine(uc.EvalStr("My_Variable"));
Console.WriteLine(uc.EvalStr("Variable123"));
No error
No error
[a-zA-Z_][a-zA-Z0-9_]*
111
222
---
Invalid definition
Invalid definition
Undefined identifier
Undefined identifier
Undefined identifier
Undefined identifier
---
111
222 using uCalcSoftware; var uc = new uCalc(); // (See alternate version of this example using ItemOf instead of ExpressionTokens) // In this section underscore, _, and numeric digits // are accepted as part of alphanumeric tokens uc.DefineVariable("My_Variable = 111"); Console.WriteLine(uc.Error.Message); uc.DefineVariable("Variable123 = 222"); Console.WriteLine(uc.Error.Message); Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Regex); Console.WriteLine(uc.EvalStr("My_Variable")); Console.WriteLine(uc.EvalStr("Variable123")); Console.WriteLine("---"); // Now we no longer want underscore, _, or numeric digits // to be accepted in alphanumeric tokens; only A-Z uc.ExpressionTokens[TokenType.AlphaNumeric].Regex = "[a-zA-Z]+"; uc.DefineVariable("Other_Variable = 333"); Console.WriteLine(uc.Error.Message); uc.DefineVariable("OtherVariable123 = 444"); Console.WriteLine(uc.Error.Message); Console.WriteLine(uc.EvalStr("Other_Variable")); Console.WriteLine(uc.EvalStr("OtherVariable123 ")); Console.WriteLine(uc.EvalStr("My_Variable")); Console.WriteLine(uc.EvalStr("Variable123")); Console.WriteLine("---"); // We restore the alphanumeric regex to support _ and numbers again // Note: My_Variable and Variable123 remained; they were simply inaccessible uc.ExpressionTokens[TokenType.AlphaNumeric].Regex = "[a-zA-Z_][a-zA-Z0-9_]*"; Console.WriteLine(uc.EvalStr("My_Variable")); Console.WriteLine(uc.EvalStr("Variable123"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// (See alternate version of this example using ItemOf instead of ExpressionTokens)
// In this section underscore, _, and numeric digits
// are accepted as part of alphanumeric tokens
uc.DefineVariable("My_Variable = 111");
cout << uc.Error().Message() << endl;
uc.DefineVariable("Variable123 = 222");
cout << uc.Error().Message() << endl;
cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex() << endl;
cout << uc.EvalStr("My_Variable") << endl;
cout << uc.EvalStr("Variable123") << endl;
cout << "---" << endl;
// Now we no longer want underscore, _, or numeric digits
// to be accepted in alphanumeric tokens; only A-Z
uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex("[a-zA-Z]+");
uc.DefineVariable("Other_Variable = 333");
cout << uc.Error().Message() << endl;
uc.DefineVariable("OtherVariable123 = 444");
cout << uc.Error().Message() << endl;
cout << uc.EvalStr("Other_Variable") << endl;
cout << uc.EvalStr("OtherVariable123 ") << endl;
cout << uc.EvalStr("My_Variable") << endl;
cout << uc.EvalStr("Variable123") << endl;
cout << "---" << endl;
// We restore the alphanumeric regex to support _ and numbers again
// Note: My_Variable and Variable123 remained; they were simply inaccessible
uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex("[a-zA-Z_][a-zA-Z0-9_]*");
cout << uc.EvalStr("My_Variable") << endl;
cout << uc.EvalStr("Variable123") << endl;
}
No error
No error
[a-zA-Z_][a-zA-Z0-9_]*
111
222
---
Invalid definition
Invalid definition
Undefined identifier
Undefined identifier
Undefined identifier
Undefined identifier
---
111
222 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // (See alternate version of this example using ItemOf instead of ExpressionTokens) // In this section underscore, _, and numeric digits // are accepted as part of alphanumeric tokens uc.DefineVariable("My_Variable = 111"); cout << uc.Error().Message() << endl; uc.DefineVariable("Variable123 = 222"); cout << uc.Error().Message() << endl; cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex() << endl; cout << uc.EvalStr("My_Variable") << endl; cout << uc.EvalStr("Variable123") << endl; cout << "---" << endl; // Now we no longer want underscore, _, or numeric digits // to be accepted in alphanumeric tokens; only A-Z uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex("[a-zA-Z]+"); uc.DefineVariable("Other_Variable = 333"); cout << uc.Error().Message() << endl; uc.DefineVariable("OtherVariable123 = 444"); cout << uc.Error().Message() << endl; cout << uc.EvalStr("Other_Variable") << endl; cout << uc.EvalStr("OtherVariable123 ") << endl; cout << uc.EvalStr("My_Variable") << endl; cout << uc.EvalStr("Variable123") << endl; cout << "---" << endl; // We restore the alphanumeric regex to support _ and numbers again // Note: My_Variable and Variable123 remained; they were simply inaccessible uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex("[a-zA-Z_][a-zA-Z0-9_]*"); cout << uc.EvalStr("My_Variable") << endl; cout << uc.EvalStr("Variable123") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// (See alternate version of this example using ItemOf instead of ExpressionTokens)
'// In this section underscore, _, and numeric digits
'// are accepted as part of alphanumeric tokens
uc.DefineVariable("My_Variable = 111")
Console.WriteLine(uc.Error.Message)
uc.DefineVariable("Variable123 = 222")
Console.WriteLine(uc.Error.Message)
Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Regex)
Console.WriteLine(uc.EvalStr("My_Variable"))
Console.WriteLine(uc.EvalStr("Variable123"))
Console.WriteLine("---")
'// Now we no longer want underscore, _, or numeric digits
'// to be accepted in alphanumeric tokens; only A-Z
uc.ExpressionTokens(TokenType.AlphaNumeric).Regex = "[a-zA-Z]+"
uc.DefineVariable("Other_Variable = 333")
Console.WriteLine(uc.Error.Message)
uc.DefineVariable("OtherVariable123 = 444")
Console.WriteLine(uc.Error.Message)
Console.WriteLine(uc.EvalStr("Other_Variable"))
Console.WriteLine(uc.EvalStr("OtherVariable123 "))
Console.WriteLine(uc.EvalStr("My_Variable"))
Console.WriteLine(uc.EvalStr("Variable123"))
Console.WriteLine("---")
'// We restore the alphanumeric regex to support _ and numbers again
'// Note: My_Variable and Variable123 remained; they were simply inaccessible
uc.ExpressionTokens(TokenType.AlphaNumeric).Regex = "[a-zA-Z_][a-zA-Z0-9_]*"
Console.WriteLine(uc.EvalStr("My_Variable"))
Console.WriteLine(uc.EvalStr("Variable123"))
End Sub
End Module
No error
No error
[a-zA-Z_][a-zA-Z0-9_]*
111
222
---
Invalid definition
Invalid definition
Undefined identifier
Undefined identifier
Undefined identifier
Undefined identifier
---
111
222 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// (See alternate version of this example using ItemOf instead of ExpressionTokens) '// In this section underscore, _, and numeric digits '// are accepted as part of alphanumeric tokens uc.DefineVariable("My_Variable = 111") Console.WriteLine(uc.Error.Message) uc.DefineVariable("Variable123 = 222") Console.WriteLine(uc.Error.Message) Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Regex) Console.WriteLine(uc.EvalStr("My_Variable")) Console.WriteLine(uc.EvalStr("Variable123")) Console.WriteLine("---") '// Now we no longer want underscore, _, or numeric digits '// to be accepted in alphanumeric tokens; only A-Z uc.ExpressionTokens(TokenType.AlphaNumeric).Regex = "[a-zA-Z]+" uc.DefineVariable("Other_Variable = 333") Console.WriteLine(uc.Error.Message) uc.DefineVariable("OtherVariable123 = 444") Console.WriteLine(uc.Error.Message) Console.WriteLine(uc.EvalStr("Other_Variable")) Console.WriteLine(uc.EvalStr("OtherVariable123 ")) Console.WriteLine(uc.EvalStr("My_Variable")) Console.WriteLine(uc.EvalStr("Variable123")) Console.WriteLine("---") '// We restore the alphanumeric regex to support _ and numbers again '// Note: My_Variable and Variable123 remained; they were simply inaccessible uc.ExpressionTokens(TokenType.AlphaNumeric).Regex = "[a-zA-Z_][a-zA-Z0-9_]*" Console.WriteLine(uc.EvalStr("My_Variable")) Console.WriteLine(uc.EvalStr("Variable123")) End Sub End Module