changes here and there

This commit is contained in:
2021-07-12 18:45:51 +02:00
parent 5e69ce1047
commit 5e4480c767
18 changed files with 1692 additions and 1309 deletions

58
lexer.h
View File

@@ -5,7 +5,9 @@
#include <stdexcept>
#include <string>
enum class TokenType {
namespace usql {
enum class TokenType {
undef,
identifier,
plus,
@@ -21,8 +23,9 @@ enum class TokenType {
keyword_create,
keyword_table,
keyword_where,
keyword_delete,
keyword_update,
keyword_delete,
keyword_update,
keyword_load,
keyword_from,
keyword_insert,
keyword_into,
@@ -48,46 +51,63 @@ enum class TokenType {
newline,
comment,
eof
};
};
struct Token {
struct Token {
std::string token_string;
TokenType type;
Token(const std::string &token_str, TokenType typ);
};
class Lexer {
public:
Lexer() {};
Token(const std::string &token_str, TokenType typ);
};
class Lexer {
public:
Lexer();
void parse(const std::string &code);
void debugTokens();
Token currentToken();
Token currentToken();
Token consumeCurrentToken();
void nextToken();
void skipToken(TokenType type);
void skipTokenOptional(TokenType type);
TokenType tokenType();
TokenType nextTokenType();
TokenType prevTokenType();
static bool isRelationalOperator(TokenType token_type);
static bool isLogicalOperator(TokenType token_type);
static bool isRelationalOperator(TokenType token_type);
static bool isLogicalOperator(TokenType token_type);
static bool isArithmeticalOperator(TokenType token_type);
private:
private:
TokenType type(const std::string &token);
std::string stringLiteral(std::string token);
static std::string typeToString(TokenType token_type);
private:
std::string m_code_str;
std::vector<Token> m_tokens;
int m_index = 0;
};
private:
std::string m_code_str;
std::vector<Token> m_tokens;
int m_index = 0;
std::regex k_words_regex;
std::regex k_int_regex;
std::regex k_int_underscored_regex;
std::regex k_double_regex;
std::regex k_identifier_regex;
};
}