working AST
This commit is contained in:
parent
7c6379c62d
commit
9e9039af05
13 changed files with 962 additions and 36 deletions
52
simulator_SIC_XE/include/parser.h
Normal file
52
simulator_SIC_XE/include/parser.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue