diff --git a/main b/main deleted file mode 100755 index adccdbc..0000000 Binary files a/main and /dev/null differ diff --git a/mx b/mx index a8dd211..b3f0eb9 100755 Binary files a/mx and b/mx differ diff --git a/src/main.cpp b/src/main.cpp index 2dc7530..802fcde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,6 +131,26 @@ class Logger { } }; +class SyntaxError { + private: + public: + void fnTypeMismatch(string function, vector validTypes, valtype typeGiven) { + cout << "TypeError: function type mismatch" << endl; + cout << "Function '" << function << "' expected one of the following types: "; + for (int i = 0; i < validTypes.size(); i++) { + if (i != 0) cout << ", "; + cout << validTypes[i]; + } + cout << endl << "Got type '"; + if (typeGiven == valtype::INT) cout << "int"; + else if (typeGiven == valtype::DEC) cout << "dec"; + else if (typeGiven == valtype::STR) cout << "str"; + else if (typeGiven == valtype::BOOL) cout << "bool"; + else cout << "unknown"; + cout << "' instead" << endl; + } +}; + class Parser { private: string buffer; @@ -333,6 +353,7 @@ class Interpreter { } } void executeCode(vector tokens) { + SyntaxError syntaxError; for (int i = 0; i < tokens.size(); i++) { if (tokens[i].keyword == keywords::PRINT) { i++; @@ -368,8 +389,12 @@ class Interpreter { case valtype::INT: exit(get(nextToken.value.value)); break; + case valtype::DEC: + exit(get(nextToken.value.value)); + break; default: - log.error("Unsupported value type"); + vector validTypes = {"int", "dec"}; + syntaxError.fnTypeMismatch("exit", validTypes, nextToken.type); } } } @@ -404,4 +429,4 @@ int main(int argc, char* argv[]) { // Convert to tokens and run the code interpreter.convertToTokens(parser.getTokens()); return 0; -} \ No newline at end of file +} diff --git a/test.mx b/test.mx index bd922a6..c8691f5 100644 --- a/test.mx +++ b/test.mx @@ -1,2 +1,2 @@ print "Hello world!"; -exit 1; \ No newline at end of file +exit fjdskfdkls;