fix message errors
This commit is contained in:
@ -130,11 +130,11 @@ void ASTSemanticCheckVisitor::ActuralVisit(JmpStatement_ASTNode *node) {
|
|||||||
has_return = true;
|
has_return = true;
|
||||||
node->return_value->accept(this);
|
node->return_value->accept(this);
|
||||||
if (cur_func_schema.return_type != node->return_value->expr_type_info) {
|
if (cur_func_schema.return_type != node->return_value->expr_type_info) {
|
||||||
throw SemanticError("Return type mismatch", 1);
|
throw SemanticError("Type Mismatch", 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (cur_func_schema.return_type != "void") {
|
if (cur_func_schema.return_type != "void") {
|
||||||
throw SemanticError("Return type mismatch", 1);
|
throw SemanticError("Type Mismatch", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ class MXErrorListener : public antlr4::BaseErrorListener {
|
|||||||
MXErrorListener() : no_problem(true) {}
|
MXErrorListener() : no_problem(true) {}
|
||||||
void syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offendingSymbol, size_t line,
|
void syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offendingSymbol, size_t line,
|
||||||
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override {
|
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override {
|
||||||
std::cout << "line " << line << ":" << charPositionInLine << " AT " << offendingSymbol->getText() << ": " << msg
|
// std::cerr << "line " << line << ":" << charPositionInLine << " AT " << offendingSymbol->getText() << ": " << msg
|
||||||
<< std::endl;
|
// << std::endl;
|
||||||
no_problem = false;
|
no_problem = false;
|
||||||
}
|
}
|
||||||
bool IsOk() { return no_problem; }
|
bool IsOk() { return no_problem; }
|
||||||
@ -79,6 +79,7 @@ void SemanticCheck(std::istream &fin, std::shared_ptr<Program_ASTNode> &ast_out)
|
|||||||
lexer.addErrorListener(&error_listener);
|
lexer.addErrorListener(&error_listener);
|
||||||
antlr4::CommonTokenStream tokens(&lexer);
|
antlr4::CommonTokenStream tokens(&lexer);
|
||||||
tokens.fill();
|
tokens.fill();
|
||||||
|
if (!error_listener.IsOk()) throw SemanticError("Invalid Identifier", 1);
|
||||||
MXParser parser(&tokens);
|
MXParser parser(&tokens);
|
||||||
parser.removeErrorListeners();
|
parser.removeErrorListeners();
|
||||||
parser.addErrorListener(&error_listener);
|
parser.addErrorListener(&error_listener);
|
||||||
|
Reference in New Issue
Block a user