Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / main.cpp
diff options
context:
space:
mode:
1 files changed, 36 insertions, 0 deletions
-rw-r--r--JSImpl/src/main.cpp36
diff --git a/JSImpl/src/main.cpp b/JSImpl/src/main.cpp
new file mode 100644
index 0000000..3fe6f99
--- /dev/null
+++ b/JSImpl/src/main.cpp
@@ -0,0 +1,36 @@
+#include "Lexer.h"
+#include "Parser.h"
+#include "ASTPrinter.h"
+#include "ASTInterpreter.h"
+#include <iostream>
+
+void RunParseCalc()
+{
+ IPLVector<Token> tokens;
+ //Tokenize("var a = 0; var b = a + 123;a+b;", 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);
+ 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.back() << std::endl;
+ result.pop_back();
+ }
+ std::cout << "S = " << i.ModifyVariable("s") << std::endl;
+}
+
+int main()
+{
+ RunParseCalc();
+
+#if defined(_WIN32)
+ std::system("pause");
+#endif
+ return 0;
+}