This commit is contained in:
Maxwell Jeffress 2025-04-22 17:44:48 +10:00
parent 88792d453a
commit 75eb6fb603
4 changed files with 19 additions and 10 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea

BIN
main Executable file

Binary file not shown.

View File

@ -217,11 +217,14 @@ class Interpreter {
vector<Token> tokens; vector<Token> tokens;
Logger log; Logger log;
int tokenIndex = 0; int tokenIndex = 0;
Token consume() { optional<Token> consume() {
return tokens.at(tokenIndex++); tokenIndex++;
if (tokens.size() > tokenIndex) return tokens.at(tokenIndex);
else return {};
} }
Token peek(int index = 1) { optional<Token> peek(int index = 1) {
return tokens.at(tokenIndex + index); if (tokens.size() > tokenIndex + index) return tokens.at(tokenIndex + index);
else return {};
} }
public: public:
@ -229,14 +232,18 @@ class Interpreter {
tokens = tokenList; tokens = tokenList;
log.debug("Alright we got " + to_string(tokens.size()) + " tokens"); log.debug("Alright we got " + to_string(tokens.size()) + " tokens");
while (tokenIndex < tokens.size()) { while (tokenIndex < tokens.size()) {
Token currentToken = consume(); if (peek().has_value()) Token currentToken = consume().value();
else break;
int peekAhead = 1; int peekAhead = 1;
vector<Token> currentInstruction; vector<Token> currentInstruction;
while (peek(peekAhead).keyword != keywords::SEMICOLON) { if (peek(peekAhead).has_value()) while (peek(peekAhead).value().keyword != keywords::SEMICOLON) {
raise(SIGINT); if (peek(peekAhead).has_value()) {
currentInstruction.push_back(peek(peekAhead)); currentInstruction.push_back(peek(peekAhead).value());
peekAhead ++; peekAhead ++;
} else break;
} }
consume();
} }
} }
}; };