Skip to content

Instantly share code, notes, and snippets.

@wuerges
Created July 12, 2017 02:16
Show Gist options
  • Save wuerges/6f05cdd78f445540624f21d392bf5a93 to your computer and use it in GitHub Desktop.
Save wuerges/6f05cdd78f445540624f21d392bf5a93 to your computer and use it in GitHub Desktop.
p1 = "<S> ::= a<A> | a<C> | b<B> | b<C>\n<A> ::= a<F> | a<G>\n<B> ::= b<F> | b<G>\n<C> ::= a<A> | a<C> | b<B> | b<C>\n<F> ::= a<F> | b<F> | a<G> | b<G>\n<G> ::= &\n"
p2 = p1.split('\n')
p3 = map(lambda x : x.split('::='), p2)
p4 = list(map(lambda x : list(map(lambda y: y.split('|'), x)), p3))
print(p4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment