diff --git a/interpreter.cpp b/interpreter.cpp index 1b1b71f..4f3615c 100644 --- a/interpreter.cpp +++ b/interpreter.cpp @@ -52,7 +52,7 @@ std::string interpreter::eval(std::istream& in, bool& done) { _pc++; continue; } - + // check literal int if (std::isdigit(code[0])) { _stack.push_back(code); @@ -130,7 +130,7 @@ void interpreter::exec_instruction(const std::string& code, bool& done) { else if (code == "inp") inp(); else if (code == "out") out(); else if (code == "err") err(); - else throw syntax_error {code}; + else throw syntax_error {code, _pc + 1}; } // integer operations ----------------------------------------------------- diff --git a/interpreter.hpp b/interpreter.hpp index c5b5f77..01a3abd 100644 --- a/interpreter.hpp +++ b/interpreter.hpp @@ -18,7 +18,11 @@ class syntax_error : public std::runtime_error { public: - syntax_error(const std::string& what_arg) : std::runtime_error(what_arg) {} + syntax_error(const std::string& what_arg, size_t lineno) + : std::runtime_error {what_arg}, _lineno {lineno} {} + size_t lineno() const { return _lineno; } + private: + size_t _lineno {0}; }; class interpreter {