diff --git a/interpreter.cpp b/interpreter.cpp index 1543d6e..3a3d2e6 100644 --- a/interpreter.cpp +++ b/interpreter.cpp @@ -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++; +} diff --git a/interpreter.hpp b/interpreter.hpp index d042f03..c5b5f77 100644 --- a/interpreter.hpp +++ b/interpreter.hpp @@ -72,8 +72,10 @@ class interpreter { void fun(); void ret(); - // debugging + // I/O + void inp(); void out(); + void err(); }; #endif // _interpreter_H_