@Override public Boolean visit(Neg ast) { boolean checkArg = ast.getArg().accept(this); if (!checkArg) return false; Type argType = ast.getArg().typeOf(env); if (!argType.isCompatibleToNumeric()) { addToErrorList( ast, "the unary operator - can not be applied to instances of type " + argType.getClass()); return false; } return true; }
// Unary Expressions @Override public Boolean visit(Neg exp) { Expr unExpr = exp.getExpr(); if (!(unExpr.typeOf(environment) == new IntType())) { errorMsgs.add(String.format("Neg expression is not numeric: %s", exp)); return false; } return unExpr.accept(this); }