added inp and err instructions

This commit is contained in:
Bob Polis 2020-09-21 10:17:16 +02:00
parent c41883c11a
commit b46fae13d7
2 changed files with 18 additions and 2 deletions

View File

@ -121,7 +121,9 @@ void interpreter::exec_instruction(const std::string& code, bool& done) {
else if (code == "fun") fun();
else if (code == "ret") ret();
else if (code == "enl") enl();
else if (code == "out") out(); // for debugging
else if (code == "inp") inp();
else if (code == "out") out();
else if (code == "err") err();
else throw syntax_error {code};
}
@ -387,7 +389,19 @@ void interpreter::ret() {
// debugging --------------------------------------------------------------
void interpreter::inp() {
std::string val;
std::cin >> val;
_stack.push_back(val);
_pc++;
}
void interpreter::out() {
std::cout << _stack.back() << '\n';
_pc++;
}
void interpreter::err() {
std::cerr << _stack.back() << '\n';
_pc++;
}

View File

@ -72,8 +72,10 @@ class interpreter {
void fun();
void ret();
// debugging
// I/O
void inp();
void out();
void err();
};
#endif // _interpreter_H_