diff --git a/mx b/mx index 3adb443..c052949 100755 Binary files a/mx and b/mx differ diff --git a/src/Interpreter.cpp b/src/Interpreter.cpp index 0cfa023..5d8bf9d 100644 --- a/src/Interpreter.cpp +++ b/src/Interpreter.cpp @@ -239,6 +239,12 @@ void Interpreter::executeCode(vector tokens) { if (tokens.size() < i + 1) syntaxError.mathTooFewArgs(); if (tokens[i + 1].value.type != valtype::INT) syntaxError.mathTypeMismatch("Expected an int when subtracting from an int"); variables[varName].value = get(variables[varName].value) - get(tokens[i + 1].value.value); + } else if (tokens[i].keyword == keywords::SET) { + if (tokens.size() < i + 1) syntaxError.mathTooFewArgs(); + if (tokens[i + 1].value.type != valtype::INT) syntaxError.mathTypeMismatch("Expected an int when changing an int"); + variables[varName].value = get(tokens[i + 1].value.value); + } else { + syntaxError.mathCannotDoOperationOnType("unknown", "int"); } } else if (variables[varName].type == valtype::DEC) { if (tokens[i].keyword == keywords::INCREMENT) { @@ -253,6 +259,12 @@ void Interpreter::executeCode(vector tokens) { if (tokens.size() < i + 1) syntaxError.mathTooFewArgs(); if (tokens[i + 1].value.type != valtype::DEC) syntaxError.mathTypeMismatch("Expected an dec when subtracting from an dec"); variables[varName].value = get(variables[varName].value) - get(tokens[i + 1].value.value); + } else if (tokens[i].keyword == keywords::SET) { + if (tokens.size() < i + 1) syntaxError.mathTooFewArgs(); + if (tokens[i + 1].value.type != valtype::DEC) syntaxError.mathTypeMismatch("Expected a dec when changing a dec"); + variables[varName].value = get(tokens[i + 1].value.value); + } else { + syntaxError.mathCannotDoOperationOnType("unknown", "dec"); } } } else { diff --git a/src/Parser.cpp b/src/Parser.cpp index 54988d3..2b5666c 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -115,6 +115,7 @@ void Parser::processLines() { else if (ct == "-") token.keyword = keywords::SUBTRACT; else if (ct == "*") token.keyword = keywords::MULTIPLY; else if (ct == "/") token.keyword = keywords::DIVIDE; + else if (ct == "=") token.keyword = keywords::SET; else if (ct == "++") token.keyword = keywords::INCREMENT; else if (ct == "--") token.keyword = keywords::DECREMENT; else if (ct == "+=") token.keyword = keywords::ADDTO; diff --git a/src/SyntaxError.cpp b/src/SyntaxError.cpp index cb4aa49..2eb923f 100644 --- a/src/SyntaxError.cpp +++ b/src/SyntaxError.cpp @@ -30,7 +30,7 @@ void SyntaxError::unknownFn() { } void SyntaxError::mathTypeMismatch(string notes) { - cerr << "MathError: cannot add two different types together" << endl; + cerr << "MathError: cannot use two different types together" << endl; if (!notes.empty()) cerr << "Notes: " << notes << endl; exit(1); } diff --git a/src/common.h b/src/common.h index eb402d8..9da9965 100644 --- a/src/common.h +++ b/src/common.h @@ -16,7 +16,7 @@ enum class valtype { enum class keywords { IF, ELSE, WHILE, INT, DEC, STR, BOOL, FUN, RETURN, OPARE, CPARE, OBRAC, CBRAC, - ADDTO, SUBTRACTFROM, MULTIPLYTO, DIVIDEFROM, + SET, ADDTO, SUBTRACTFROM, MULTIPLYTO, DIVIDEFROM, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, LESS, GREATER, EQLESS, EQGREATER, INCREMENT, DECREMENT, diff --git a/test.mx b/test.mx index 116f4a7..d3c6c3b 100644 --- a/test.mx +++ b/test.mx @@ -2,4 +2,7 @@ print "dingusify"; let str bingus "heheheha its bingusing time"; print bingus; print 1 + 1; -let int myInt 3; \ No newline at end of file +let int myInt 3; +print myInt; +myInt = 5; +print myInt; \ No newline at end of file