e
This commit is contained in:
parent
97bc3f447a
commit
da3d9a536b
27
src/main.cpp
27
src/main.cpp
|
@ -131,6 +131,26 @@ class Logger {
|
|||
}
|
||||
};
|
||||
|
||||
class SyntaxError {
|
||||
private:
|
||||
public:
|
||||
void fnTypeMismatch(string function, vector<string> 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<Token> 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<int>(nextToken.value.value));
|
||||
break;
|
||||
case valtype::DEC:
|
||||
exit(get<double>(nextToken.value.value));
|
||||
break;
|
||||
default:
|
||||
log.error("Unsupported value type");
|
||||
vector<string> validTypes = {"int", "dec"};
|
||||
syntaxError.fnTypeMismatch("exit", validTypes, nextToken.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user