from nltk_lite import parse, tokenize

grammar = parse.cfg.parse_grammar('''
S -> NP V NP PP
S -> NP V NP
V -> "saw" | "ate"
NP -> "John" | "Mary" | "Bob" | Det N | Det N PP
Det -> "a" | "an" | "the" | "my"
N -> "dog" | "cat" | "cookie" | "park"
PP -> P NP
P -> "in" | "on" | "by" | "with"
''')
sent = list(tokenize.whitespace("Mary saw the cat in the park"))
rd_parser = parse.RecursiveDescent(grammar)
for p in rd_parser.get_parse_list(sent):
  print p


