stuff
This commit is contained in:
parent
88792d453a
commit
75eb6fb603
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.idea
|
||||||
|
|
23
src/main.cpp
23
src/main.cpp
|
@ -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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user