Skip to content

Instantly share code, notes, and snippets.

@JakeCoxon
Last active August 29, 2015 14:01
Show Gist options
  • Save JakeCoxon/84e4a91756d701e6483b to your computer and use it in GitHub Desktop.
Save JakeCoxon/84e4a91756d701e6483b to your computer and use it in GitHub Desktop.
String/Graph grammar
val form1 = StringForm("aAabBbaB")
val grammar1 = new StringGrammar(
"A" -> "aAB",
"A" -> "aa",
"B" -> "bbbb")
val derivation1 = StringDerivation("aAB")
form1.applyFirst(grammar1)
form1.applyFirst(derivation1)
val form2 = GraphForm("A->b A->c c->d")
val grammar2 = GraphGrammar(
"A(a b c)" -> "A->a A->b A->c")
val derivation1 = GraphDerivation("a b c", "A->a A->b A->c")
form2.applyFirst(grammar2)
form2.applyFirst(derivation2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment