Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / main.cpp
diff options
context:
space:
mode:
Commitd5cb498ba37949193fecafa8c1f15d70ade79515 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-10-21 21:27:36 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-10-24 19:43:48 +0300
Filesdbf7da8806366afa5d435ff6a3e9d1adf397aa77 /JSImpl/src/main.cpp
IPL-d5cb498ba37949193fecafa8c1f15d70ade79515.tar
IPL-d5cb498ba37949193fecafa8c1f15d70ade79515.tar.gz
IPL-d5cb498ba37949193fecafa8c1f15d70ade79515.zip
Parentd57561ef43c80fa6050e80f4876a45ba886818ff (diff)
Added a tree interpreter
1 files changed, 23 insertions, 1 deletions
-rw-r--r--JSImpl/src/main.cpp24
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 <iostream>
#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<Token> 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<Token> tokens;
@@ -235,7 +256,8 @@ int main()
EXECUTE_TEST(TestHexNumber);
EXECUTE_TEST(TestScientificNotationNumber);
- // TestParseUnaryExpr();
+ //TestParseUnaryExpr();
+ //RunParseCalc();
#if defined(_WIN32)
std::system("pause");
#endif