コード例 #1
0
 @Override
 public Boolean visit(Not exp) {
   Expr unExpr = exp.getExpr();
   if (!(unExpr.typeOf(environment) == new BoolType())) {
     errorMsgs.add(String.format("Not expression is not a boolean: %s", exp));
     return false;
   }
   return unExpr.accept(this);
 }
コード例 #2
0
  private boolean isBinaryBooleanOrNumeric(BinaryExpr exp) {
    Expr left = exp.getLeft();
    Expr right = exp.getRight();

    if (left.accept(this) && right.accept(this))
      return ((left.typeOf(environment).equals(new IntType())
              && right.typeOf(environment).equals(new IntType()))
          || left.typeOf(environment).equals(new BoolType())
              && right.typeOf(environment).equals(new BoolType()));
    else return false;
  }