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 <iostream>
#include <csignal>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -51,18 +52,19 @@ struct var {
} }
}; };
string logList;
class Logger { class Logger {
private: private:
bool isDebug = false; bool isDebug = false;
string log;
void writeToLog(string type, string in) { void writeToLog(string type, string in) {
log += type + ": " + in + "\n"; logList += type + ": " + in + "\n";
} }
public: public:
string getLog() { string getLog() {
return log; return logList;
} }
void toggleDebugPrint() { void toggleDebugPrint() {
isDebug = !isDebug; isDebug = !isDebug;
@ -205,24 +207,36 @@ class Parser {
tokens.push_back(semi); tokens.push_back(semi);
} }
} }
vector<Token> getTokens() {
return tokens;
}
}; };
class Interpreter { class Interpreter {
private: private:
vector<Token> tokens; vector<Token> tokens;
Logger log;
int tokenIndex = 0; int tokenIndex = 0;
Token consume() { Token consume() {
return tokens[tokenIndex++]; return tokens.at(tokenIndex++);
} }
Token peek(int index = 1) { Token peek(int index = 1) {
return tokens[tokenIndex + index]; return tokens.at(tokenIndex + index);
} }
public: public:
void interpret(vector<Token> tokenList) { void interpret(vector<Token> tokenList) {
tokens = tokenList; tokens = tokenList;
log.debug("Alright we got " + to_string(tokens.size()) + " tokens");
while (tokenIndex < tokens.size()) { 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.parseLines(file, log);
parser.processLines(); parser.processLines();
Interpreter interpreter;
interpreter.interpret(parser.getTokens());
return 0; return 0;
} }