aboutsummaryrefslogtreecommitdiffstats
path: root/src/runtime.cpp
diff options
context:
space:
mode:
authorjantuomi <jans.tuomi@gmail.com>2016-09-01 14:29:59 +0300
committerjantuomi <jans.tuomi@gmail.com>2016-09-01 14:29:59 +0300
commit2f4c8ad33b64a8ca3145f4e6b6bd85cf89cf1006 (patch)
tree0650945f0bb8bff20cf5e80b9338d98a1d030809 /src/runtime.cpp
parent53e30cdd779f12ba5b19a59e9e18abf69c795ad5 (diff)
Add functions
Diffstat (limited to 'src/runtime.cpp')
-rw-r--r--src/runtime.cpp18
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) {