private void checkBalance(List<Token> tokens) {
        int count = 0;
        for (Token token : tokens) {
            if (token == OPEN) {
                count++;
            } else if (token == CLOSE) {
                count--;
            }
            if (count < 0) {
                throw new ParseException("Closing parenthesis without opening parenthesis");
            }
            if (token == SEPARATOR && count == 0) {
                throw new ParseException("Comma outside of parenthesis");
            }
        }

        if (count != 0) {
            throw new ParseException(count > 0
                    ? "Closing parenthesis is missing"
                    : "Too many closing parentheses");
        }
    }