This is usually done by exploiting standard dynamic programming techniques; see for instance (Seki et al., 1991).
1 the polynomial degree in the running time is a monotonically strictly increasing function that depends on both the rank and the fan-out of the productions in the grammar.