def get_sentence(start=None, depth=<NUM_LIT:7>):
if not GRAMMAR:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>start = start if start else GRAMMAR.start()<EOL>if isinstance(start, Nonterminal):<EOL><INDENT>productions = GRAMMAR.productions(start)<EOL>if not depth:<EOL><INDENT>terminals = [p for p in productions if not isinstance(start, Nonterminal)]<EOL>if len(terminals):<EOL><INDENT>production = terminals<EOL><DEDENT><DEDENT>production = random.choice(productions)<EOL>sentence = []<EOL>for piece in production.rhs():<EOL><INDENT>sentence += get_sentence(start=piece, depth=depth-<NUM_LIT:1>)<EOL><DEDENT>return sentence<EOL><DEDENT>else:<EOL><INDENT>return [start]<EOL><DEDENT>
follow the grammatical patterns to generate a random sentence