2022-03-11 16:00:09 +00:00
|
|
|
#pragma once
|
|
|
|
#include "Location.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
enum TokenType
|
|
|
|
{
|
|
|
|
TT_Identifier,
|
|
|
|
TT_Number,
|
|
|
|
TT_Float,
|
|
|
|
TT_Keyword,
|
|
|
|
TT_String,
|
|
|
|
TT_Plus,
|
|
|
|
TT_Minus,
|
|
|
|
TT_Mul,
|
|
|
|
TT_Div,
|
|
|
|
TT_At,
|
|
|
|
TT_Equal,
|
|
|
|
TT_LessThan,
|
|
|
|
TT_GreaterThan,
|
|
|
|
TT_LParen,
|
|
|
|
TT_RParen,
|
|
|
|
TT_LBracket,
|
|
|
|
TT_RBracket,
|
|
|
|
TT_Semicolon,
|
|
|
|
TT_LoadedString,
|
|
|
|
TT_EOF,
|
|
|
|
TT_Null,
|
|
|
|
TT_Equals,
|
|
|
|
TT_GTE,
|
2022-05-28 18:44:26 +00:00
|
|
|
TT_LTE,
|
|
|
|
TT_Period,
|
|
|
|
TT_Comma,
|
|
|
|
TT_Path,
|
|
|
|
TT_Exclamation,
|
2022-06-02 16:25:01 +00:00
|
|
|
TT_NEqual,
|
|
|
|
TT_LSQB,
|
|
|
|
TT_RSQB,
|
|
|
|
TT_Type,
|
|
|
|
TT_Import,
|
|
|
|
TT_Syscall0,
|
|
|
|
TT_Syscall1,
|
|
|
|
TT_Syscall2,
|
|
|
|
TT_Syscall3,
|
|
|
|
TT_Syscall4,
|
|
|
|
TT_Syscall5
|
2022-03-11 16:00:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const std::string token_strings[];
|
|
|
|
|
|
|
|
struct Token
|
|
|
|
{
|
|
|
|
TokenType tk_type;
|
|
|
|
|
|
|
|
int int_value;
|
|
|
|
std::string string_value;
|
|
|
|
float float_value;
|
|
|
|
|
|
|
|
Location loc;
|
|
|
|
|
|
|
|
Token(const TokenType& type);
|
|
|
|
|
|
|
|
Token(const TokenType& type, const Location& location);
|
|
|
|
|
|
|
|
Token(const TokenType& type, const int& val, const Location& location);
|
|
|
|
|
|
|
|
Token(const TokenType& type, const std::string& val, const Location& location);
|
|
|
|
|
|
|
|
Token(const TokenType& type, const std::string& val);
|
|
|
|
|
|
|
|
Token(const TokenType& type, const float& val, const Location& location);
|
|
|
|
|
|
|
|
~Token();
|
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
|
|
|
std::string line() const;
|
|
|
|
|
|
|
|
static Token make_with_line(const Token& origin, const std::string& line_text);
|
|
|
|
|
|
|
|
void operator=(const Token& other);
|
|
|
|
|
|
|
|
static void erase(Token& tk);
|
|
|
|
|
|
|
|
Token copy_with_new_type(const TokenType& type);
|
|
|
|
|
2022-05-28 18:44:26 +00:00
|
|
|
static bool match_token_types(const std::vector<Token>& a, const std::vector<Token>& b, int count);
|
2022-03-11 16:00:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string line_text;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Token> TokenStream;
|