improved syntax_error to hold line number as well
This commit is contained in:
parent
27b798a83e
commit
372bc976a0
@ -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 -----------------------------------------------------
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user