#ifndef LEXER_H #define LEXER_H #include #include #include enum class TokenType { TOK_NUMBERS_LIT, TOK_STRING_LIT, TOK_BOOL_LIT, TOK_NULL_LIT, TOK_IDENT_LIT, TOK_ADD_OP, TOK_SUB_OP, TOK_DIV_OP, TOK_MULT_OP, TOK_MOD_OP, TOK_OR, // || TOK_AND, // && TOK_EQ, // == TOK_NEQ, // != TOK_LT, // < TOK_LT_EQ, // <= TOK_GT, // > TOK_GT_EQ, // >= TOK_OPEN_PAREN, // ( TOK_CLOSE_PAREN, // ) TOK_EOF }; struct Token { TokenType type; std::string name, value; Token(TokenType _type, std::string _name, std::string _value); }; class Lexer { public: Lexer() = default; // Given user input, convert it to vector of token object const std::vector &tokenize(const std::string &src); // Return the vector of token object const std::vector &tokens(); private: void tokenizeNumbers(); void tokenizeString(); void tokenizeIdentifiers(); void tokenizeOperators(); void skipWhitespaces(); [[nodiscard]] char peek() const; char advance(); [[nodiscard]] bool eof() const; void expect(char c, const std::string &error); int m_cursor = 0; std::string m_src; std::vector m_tokens; }; #endif // LEXER_H