aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parent53e30cdd779f12ba5b19a59e9e18abf69c795ad5 (diff)
Add functions
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp2
-rw-r--r--src/runtime.cpp18
-rw-r--r--src/runtime.h3
3 files changed, 18 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 8a00d55..53a6540 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -37,7 +37,5 @@ int main(int argc, char** argv) {
runtime.initValues(values);
runtime.run(tokens);
- runtime.printValues();
-
return 0;
}
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) {
diff --git a/src/runtime.h b/src/runtime.h
index 16c1c28..2a32220 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -9,10 +9,11 @@ class Runtime {
void runCommand(const Token& token);
void doSum();
+ void doPrint() const;
+ void doPrintAscii() const;
public:
Runtime();
void initValues(const std::vector<int>& values);
void run(std::vector<Token>& tokens);
- void printValues() const;
};