PorygonLang/src/Parser/Token.hpp

105 lines
2.0 KiB
C++

#include <utility>
#ifndef PORYGONLANG_TOKEN_HPP
#define PORYGONLANG_TOKEN_HPP
#include <utility>
#include <string>
#include "TokenKind.hpp"
using namespace std;
class IToken{
unsigned int Position;
unsigned int Length;
public:
virtual TokenKind GetKind() = 0;
IToken(unsigned int position, unsigned int length){
Position = position;
Length = length;
}
unsigned int GetStartPosition(){
return Position;
}
unsigned int GetEndPosition(){
return Position + Length - 1;
}
unsigned int GetLength(){
return Length;
}
virtual ~IToken(){
}
};
class SimpleToken : public IToken{
public:
TokenKind Kind;
explicit SimpleToken(TokenKind type, unsigned int position, unsigned int length) : IToken(position, length){
Kind = type;
}
TokenKind GetKind() override{
return Kind;
}
};
class IntegerToken : public IToken{
public:
long Value;
explicit IntegerToken(long value, unsigned int position, unsigned int length) : IToken(position, length){
Value = value;
}
TokenKind GetKind() override{
return TokenKind::Integer;
}
};
class FloatToken : public IToken{
public:
double Value;
explicit FloatToken(double value, unsigned int position, unsigned int length) : IToken(position, length){
Value = value;
}
TokenKind GetKind() override{
return TokenKind::Float;
}
};
class StringToken : public IToken{
public:
string Value;
explicit StringToken(string value, unsigned int position, unsigned int length) : IToken(position, length){
Value = std::move(value);
}
TokenKind GetKind() override{
return TokenKind::String;
}
};
class IdentifierToken : public IToken{
public:
string Value;
explicit IdentifierToken(string value, unsigned int position, unsigned int length) : IToken(position, length){
Value = std::move(value);
}
TokenKind GetKind() override{
return TokenKind::Identifier;
}
};
#endif //PORYGONLANG_TOKEN_HPP