aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..c39e469
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,40 @@
+#include <iostream>
+#include <fstream>
+#include <streambuf>
+#include <string>
+#include "parser.h"
+#include "runtime.h"
+
+std::string readFile(std::string& filename) {
+ std::ifstream t(filename);
+ std::string str((std::istreambuf_iterator<char>(t)),
+ (std::istreambuf_iterator<char>()));
+ return str;
+}
+
+int main(int argc, char** argv) {
+ if (argc != 2) {
+ std::cout << "Please supply input file name as a parameter." << std::endl;
+ return 1;
+ }
+
+ std::string filename = std::string(argv[1]);
+ std::string code = readFile(filename);
+
+ std::string valueString;
+ std::string stdinLine;
+ while (std::cin >> stdinLine) {
+ valueString += stdinLine + " ";
+ }
+
+ Parser parser;
+ std::vector<Token> tokens = parser.parseCode(code);
+ std::vector<int> values = parser.parseValues(valueString);
+ parser.printTokens(tokens);
+ parser.printValues(values);
+
+ Runtime runtime;
+ runtime.run(tokens);
+
+ return 0;
+}