From c4cae690deddcb8a7fc6a537816e832525ca0e86 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 31 Aug 2016 20:05:10 +0000 Subject: Develop runtime --- main.cpp | 4 ++++ runtime.cpp | 11 ++++++++++- runtime.h | 3 +++ token.cpp | 4 ++++ token.h | 1 + value.cpp | 11 +++++------ value.h | 3 ++- 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 0e8e367..9de9ce8 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ #include #include #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& tokens) { for (auto& token : tokens) { - + if (!runCommand(token)) { + Value value(token); + } } } diff --git a/runtime.h b/runtime.h index f1b050d..cdecd84 100644 --- a/runtime.h +++ b/runtime.h @@ -1,10 +1,13 @@ #pragma once #include "value.h" #include +#include "token.h" class Runtime { private: std::vector m_values; + bool runCommand(const Token& token); + public: Runtime(); void run(std::vector& tokens); diff --git a/token.cpp b/token.cpp index df8c82a..6e9e5e2 100644 --- a/token.cpp +++ b/token.cpp @@ -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; +} diff --git a/token.h b/token.h index 0d3a314..8ccb975 100644 --- a/token.h +++ b/token.h @@ -9,4 +9,5 @@ class Token { public: Token(std::string& lexeme, bool isString); const std::string& getLexeme() const; + bool isString() const; }; diff --git a/value.cpp b/value.cpp index acf80ce..90b689b 100644 --- a/value.cpp +++ b/value.cpp @@ -1,14 +1,13 @@ #include "value.h" #include -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(); } } diff --git a/value.h b/value.h index 71d5101..7d85d3c 100644 --- a/value.h +++ b/value.h @@ -1,5 +1,6 @@ #pragma once #include +#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; -- cgit v1.3