#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("x = 1"); uc.DefineVariable("y = 2"); uc.DefineFunction("f(x) = x * 10"); auto t = uc.NewTransformer(); auto text = "Adding {x} and {y} gives: {x + y}. f(5) = {f(5)}"; uCalc uNew; uNew.DefineVariable("x = 111"); uNew.DefineVariable("y = 222"); uNew.DefineFunction("f(x) = x * 1000"); // Note: {@@Eval: txt} is equivalent of {@Eval: Eval(txt)} // which is what's needed for to evaluate the expression // resulting from the match that is not known ahead of time t.FromTo("'{' {expr} '}'", "{@@Eval: expr}"); cout << t.Transform(text) << endl; t.uCalc(uNew); t.FromTo("'{' {expr} '}'", "{@@Eval: expr}"); cout << t.Transform(text) << endl; }