#NEWLINE# def demo( ) : #NEWLINE# #INDENT# from nltk import Nonterminal , CFG #NEWLINE# nonterminals = 'S VP NP PP P N Name V Det' #NEWLINE# ( S , VP , NP , PP , P , N , Name , V , Det ) = [ Nonterminal ( s ) for s in nonterminals . split ( ) ] #NEWLINE# grammar = CFG . fromstring ( "\n    S -> NP VP\n    PP -> P NP\n    NP -> Det N\n    NP -> NP PP\n    VP -> V NP\n    VP -> VP PP\n    Det -> 'a'\n    Det -> 'the'\n    Det -> 'my'\n    NP -> 'I'\n    N -> 'dog'\n    N -> 'man'\n    N -> 'park'\n    N -> 'statue'\n    V -> 'saw'\n    P -> 'in'\n    P -> 'up'\n    P -> 'over'\n    P -> 'with'\n    " ) #NEWLINE# def cb( grammar ) : #NEWLINE# #INDENT# print ( grammar ) #NEWLINE# #UNINDENT# top = Tk ( ) #NEWLINE# editor = CFGEditor ( top , grammar , cb ) #NEWLINE# Label ( top , text = '\nTesting CFG Editor\n' ) . pack ( ) #NEWLINE# Button ( top , text = 'Quit' , command = top . destroy ) . pack ( ) #NEWLINE# top . mainloop ( )