Basic arithmetic and jump labels

This commit is contained in:
2019-11-17 21:02:35 +01:00
commit b84557b3e1
34 changed files with 1350 additions and 0 deletions

View 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);
}

View 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
View 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;
};
}

View 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);
};
}

View File

@@ -0,0 +1,14 @@
#pragma once
namespace Token
{
enum class TokenType
{
Unknown = -1,
Operand = 0,
ImmediateInteger,
Register,
StatementEnd,
Label
};
}