aboutsummaryrefslogtreecommitdiffstats
path: root/src/runtime.cpp
blob: 3f61060a442592477e7342c3ca619bf4adf8ebe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "runtime.h"
#include <iostream>

Runtime::Runtime() {

}

void Runtime::initValues(const std::vector<int>& values) {
    for (const int i : values) {
        m_values.push_back(i);
    }
}

void Runtime::runCommand(const Token& token) {
    if (token.getLexeme() == "S") {
        doSum();
    }
}

void Runtime::run(std::vector<Token>& tokens) {
    for (auto& token : tokens) {
        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);
}