diff options
| -rw-r--r-- | main.cpp | 4 | ||||
| -rw-r--r-- | runtime.cpp | 11 | ||||
| -rw-r--r-- | runtime.h | 3 | ||||
| -rw-r--r-- | token.cpp | 4 | ||||
| -rw-r--r-- | token.h | 1 | ||||
| -rw-r--r-- | value.cpp | 11 | ||||
| -rw-r--r-- | value.h | 3 |
7 files changed, 29 insertions, 8 deletions
@@ -3,6 +3,7 @@ #include <streambuf> #include <string> #include "parser.h" +#include "runtime.h" std::string readFile(std::string& filename) { std::ifstream t(filename); @@ -24,5 +25,8 @@ int main(int argc, char** argv) { Parser parser(input); parser.printTokens(); + Runtime runtime; + runtime.run(parser.getTokens()); + return 0; } diff --git a/runtime.cpp b/runtime.cpp index 8478da7..b4db6a8 100644 --- a/runtime.cpp +++ b/runtime.cpp @@ -1,11 +1,20 @@ #include "runtime.h" +#include "value.h" Runtime::Runtime() { } +/* Returns false if token is not a command */ +bool Runtime::runCommand(const Token& token) { + // TODO + return false; +} + void Runtime::run(std::vector<Token>& tokens) { for (auto& token : tokens) { - + if (!runCommand(token)) { + Value value(token); + } } } @@ -1,10 +1,13 @@ #pragma once #include "value.h" #include <vector> +#include "token.h" class Runtime { private: std::vector<Value> m_values; + bool runCommand(const Token& token); + public: Runtime(); void run(std::vector<Token>& tokens); @@ -8,3 +8,7 @@ Token::Token(std::string& lexeme, bool isString) : const std::string& Token::getLexeme() const { return m_lexeme; } + +bool Token::isString() const { + return m_isString; +} @@ -9,4 +9,5 @@ class Token { public: Token(std::string& lexeme, bool isString); const std::string& getLexeme() const; + bool isString() const; }; @@ -1,14 +1,13 @@ #include "value.h" #include <string> -Value::Value(std::string& lexeme) { - if (lexeme.find_first_not_of("0123456789")) { +Value::Value(Token& token) { + if (!token.isString()) m_type = Value::Type::Integer; - m_intData = std::stoi(lexeme, nullptr, 10); - } - else { + m_intData = std::stoi(token.getLexeme(), nullptr, 10); + } else { m_type = Value::Type::String; - m_strData = lexeme; + m_strData = token.getLexeme(); } } @@ -1,5 +1,6 @@ #pragma once #include <string> +#include "token.h" class Value { public: @@ -8,7 +9,7 @@ class Value { String }; - Value(std::string& lexeme); + Value(Token& token); const Value::Type getType() const; const int getIntData() const; const std::string& getStrData() const; |
