<gh_stars>0
import nltk
#defining Contex Free Grammar
grammar = nltk.CFG.fromstring("""
    T1 -> '64' T8 T6 T8 T9 T9 '60' '59' T13 '62' T6 
    T2 -> T4 T4 T7 '64' T6 '52' '57' T7 '67' '64' T6 
    T3 -> '64' '66' '67' '69' '67' '66' '64' T6 
    T4 -> '57' '59' '55' '52' T5 '62' '61' '59' '61' '59' '57' T6 '57' T5 '60' '59' '57' 
    T5 -> '55' '57' '59' 
    T6 -> '59' '57' '55' 
    T7 -> T5 '55' '52' '52' 
    T8 -> T10 '54' T10 '66' T13 T11 T11 '59' '57' T6 T13 '62' 
    T9 -> '57' '55' T12 '55' '55' '55' '57' T12 '60' '60' T11 '60' T11 '60' '62' T8 
    T10 -> '64' T11 '59' '59' T11 '59' '57' '59' '59' '59' '59' '59' 
    T11 -> '62' '60' 
    T12 -> '57' '60' '64' T11 T6 
    T13 -> '67' '66' '64'      
  """)

sentence = '64 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 59 57 55 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 57 55 57 60 64 62 60 59 57 55 55 55 55 57 57 60 64 62 60 59 57 55 60 60 62 60 60 62 60 60 62 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 57 55 57 60 64 62 60 59 57 55 55 55 55 57 57 60 64 62 60 59 57 55 60 60 62 60 60 62 60 60 62 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 60 59 67 66 64 62 59 57 55'.split()
def parse(sent):
    #Returns nltk.Tree.Tree format output
    a = []
    parser = nltk.ChartParser(grammar)
    for tree in parser.parse(sent):
        a.append(tree)
    return(a[0])

#Gives output as structured tree
print(parse(sentence))

#Gives tree diagrem in tkinter window
parse(sentence).draw()
import nltk
#defining Contex Free Grammar
grammar = nltk.CFG.fromstring("""
    T1 -> '64' T8 T6 T8 T9 T9 '60' '59' T13 '62' T6 
    T2 -> T4 T4 T7 '64' T6 '52' '57' T7 '67' '64' T6 
    T3 -> '64' '66' '67' '69' '67' '66' '64' T6 
    T4 -> '57' '59' '55' '52' T5 '62' '61' '59' '61' '59' '57' T6 '57' T5 '60' '59' '57' 
    T5 -> '55' '57' '59' 
    T6 -> '59' '57' '55' 
    T7 -> T5 '55' '52' '52' 
    T8 -> T10 '54' T10 '66' T13 T11 T11 '59' '57' T6 T13 '62' 
    T9 -> '57' '55' T12 '55' '55' '55' '57' T12 '60' '60' T11 '60' T11 '60' '62' T8 
    T10 -> '64' T11 '59' '59' T11 '59' '57' '59' '59' '59' '59' '59' 
    T11 -> '62' '60' 
    T12 -> '57' '60' '64' T11 T6 
    T13 -> '67' '66' '64'      
  """)

sentence = '64 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 59 57 55 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 57 55 57 60 64 62 60 59 57 55 55 55 55 57 57 60 64 62 60 59 57 55 60 60 62 60 60 62 60 60 62 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 57 55 57 60 64 62 60 59 57 55 55 55 55 57 57 60 64 62 60 59 57 55 60 60 62 60 60 62 60 60 62 64 62 60 59 59 62 60 59 57 59 59 59 59 59 54 64 62 60 59 59 62 60 59 57 59 59 59 59 59 66 67 66 64 62 60 62 60 59 57 59 57 55 67 66 64 62 60 59 67 66 64 62 59 57 55'.split()
def parse(sent):
    #Returns nltk.Tree.Tree format output
    a = []
    parser = nltk.ChartParser(grammar)
    for tree in parser.parse(sent):
        a.append(tree)
    return(a[0])

#Gives output as structured tree
print(parse(sentence))

#Gives tree diagrem in tkinter window
parse(sentence).draw()
#defining Contex Free Grammar T1 -> '64' T8 T6 T8 T9 T9 '60' '59' T13 '62' T6      T2 -> T4 T4 T7 '64' T6 '52' '57' T7 '67' '64' T6      T3 -> '64' '66' '67' '69' '67' '66' '64' T6      T4 -> '57' '59' '55' '52' T5 '62' '61' '59' '61' '59' '57' T6 '57' T5 '60' '59' '57'      T5 -> '55' '57' '59'      T6 -> '59' '57' '55'      T7 -> T5 '55' '52' '52'      T8 -> T10 '54' T10 '66' T13 T11 T11 '59' '57' T6 T13 '62'      T9 -> '57' '55' T12 '55' '55' '55' '57' T12 '60' '60' T11 '60' T11 '60' '62' T8      T10 -> '64' T11 '59' '59' T11 '59' '57' '59' '59' '59' '59' '59'      T11 -> '62' '60'      T12 -> '57' '60' '64' T11 T6      T13 -> '67' '66' '64' #Returns nltk.Tree.Tree format output #Gives output as structured tree #Gives tree diagrem in tkinter window