Support for several splitter characters added

This commit is contained in:
Tristan B. Velloza Kildaire 2021-03-02 22:43:09 +02:00
parent ce7ea36b0b
commit acab7dd5f3
2 changed files with 13 additions and 3 deletions

View File

@ -38,7 +38,7 @@ public final class Lexer
position++; position++;
} }
else if(currentChar == ';' && !stringMode) else if(isSpliter(currentChar) && !stringMode)
{ {
/* Flush the current token (if one exists) */ /* Flush the current token (if one exists) */
if(currentToken.length) if(currentToken.length)
@ -100,4 +100,14 @@ public final class Lexer
{ {
return tokens; return tokens;
} }
/* TODO: We need to add pop functionality if we encounter || */
private bool isSpliter(char character)
{
return character == ';' || character == ',' || character == '(' ||
character == ')' || character == '[' || character == ']' ||
character == '+' || character == '-' || character == '/' ||
character == '%' || character == '*' || character == '&' ||
character == '|' || character == '^' || character == '!';
}
} }

View File

@ -15,8 +15,8 @@ void beginCompilation(string[] sourceFiles)
gprintln("Performing tokenization on '"~sourceFile~"' ..."); gprintln("Performing tokenization on '"~sourceFile~"' ...");
/* TODO: Open source file */ /* TODO: Open source file */
// string sourceCode = "hello \"world\";"; string sourceCode = "hello \"world\";";
string sourceCode = "hello;"; // string sourceCode = "hello;";
Lexer currentLexer = new Lexer(sourceCode); Lexer currentLexer = new Lexer(sourceCode);
currentLexer.performLex(); currentLexer.performLex();