implementation of the cyk algorithm