Basic arithmetic and jump labels
This commit is contained in:
19
include/token/operandtype.hpp
Normal file
19
include/token/operandtype.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace Token
|
||||
{
|
||||
enum class OperandType
|
||||
{
|
||||
Unknown = -1,
|
||||
AddInteger = 0,
|
||||
SubtractInteger,
|
||||
DivideInteger,
|
||||
MultiplyInteger,
|
||||
ShiftIntegerLeft,
|
||||
ShiftIntegerRight,
|
||||
Jump
|
||||
};
|
||||
|
||||
OperandType GetOperandType(std::string const & op);
|
||||
}
|
||||
16
include/token/registertype.hpp
Normal file
16
include/token/registertype.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace Token
|
||||
{
|
||||
enum class RegisterType
|
||||
{
|
||||
Unknown = -1,
|
||||
A = 0,
|
||||
B,
|
||||
C,
|
||||
D
|
||||
};
|
||||
|
||||
RegisterType GetRegisterType(std::string const & reg);
|
||||
}
|
||||
27
include/token/token.hpp
Normal file
27
include/token/token.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <token/operandtype.hpp>
|
||||
#include <token/registertype.hpp>
|
||||
#include <token/tokentype.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Token
|
||||
{
|
||||
struct Token
|
||||
{
|
||||
int const lineNumber;
|
||||
int const lineColumn;
|
||||
TokenType type;
|
||||
bool isValid;
|
||||
std::variant<OperandType, RegisterType, int, std::string> data;
|
||||
|
||||
Token(int const lineNumber, int const lineColumn);
|
||||
Token(int const lineNumber, int const lineColumn, OperandType operatorType, bool validness);
|
||||
Token(int const lineNumber, int const lineColumn, RegisterType registerType, bool validness);
|
||||
Token(int const lineNumber, int const lineColumn, int value, bool validness);
|
||||
Token(int const lineNumber, int const lineColumn, std::string const & value, bool validness);
|
||||
|
||||
Token(Token const & other);
|
||||
|
||||
void DebugPrint() const;
|
||||
};
|
||||
}
|
||||
13
include/token/tokenizer.hpp
Normal file
13
include/token/tokenizer.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <token/token.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Token
|
||||
{
|
||||
class Tokenizer
|
||||
{
|
||||
public:
|
||||
void Tokenize(std::string const & line, int const lineNumber, std::vector<Token> & tokens);
|
||||
};
|
||||
}
|
||||
14
include/token/tokentype.hpp
Normal file
14
include/token/tokentype.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace Token
|
||||
{
|
||||
enum class TokenType
|
||||
{
|
||||
Unknown = -1,
|
||||
Operand = 0,
|
||||
ImmediateInteger,
|
||||
Register,
|
||||
StatementEnd,
|
||||
Label
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user