diff options
Diffstat (limited to 'src/runtime.cpp')
| -rw-r--r-- | src/runtime.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/runtime.cpp b/src/runtime.cpp index 3f61060..7519ea9 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -12,9 +12,16 @@ void Runtime::initValues(const std::vector<int>& values) { } void Runtime::runCommand(const Token& token) { - if (token.getLexeme() == "S") { + const std::string lexeme = token.getLexeme(); + if (lexeme == "S") { doSum(); } + else if (lexeme == "o") { + doPrint(); + } + else if (lexeme == "O") { + doPrintAscii(); + } } void Runtime::run(std::vector<Token>& tokens) { @@ -23,13 +30,20 @@ void Runtime::run(std::vector<Token>& tokens) { } } -void Runtime::printValues() const { +void Runtime::doPrint() const { for (const int value : m_values) { std::cout << value << " "; } std::cout << std::endl; } +void Runtime::doPrintAscii() const { + for (const int value : m_values) { + std::cout << static_cast<char>(value); + } + std::cout << std::endl; +} + void Runtime::doSum() { int sum = 0; for (const int i : m_values) { |
