// parser.h #ifndef PARSER_H #define PARSER_H #include #include #include #include #include #include "lexer.h" #include "code.h" #include "opcode.h" #include "mnemonic.h" class Parser { public: Parser() = default; Code parse(const std::string& input); private: std::string parseLabel(); std::shared_ptr parseMnemonic(); std::string parseSymbol(); int parseRegister(); void parseComma(); bool parseIndexed(); int parseNumber(int lo, int hi); std::vector parseData(); void parseOperands(Mnemonic& m); bool isDirective(const std::string& name); bool isDataDirective(const std::string& name); std::shared_ptr parseDirective(const std::string& label, const std::string& directive); std::shared_ptr parseDataDirective(const std::string& label, const std::string& directive); std::shared_ptr parseInstruction(); Code parseCode(); std::shared_ptr makeMnemonic(const std::string& name, bool extended); static void initMnemonicMap(); private: Lexer lexer_{""}; static inline std::unordered_map s_nameToOpcode{}; static inline bool s_mnemonicMapInitialized = false; }; #endif // PARSER_H