Ramanujan defined the polynomials ψ k (r, x) in his study of power series inversion. Berndt, Evans and Wilson obtained a recurrence relation for ψ k (r, x). In a different context, Shor introduced the polynomials Q(i, j, k) related to improper edges of a rooted tree, leading to a refinement of Cayley's formula. He also proved a recurrence relation and raised the question of finding a combinatorial proof. Zeng realized that the polynomials of Ramanujan coincide with the polynomials of Shor, and that the recurrence relation of Shor coincides with the recurrence relation of Berndt, Evans and Wilson. So we call these polynomials the Ramanujan-Shor polynomials, and call the recurrence relation the Berndt-Evans-Wilson-Shor recursion. A combinatorial proof of this recursion was obtained by Chen and Guo, and a simpler proof was recently given by Guo. From another perspective, Dumont and Ramamonjisoa found a context-free grammar G to generate the number of rooted trees on n vertices with k improper edges. Based on the grammar G, we find a grammar H for the Ramanujan-Shor polynomials. This leads to a formal calculus for the Ramanujan-Shor polynomials. In particular, we obtain a grammatical derivation of the Berndt-Evans-Wilson-Shor recursion. We also provide a grammatical approach to the Abel identities and a grammatical explanation of the Lacasse identity.