Constructs probabilistic context free grammars for an input