Add string literals

This commit is contained in:
2020-05-17 20:30:57 +02:00
parent fc2870ca74
commit e1008b43a6
11 changed files with 152 additions and 48 deletions

View File

@@ -5,71 +5,71 @@
namespace Interpret
{
struct TokenError : public std::exception
struct InterpretationError : public std::exception
{
Token::Token errorToken;
std::string errorMsg;
TokenError(Token::Token const & token, std::string const & msg);
InterpretationError(Token::Token const & token, std::string const & msg);
};
struct ExpectedArgument : public TokenError
struct ExpectedArgument : public InterpretationError
{
ExpectedArgument(Token::Token const & token);
};
struct ExpectedLabel : public TokenError
struct ExpectedLabel : public InterpretationError
{
ExpectedLabel(Token::Token const & token);
};
struct ExpectedValue : public TokenError
struct ExpectedValue : public InterpretationError
{
ExpectedValue(Token::Token const & token);
};
struct ExpectedImmediate : public TokenError
struct ExpectedImmediate : public InterpretationError
{
ExpectedImmediate(Token::Token const & token);
};
struct ExpectedImmediateOrMemory : public TokenError
struct ExpectedImmediateOrMemory : public InterpretationError
{
ExpectedImmediateOrMemory(Token::Token const & token);
};
struct ExpectedRegister : public TokenError
struct ExpectedRegister : public InterpretationError
{
ExpectedRegister(Token::Token const & token);
};
struct ExpectedRegisterOrMemory : public TokenError
struct ExpectedRegisterOrMemory : public InterpretationError
{
ExpectedRegisterOrMemory(Token::Token const & token);
};
struct ExpectedOperand : public TokenError
struct ExpectedOperand : public InterpretationError
{
ExpectedOperand(Token::Token const & token);
};
struct TooManyArguments : public TokenError
struct TooManyArguments : public InterpretationError
{
TooManyArguments(Token::Token const & token);
};
struct TooFewArguments : public TokenError
struct TooFewArguments : public InterpretationError
{
TooFewArguments(Token::Token const & token);
};
struct MissingEndOfStatment : public TokenError
struct MissingEndOfStatment : public InterpretationError
{
MissingEndOfStatment(Token::Token const & token);
};
namespace Internal
{
struct BadTokenForValue : public TokenError
struct BadTokenForValue : public InterpretationError
{
BadTokenForValue(Token::Token const & token);
};

18
include/token/errors.hpp Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include <stdexcept>
#include <token/token.hpp>
namespace Token
{
struct TokenizationError : public std::exception
{
Token errorToken;
std::string errorMsg;
TokenizationError(Token const & token, std::string const & msg);
};
struct MissingEndOfString : public TokenizationError
{
MissingEndOfString(Token const & token);
};
}

View File

@@ -42,6 +42,7 @@ namespace Token
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, bool isValid, int const lineNumber, int const lineColumn);
static Token CreateStringLiteralToken(std::string const & value, int const lineNumber, int const lineColumn);
void DebugPrint() const;
};

View File

@@ -10,6 +10,7 @@ namespace Token
Register,
StatementEnd,
Label,
String,
Memory
};
}