I am using python and CFG from nltk and importing a grammar like this:
grammar = CFG.fromstring(""" S -> NP VP NP -> Det N PP -> P NP VP