We consider context-free grammars of the form G={f.fb1+b2+1ga1+a2,g.fb1ga1+1}, where a i and b i are integers subject to certain positivity conditions. Such a grammar G gives rise to triangular arrays {T(n, k)}0.k.n satisfying a three-term recurrence relation. Many combinatorial sequences can be generated in this way. Let T n (x) = . nk=0 T(n, k)x k. Based on the differential operator with respect to G, we define a sequence of linear operators P n such that T n+1(x) = P n (T n (x)). Applying the characterization of real stability preserving linear operators on the multivariate polynomials due to Borcea and Brändén, we obtain a necessary and sufficient condition for the operator P n to be real stability preserving for any n. As a consequence, we are led to a sufficient condition for the real-rootedness of the polynomials defined by certain triangular arrays, obtained by Wang and Yeh. Moreover, as special cases we obtain grammars that lead to identities involving the Whitney numbers and the Bessel numbers.