#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::Transformer t; t.Owned(); // Causes t to be released when it goes out of scope // Rules must be defined in an order that allows for proper transformation. // 1. Comment rule t.FromTo("REM {comment}", "// {comment}"); // 2. Variable assignment rule t.FromTo("LET {@Alpha:var} = {val}", "var {var} = {val};"); // 3. Print statement rule t.FromTo("PRINT {output}", "console.log({output});"); // 4. IF...THEN rule with RewindOnChange to handle nested statements auto ifRule = t.FromTo("IF {condition} THEN {action}", R"(if ({condition}) { {action} })"); ifRule.RewindOnChange(true); // The legacy script to transpile auto legacyScript = R"( REM Initialize variables LET X = 10 LET Y = X * 2 IF Y > 15 THEN PRINT "Value is large" )"; // Run the transformation cout << t.Transform(legacyScript) << endl; } }