// // interpreter.hpp // curly // // Created by Bob Polis at 2020-09-05 // Copyright (c) 2020 SwiftCoder. All rights reserved. // #ifndef _interpreter_H_ #define _interpreter_H_ #include #include #include #include #include #include class syntax_error : public std::runtime_error { public: syntax_error(const std::string& what_arg) : std::runtime_error(what_arg) {} }; class interpreter { public: interpreter() = default; std::string eval(std::istream& in, bool& done); private: std::vector _prog; std::vector _stack; std::map _labels; std::map _vars; std::vector _calls; std::vector::size_type _pc {0}; void reset(); void exec_instruction(const std::string& code, bool& done); // integer operations void add(); void sub(); void mul(); void div(); void mod(); void abs(); void neg(); void inc(); void dec(); // string operations void dup(); void rev(); void slc(); void idx(); void cat(); void len(); void rot(); void enl(); // tests & jumps void gto(); void geq(); void gne(); void glt(); void gle(); void ggt(); void gge(); // subroutines void fun(); void ret(); }; #endif // _interpreter_H_