52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
// parser.h
|
|
#ifndef PARSER_H
|
|
#define PARSER_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <cstdint>
|
|
|
|
#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<Mnemonic> parseMnemonic();
|
|
std::string parseSymbol();
|
|
int parseRegister();
|
|
void parseComma();
|
|
bool parseIndexed();
|
|
int parseNumber(int lo, int hi);
|
|
std::vector<std::uint8_t> parseData();
|
|
|
|
void parseOperands(Mnemonic& m);
|
|
|
|
bool isDirective(const std::string& name);
|
|
bool isDataDirective(const std::string& name);
|
|
std::shared_ptr<Node> parseDirective(const std::string& label, const std::string& directive);
|
|
std::shared_ptr<Node> parseDataDirective(const std::string& label, const std::string& directive);
|
|
|
|
std::shared_ptr<Node> parseInstruction();
|
|
Code parseCode();
|
|
|
|
std::shared_ptr<Mnemonic> makeMnemonic(const std::string& name, bool extended);
|
|
static void initMnemonicMap();
|
|
|
|
private:
|
|
Lexer lexer_{""};
|
|
|
|
static inline std::unordered_map<std::string, std::uint8_t> s_nameToOpcode{};
|
|
static inline bool s_mnemonicMapInitialized = false;
|
|
};
|
|
|
|
#endif // PARSER_H
|