#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.ExpressionTransformer(); // Enable rewind for all subsequent rules in this transformer. t.DefaultRuleSet().SetRewindOnChange(true); // Define the recursive rules. t.FromTo("AddUp({x})", "{x}"); t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))"); t.FromTo("ArgCount({x})", "1"); t.FromTo("ArgCount({x}, {y})", "(1 + ArgCount({y}))"); // The main rule that combines the others. t.FromTo("Average({x}, {y})", "AddUp({x}, {y}) / ArgCount({x}, {y})"); auto expression = "Average(1, 2, 3, 4)"; cout << "Input: " << expression << endl; cout << "Transform: " << t.Transform(expression) << endl; cout << "Eval: " << uc.Eval(expression) << endl; }