def cky(cfg, sentence): A = Agenda() for item in cky_axioms(cfg, sentence): A.push(item) while A: item = A.pop() if item.is_complete() or is_nonterminal(item.next): for new in complete(item, A): A.push(new) else: new = scan(item, sentence) if new is not None: A.push(new) A.make_passive(item) return make_forest(A.itercomplete())