Im vonfused

This commit is contained in:
Pasha Bibko
2025-04-22 22:32:07 +01:00
parent 8e1fa45a44
commit 099e543e95
8 changed files with 100 additions and 15 deletions

View File

@@ -34,6 +34,12 @@ namespace LX
TOKEN_CASE(Token::DIV);
TOKEN_CASE(Token::NUMBER_LITERAL);
TOKEN_CASE(Token::RETURN);
TOKEN_CASE(Token::OPEN_BRACE);
TOKEN_CASE(Token::CLOSE_BRACE);
TOKEN_CASE(Token::OPEN_BRACKET);
TOKEN_CASE(Token::CLOSE_BRACKET);
TOKEN_CASE(Token::OPEN_PAREN);
TOKEN_CASE(Token::CLOSE_PAREN);
default:
return "Unknown: " + std::to_string(type);
@@ -99,6 +105,17 @@ namespace LX
{ "return" , Token::RETURN }
};
// All the symbols supported by the lexer //
static const std::unordered_map<char, Token::TokenType> symbols =
{
{ '{', Token::OPEN_BRACKET },
{ '}', Token::CLOSE_BRACKET },
{ '[', Token::OPEN_BRACE },
{ ']', Token::CLOSE_BRACE },
{ '(', Token::OPEN_PAREN },
{ ')', Token::CLOSE_PAREN }
};
// All the single-char operators currently supported by the lexer with their token-enum equivalents //
// TODO: Support multi-char operators such as: ==, -> +=, &&
static const std::unordered_map<char, Token::TokenType> operators =
@@ -257,6 +274,12 @@ namespace LX
// During a word //
else if (info.isAlpha == true);
// Symbols //
else if (auto sym = symbols.find(current); sym != symbols.end())
{
tokens.push_back({ sym->second, info, 1 });
}
// Operators (+, -, /, *) //
else if (auto op = operators.find(current); op != operators.end())
{