#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // (See alternate version of this example using ExpressionTokens instead of ItemOf) // 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.ItemOf("_Token_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.ItemOf("_Token_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 // Also: We can't use the commented line below because it has the underscore, _, // character that we had removed. // uc.ItemOf("_token_alphanumeric").Regex("[a-zA-Z_][a-zA-Z0-9_]*"); uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex("[a-zA-Z_][a-zA-Z0-9_]*"); cout << uc.EvalStr("My_Variable") << endl; cout << uc.EvalStr("Variable123") << endl; }