python
toc3unknown
plain_text
24 days ago
621 B
1
Indexable
def gen_der(productions,start_symbol,max_derivations=10): derivations=[start_symbol] for i in range(max_derivations): next_derivation="" for symbol in derivations[-1]: for production in productions: lhs,rhs=production.split("->") if symbol==lhs: next_derivation+=rhs if next_derivation=="": break derivations.append(next_derivation) return derivations production=[ "S->aSb", "S->ab", ] start_symbol="S" print(gen_der(productions,start_symbol))
Editor is loading...
Leave a Comment