From d5cb498ba37949193fecafa8c1f15d70ade79515 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Sun, 21 Oct 2018 21:27:36 +0300 Subject: Added a tree interpreter --- JSImpl/src/main.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'JSImpl/src/main.cpp') diff --git a/JSImpl/src/main.cpp b/JSImpl/src/main.cpp index 73f883f..80dcd32 100644 --- a/JSImpl/src/main.cpp +++ b/JSImpl/src/main.cpp @@ -1,6 +1,7 @@ #include "Lexer.h" #include "Parser.h" #include "ASTPrinter.h" +#include "ASTInterpreter.h" #include #define LOG(msg) std::cout << msg << std::endl #define EXECUTE_TEST(test) std::cout << #test << " "; test(); @@ -198,6 +199,26 @@ void TestParseUnaryExpr() expr->Accept(p); } +void RunParseCalc() +{ + IPLVector tokens; + //Tokenize("var a = 0; var b = a + 123;a+b;", tokens); + Tokenize("123 + 321", tokens); + + // TODO make actual test :D + auto expr = Parse(tokens); + ASTPrinter p(std::cout); + expr->Accept(p); + ASTInterpreter i; + 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(); + } +} + void TestHexNumber() { IPLVector tokens; @@ -235,7 +256,8 @@ int main() EXECUTE_TEST(TestHexNumber); EXECUTE_TEST(TestScientificNotationNumber); - // TestParseUnaryExpr(); + //TestParseUnaryExpr(); + //RunParseCalc(); #if defined(_WIN32) std::system("pause"); #endif -- cgit v1.3.1-23-gd82d