aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.cpp4
-rw-r--r--runtime.cpp11
-rw-r--r--runtime.h3
-rw-r--r--token.cpp4
-rw-r--r--token.h1
-rw-r--r--value.cpp11
-rw-r--r--value.h3
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 <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);
+ }
}
}
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 <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);
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 <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();
}
}
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 <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;