In this paper we investigate a class of backward stochastic differential equations (BSDE) whose terminal values are allowed to depend on the history of a forward diffusion. We first establish a probabilistic representation for the spatial gradient of the viscosity solution to a quasilinear parabolic PDE in the spirit of the Feynman--Kac formula, without using the derivatives of the coefficients of the corresponding BSDE. Such a representation then leads to a closed-form representation of the martingale integrand of a BSDE, under only a standard Lipschitz condition on the coefficients. As a direct consequence we prove that the paths of the martingale integrand of such BSDEs are at least c\`{a}dl\`{a}g, which not only extends the existing path regularity results for solutions to BSDEs, but contains the cases where existing methods are not applicable. The BSDEs in this paper can be considered as the nonlinear wealth processes appearing in finance models; our results could lead to efficient Monte Carlo methods for computing both price and optimal hedging strategy for options with nonsmooth, path-dependent payoffs in the situation where the wealth is possibly nonlinear.