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

View File

@ -1,3 +1,3 @@
fun int main() {
return 1;
return 1;
}