s = np vp
np = dp adjp n | pn
dp = "the" | "a"
adjp = adj | adj adjp
adj = "pretty" | "green" | "pretentious"
n = "girl" | "guy"
pn = "John" | "Jane"
vp = tv np | iv
tv = "loved" | "hated"
iv = "laughed" | "wept"
Write a method parse that checks whether a given input string follows the rule.
Define helper methods if needed. There are multiple ways of doing it. Feel free to use our helper methods as well.