def edit_grammar(self, *e): CFGEditor(self._top, self._parser.grammar(), self.set_grammar)
open_factor -> "(" close_factor -> ")" open_set -> {open_set} close_set -> {close_set} zero -> "0" not_zero -> {numbers} letter -> {letters} """.format( open_set='"{"', close_set='"}"', numbers="|".join(map(lambda x: '"%s"' % x, string.digits[1:])), letters="|".join(map(lambda x: '"%s"' % x, string.ascii_letters)), ) grammar = nltk.CFG.fromstring(grammar_text) if __name__ == '__main__': rd_parser = nltk.ChartParser(grammar) res = rd_parser.parse("Set1={1,2,3}") print(list(res)) top = Tk() editor = CFGEditor(top, grammar, print) top.mainloop()