Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / main.cpp
diff options
context:
space:
mode:
1 files changed, 38 insertions, 1 deletions
-rw-r--r--JSImpl/src/main.cpp39
diff --git a/JSImpl/src/main.cpp b/JSImpl/src/main.cpp
index 0d78a10..f3eb90a 100644
--- a/JSImpl/src/main.cpp
+++ b/JSImpl/src/main.cpp
@@ -25,9 +25,46 @@ void RunParseCalc()
std::cout << "S = " << i.ModifyVariable("a") << std::endl;
}
+class InterpreterPrinter : public ASTInterpreter::Printer
+{
+public:
+ virtual void PrintVariable(const char* name, double value) override
+ {
+ std::cout << name << ": " << value << std::endl;
+ }
+};
+
+void InteractiveInterpreter()
+{
+ char command[1000];
+ ASTInterpreter i;
+ InterpreterPrinter p;
+ do
+ {
+ std::cin.getline(command, 1000);
+ if (strcmp(command, "exit") == 0)
+ {
+ break;
+ }
+ if (strcmp(command, "print") == 0)
+ {
+ i.Print(p);
+ continue;
+ }
+ IPLVector<Token> tokens;
+ Tokenize(command, tokens);
+ auto result = i.Run(Parse(tokens).get());
+ while (!result.empty()) {
+ std::cout << result.back() << std::endl;
+ result.pop_back();
+ }
+ } while (true);
+}
+
int main()
{
- RunParseCalc();
+ //RunParseCalc();
+ InteractiveInterpreter();
#if defined(_WIN32)
std::system("pause");