From 2f4c8ad33b64a8ca3145f4e6b6bd85cf89cf1006 Mon Sep 17 00:00:00 2001 From: jantuomi Date: Thu, 1 Sep 2016 14:29:59 +0300 Subject: Add functions --- src/runtime.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/runtime.cpp') 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& 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& tokens) { @@ -23,13 +30,20 @@ void Runtime::run(std::vector& 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(value); + } + std::cout << std::endl; +} + void Runtime::doSum() { int sum = 0; for (const int i : m_values) { -- cgit v1.3