This commit is contained in:
Maxwell 2025-04-21 19:01:43 +10:00
parent a0a9a94107
commit 88792d453a
2 changed files with 22 additions and 6 deletions

BIN
mx Executable file

Binary file not shown.

View File

@ -1,4 +1,5 @@
#include <iostream>
#include <csignal>
#include <fstream>
#include <string>
#include <vector>
@ -51,18 +52,19 @@ struct var {
}
};
string logList;
class Logger {
private:
bool isDebug = false;
string log;
void writeToLog(string type, string in) {
log += type + ": " + in + "\n";
logList += type + ": " + in + "\n";
}
public:
string getLog() {
return log;
return logList;
}
void toggleDebugPrint() {
isDebug = !isDebug;
@ -205,24 +207,36 @@ class Parser {
tokens.push_back(semi);
}
}
vector<Token> getTokens() {
return tokens;
}
};
class Interpreter {
private:
vector<Token> tokens;
Logger log;
int tokenIndex = 0;
Token consume() {
return tokens[tokenIndex++];
return tokens.at(tokenIndex++);
}
Token peek(int index = 1) {
return tokens[tokenIndex + index];
return tokens.at(tokenIndex + index);
}
public:
void interpret(vector<Token> tokenList) {
tokens = tokenList;
log.debug("Alright we got " + to_string(tokens.size()) + " tokens");
while (tokenIndex < tokens.size()) {
Token currentToken = consume();
int peekAhead = 1;
vector<Token> currentInstruction;
while (peek(peekAhead).keyword != keywords::SEMICOLON) {
raise(SIGINT);
currentInstruction.push_back(peek(peekAhead));
peekAhead ++;
}
}
}
};
@ -244,5 +258,7 @@ int main(int argc, char* argv[]) {
}
parser.parseLines(file, log);
parser.processLines();
Interpreter interpreter;
interpreter.interpret(parser.getTokens());
return 0;
}