grammar = nltk.parse_cfg(
    """
S -> NP VP
PP -> P NP
NP -> Det N | Det N PP | N
VP -> V NP | V PP
N -> 'Kim' | 'Dana' | 'everyone'
V -> 'arrived' | 'left' |'cheered'
P -> 'or' | 'and'
"""
    )
sent = 'Kim arrived or Dana left'.split()
parser = nltk.ChartParser(grammar)
print(parser.nbest_parse(sent))
sent = 'Kim arrived or Dana left and'.split()
parser = nltk.ChartParser(grammar)
print(parser.nbest_parse(sent))
sent = 'Kim arrived or Dana left and everyone'.split()
parser = nltk.ChartParser(grammar)
print(parser.nbest_parse(sent))
sent = 'Kim arrived or Dana left and everyone cheered'.split()
parser = nltk.ChartParser(grammar)
print(parser.nbest_parse(sent))
Python and NLTK: How to analyze sentence grammar?