Half working code
This commit is contained in:
parent
96f93ceb49
commit
ab07efcb86
|
@ -239,6 +239,12 @@ void Interpreter::executeCode(vector<Token> 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<int>(variables[varName].value) - get<int>(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<int>(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<Token> 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<double>(variables[varName].value) - get<double>(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<int>(tokens[i + 1].value.value);
|
||||
} else {
|
||||
syntaxError.mathCannotDoOperationOnType("unknown", "dec");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user