public void Visit(Ast.Expr.BinOp b) { Visit(b.Item.Lhs); Visit(b.Item.Rhs); if (b.Item.Lhs.ActualType == b.Item.Rhs.ActualType) { Ast.Binary op = b.Item.Op; // Determine type of b // Check if op is defined for operands if (op.IsOpMul || op.IsOpDiv || op.IsOpPlus || op.IsOpMinus) { // Arithmetic op b.ActualType = b.Item.Lhs.ActualType; if (!b.ActualType.IsIntType && !b.ActualType.IsFloatType) { m_errorList.Add("Type Error: Operator " + op + " is not defined for operands of type " + b.Item.Lhs.ActualType + " and " + b.Item.Rhs.ActualType); } } else { // Logic op b.ActualType = Ast.Type.BoolType; Ast.Type type = b.Item.Lhs.ActualType; if (!type.IsIntType && !type.IsFloatType && !type.IsBoolType) { m_errorList.Add("Type Error: Operator " + op + " is not defined for operands of type " + b.Item.Lhs.ActualType + " and " + b.Item.Rhs.ActualType); } } } else { m_errorList.Add("Type Error: Mismatch " + b.Item.Lhs.ActualType + " " + b.Item.Rhs.ActualType); } }
public void Visit(Ast.Expr.BinOp b) { Visit(b.Item.Lhs); Visit(b.Item.Rhs); }