This commit is contained in:
Maxwell 2025-04-30 13:38:33 +10:00
parent 3eadd01cfa
commit bd509560a9
11 changed files with 47 additions and 18 deletions

View File

@ -1,4 +1,4 @@
compiler "g++";
binary "mx";
binary "bogus";
source "src/*.cpp";
compile;

BIN
bogus Executable file

Binary file not shown.

BIN
mx

Binary file not shown.

View File

5
password.bo Normal file
View File

@ -0,0 +1,5 @@
print "Enter your password: ";
let str passwdInput input;
if passwdInput == "dingus" {
println "Thank you for entering the right password.";
}

View File

@ -14,16 +14,16 @@ ArgParser::ArgParser(int argc, char* argv[]) {
debugMode = true;
args.erase(args.begin() + i);
} else if (args[i] == "--help") {
cout << "mxlang interpreter" << endl;
cout << "Usage: mx [file]" << endl;
cout << "Boguslang interpreter" << endl;
cout << "Usage: bogus [file]" << endl;
cout << "Options:" << endl;
cout << " --debug Enable debug mode" << endl;
cout << " --help Show this help message" << endl;
cout << "Issues? Send an email to max@maxwellj.xyz" << endl;
cout << "Report bugs at https://git.maxwellj.xyz/max/mx" << endl;
cout << "Report bugs at https://git.maxwellj.xyz/max/bogus" << endl;
exit(0);
} else if (args[i] == "--version") {
cout << "mxlang, version 0.0.2" << endl;
cout << "Boguslang, version 0.0.3" << endl;
exit(0);
}

View File

@ -1,4 +1,5 @@
#include "Interpreter.h"
#include "common.h"
optional<Token> Interpreter::consume() {
tokenIndex++;
@ -43,12 +44,26 @@ void Interpreter::convertToTokens(vector<Token> tokenList) {
auto varIt = variables.find(potentialVarName);
if (varIt != variables.end()) {
// Replace the token with the variable's value
Token newToken;
newToken.keyword = keywords::VALUE;
newToken.type = varIt->second.type;
newToken.value = varIt->second;
currentInstruction[i] = newToken;
// This is pretty crappy code but it exists for now. Lists are gonna break this so much it's not even gonna be funny
if (varIt->second.type == valtype::LIST) {
if (peek()->keyword == keywords::OSQUA) {
if (peek(2)->keyword == keywords::VALUE && peek(2)->type == valtype::INT && peek(2)->type == valtype::INT && peek(3)->keyword == keywords::CSQUA) {
Token newToken;
Value tokenVal = get<List>(varIt->second.value).value[get<int>(peek(2)->value.value)];
newToken.keyword = keywords::VALUE;
newToken.type = tokenVal.type;
newToken.value.value = tokenVal.value;
// Do this later
}
}
} else {
// Replace the token with the variable's value
Token newToken;
newToken.keyword = keywords::VALUE;
newToken.type = varIt->second.type;
newToken.value = varIt->second;
currentInstruction[i] = newToken;
}
}
} else if (currentInstruction[i].keyword == keywords::INPUT) {
Token newToken;
@ -405,4 +420,4 @@ void Interpreter::executeCode(vector<Token> tokens) {
}
}
}
}
}

View File

@ -131,6 +131,8 @@ void Parser::processLines() {
else if (ct == "<") token.keyword = keywords::LESS;
else if (ct == ">") token.keyword = keywords::GREATER;
else if (ct == "//") token.keyword = keywords::COMMENT;
else if (ct == "[") token.keyword = keywords::OSQUA;
else if (ct == "]") token.keyword = keywords::CSQUA;
else {
token.keyword = keywords::VALUE;
// Convert the value based on its type

View File

@ -10,12 +10,12 @@
using namespace std;
enum class valtype {
INT, DEC, STR, BOOL, KEYWORD, UNKNOWN
INT, DEC, STR, BOOL, LIST, KEYWORD, UNKNOWN
};
enum class keywords {
IF, ELSE, WHILE, INT, DEC, STR, BOOL, FUN, RETURN,
OPARE, CPARE, OBRAC, CBRAC,
OPARE, CPARE, OBRAC, CBRAC, OSQUA, CSQUA, COMMA,
SET, ADDTO, SUBTRACTFROM, MULTIPLYTO, DIVIDEFROM,
ADD, SUBTRACT, MULTIPLY, DIVIDE,
EQUAL, INEQUAL, LESS, GREATER, EQLESS, EQGREATER,
@ -25,9 +25,16 @@ enum class keywords {
COMMENT
};
struct Value;
struct List {
valtype type;
vector<Value> value;
};
struct Value {
valtype type;
variant<int, double, string, bool> value;
variant<int, double, string, bool, List> value;
};
struct Token {

View File

@ -1,4 +1,4 @@
let str thing2 "dingus";
let str thing1 "dingus";
let str thing2 "dingus";
if thing1 == thing2 {
@ -9,4 +9,4 @@ print "this is printing something without a new line";
println " this is coming from a seperate print statement lols";
print "Say some wise words... ";
println "Ah, '" + input + "', some very wise words indeed!";
println "Ah, '" + input + "', some very wise words indeed!";

View File

@ -2,4 +2,4 @@
bob
./mx test.mx
./bogus test.bo