diff options
Diffstat (limited to 'src/runtime.cpp')
| -rw-r--r-- | src/runtime.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/runtime.cpp b/src/runtime.cpp index 26c5885..3f61060 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -1,4 +1,5 @@ #include "runtime.h" +#include <iostream> Runtime::Runtime() { @@ -6,20 +7,34 @@ Runtime::Runtime() { void Runtime::initValues(const std::vector<int>& values) { for (const int i : values) { - m_values.push(i); + m_values.push_back(i); } } -/* Returns false if token is not a command */ -bool Runtime::runCommand(const Token& token) { - // TODO - return false; +void Runtime::runCommand(const Token& token) { + if (token.getLexeme() == "S") { + doSum(); + } } void Runtime::run(std::vector<Token>& tokens) { for (auto& token : tokens) { - if (!runCommand(token)) { + runCommand(token); + } +} - } +void Runtime::printValues() const { + for (const int value : m_values) { + std::cout << value << " "; } + std::cout << std::endl; +} + +void Runtime::doSum() { + int sum = 0; + for (const int i : m_values) { + sum += i; + } + + m_values.push_back(sum); } |
