54 lines
2.1 KiB
C++
54 lines
2.1 KiB
C++
#pragma once
|
|
#include <token/operandtype.hpp>
|
|
#include <token/registertype.hpp>
|
|
#include <token/tokentype.hpp>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
namespace Token
|
|
{
|
|
enum class TokenValueType
|
|
{
|
|
None = 0,
|
|
Integer,
|
|
Operand,
|
|
Register,
|
|
String
|
|
};
|
|
|
|
struct Token
|
|
{
|
|
private:
|
|
Token(TokenType type, bool validness, int const lineNumber, int const lineColumn);
|
|
Token(TokenType type, std::string const & string, bool validness, int const lineNumber, int const lineColumn);
|
|
Token(TokenType type, int value, bool validness, int const lineNumber, int const lineColumn);
|
|
Token(TokenType type, RegisterType const registerType, bool validness, int const lineNumber, int const lineColumn);
|
|
Token(TokenType type, OperandType const OperandType, bool validness, int const lineNumber, int const lineColumn);
|
|
|
|
public:
|
|
int const lineNumber;
|
|
int const lineColumn;
|
|
TokenType type;
|
|
TokenValueType const valueType;
|
|
bool isValid;
|
|
std::variant<OperandType, RegisterType, int, std::string> data;
|
|
std::string errorMessage;
|
|
|
|
Token(Token const & other);
|
|
|
|
static Token CreateEmptyToken(int const lineNumber, int const lineColumn);
|
|
static Token CreateErrorToken(std::string const & message, TokenType const type, int const lineNumber, int const lineColumn);
|
|
static Token CreateStatementEndToken(int const lineNumber, int const lineColumn);
|
|
static Token CreateLabelDefinitionToken(std::string const & string, int const lineNumber, int const lineColumn);
|
|
static Token CreateLabelArgumentToken(std::string const & string, int const lineNumber, int const lineColumn);
|
|
static Token CreateImmediateValueToken(int const value, int const lineNumber, int const lineColumn);
|
|
static Token CreateRegisterToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
|
|
static Token CreateOperandToken(OperandType const operandType, int const lineNumber, int const lineColumn);
|
|
static Token CreateMemoryToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
|
|
static Token CreateMemoryToken(int const value, int const lineNumber, int const lineColumn);
|
|
|
|
std::string GetName() const;
|
|
void Print() const;
|
|
};
|
|
}
|