void connect() throws ScriptException {

		final float[] distances = new float[2];
		BitSet[] atomSets = new BitSet[2];
		atomSets[0] = atomSets[1] = viewer.getSelectionSet();

		int distanceCount = 0;
		int atomSetCount = 0;
		short bondOrder = JmolConstants.BOND_ORDER_NULL;
		int operation = JmolConstants.MODIFY_OR_CREATE;
		boolean isDelete = false;
		boolean haveType = false;
		int nAtomSets = 0;
		int nDistances = 0;
		/*
		 * connect [<=2 distance parameters] [<=2 atom sets] [<=1 bond type] [<=1 operation]
		 */

		if (statementLength == 1) {
			viewer.rebond();
			return;
		}

		for (int i = 1; i < statementLength; ++i) {
			switch_tag: switch (statement[i].tok) {
			case Token.on:
			case Token.off:
				if (statementLength != 2)
					badArgumentCount();
				viewer.rebond();
				return;
			case Token.integer:
			case Token.decimal:
				if (++nDistances > 2)
					badArgumentCount();
				if (nAtomSets > 0 || haveType)
					invalidParameterOrder();
				distances[distanceCount++] = floatParameter(i);
				break;
			case Token.expressionBegin:
				if (++nAtomSets > 2)
					badArgumentCount();
				if (haveType)
					invalidParameterOrder();
				atomSets[atomSetCount++] = expression(statement, i);
				i = pcLastExpressionInstruction; // the for loop will increment i
				break;
			case Token.identifier:
			case Token.hbond:
				String cmd = (String) statement[i].value;
				for (int j = JmolConstants.bondOrderNames.length; --j >= 0;) {
					if (cmd.equalsIgnoreCase(JmolConstants.bondOrderNames[j])) {
						if (haveType)
							incompatibleArguments();
						cmd = JmolConstants.bondOrderNames[j];
						bondOrder = JmolConstants.getBondOrderFromString(cmd);
						haveType = true;
						break switch_tag;
					}
				}
				if (++i != statementLength)
					invalidParameterOrder();
				if ("modify".equalsIgnoreCase(cmd))
					operation = JmolConstants.connectOperationFromString(cmd);
				else if ("create".equalsIgnoreCase(cmd))
					operation = JmolConstants.connectOperationFromString(cmd);
				else if ("modifyOrCreate".equalsIgnoreCase(cmd))
					operation = JmolConstants.connectOperationFromString(cmd);
				else if ("auto".equalsIgnoreCase(cmd))
					operation = JmolConstants.connectOperationFromString(cmd);
				else unrecognizedSubcommand(cmd);
				break;
			case Token.none:
			case Token.delete:
				if (++i != statementLength)
					invalidParameterOrder();
				operation = JmolConstants.connectOperationFromString("delete");
				isDelete = true;
				break;
			default:
				invalidArgument();
			}
		}
		if (distanceCount < 2) {
			if (distanceCount == 0)
				distances[0] = JmolConstants.DEFAULT_MAX_CONNECT_DISTANCE;
			distances[1] = distances[0];
			distances[0] = JmolConstants.DEFAULT_MIN_CONNECT_DISTANCE;
		}
		int n = viewer.makeConnections(distances[0], distances[1], bondOrder, operation, atomSets[0], atomSets[1]);
		if (isDelete)
			viewer.scriptStatus(GT._("{0} connections deleted", n));
		else viewer.scriptStatus(GT._("{0} connections modified or created", n));
	}