diff --git a/src/ast/semanticvisitor.cpp b/src/ast/semanticvisitor.cpp index 24c2415..b244644 100644 --- a/src/ast/semanticvisitor.cpp +++ b/src/ast/semanticvisitor.cpp @@ -130,11 +130,11 @@ void ASTSemanticCheckVisitor::ActuralVisit(JmpStatement_ASTNode *node) { has_return = true; node->return_value->accept(this); if (cur_func_schema.return_type != node->return_value->expr_type_info) { - throw SemanticError("Return type mismatch", 1); + throw SemanticError("Type Mismatch", 1); } } else { if (cur_func_schema.return_type != "void") { - throw SemanticError("Return type mismatch", 1); + throw SemanticError("Type Mismatch", 1); } } } diff --git a/src/semantic/semantic.cpp b/src/semantic/semantic.cpp index 89bbdea..5f44acf 100644 --- a/src/semantic/semantic.cpp +++ b/src/semantic/semantic.cpp @@ -14,8 +14,8 @@ class MXErrorListener : public antlr4::BaseErrorListener { MXErrorListener() : no_problem(true) {} void syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offendingSymbol, size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override { - std::cout << "line " << line << ":" << charPositionInLine << " AT " << offendingSymbol->getText() << ": " << msg - << std::endl; + // std::cerr << "line " << line << ":" << charPositionInLine << " AT " << offendingSymbol->getText() << ": " << msg + // << std::endl; no_problem = false; } bool IsOk() { return no_problem; } @@ -79,6 +79,7 @@ void SemanticCheck(std::istream &fin, std::shared_ptr &ast_out) lexer.addErrorListener(&error_listener); antlr4::CommonTokenStream tokens(&lexer); tokens.fill(); + if (!error_listener.IsOk()) throw SemanticError("Invalid Identifier", 1); MXParser parser(&tokens); parser.removeErrorListeners(); parser.addErrorListener(&error_listener);