From 051eb93c188c15e3798018165991b0563bdbaa7f Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Mon, 22 Oct 2018 21:54:07 +0300 Subject: Enhanced tree interpreter - Added "proper" C++ like variable scoping - Added operator < - Added ++ and -- --- JSImpl/src/main.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'JSImpl/src/main.cpp') diff --git a/JSImpl/src/main.cpp b/JSImpl/src/main.cpp index 80dcd32..7dcdd74 100644 --- a/JSImpl/src/main.cpp +++ b/JSImpl/src/main.cpp @@ -203,20 +203,21 @@ void RunParseCalc() { IPLVector tokens; //Tokenize("var a = 0; var b = a + 123;a+b;", tokens); - Tokenize("123 + 321", tokens); + Tokenize("var s = 0; for (var i = 0; i < 10; ++i + --s) { s };", tokens); // TODO make actual test :D auto expr = Parse(tokens); - ASTPrinter p(std::cout); - expr->Accept(p); + //ASTPrinter p(std::cout); + //expr->Accept(p); ASTInterpreter i; - std::cout << "Running" << std::endl; + std::cout << "Running" << std::endl; auto result = i.Run(expr.get()); - std::cout << "Stack after run, top to bottom:" << std::endl; - while (!result.empty()) { - std::cout << result.top() << std::endl; - result.pop(); - } + std::cout << "Stack after run, top to bottom:" << std::endl; + while (!result.empty()) { + std::cout << result.top() << std::endl; + result.pop(); + } + std::cout << "S = " << i.ModifyVariable("i") << std::endl; } void TestHexNumber() @@ -257,7 +258,7 @@ int main() EXECUTE_TEST(TestScientificNotationNumber); //TestParseUnaryExpr(); - //RunParseCalc(); + RunParseCalc(); #if defined(_WIN32) std::system("pause"); #endif -- cgit v1.3.1-23-gd82d