#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // 1. Define the lexical rule. // The regex matches '0x' followed by hex digits. // The TokenType::TokenTransform tells the parser to pre-process this token. uc.ExpressionTokens().Add("0x[0-9a-fA-F]+", TokenType::TokenTransform); // 2. Define the transformation rule. // This captures the hex digits and replaces the whole token with a call to BaseConvert. uc.TokenTransformer().FromTo("{'0x'}{val:'[0-9a-fA-F]+'}", "BaseConvert('{val}', 16)"); // 3. Now, the new literal format can be used in expressions. cout << uc.Eval("0xFF + 0xA") << endl; // 255 + 10 cout << uc.EvalStr("Hex(0x100)") << endl; // Hex(256) }