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
|
||||
|
25
src/main.cpp
25
src/main.cpp
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user