Simon has studied Context-Free Grammar, following a set of tutorials from Daniel Shiffman’s ITP course “Programming from A to Z“. Context-Free Grammar is a set of recursive “replacement” rules to define the syntax of a language and to generate text: “Programming languages, for example, are context-free grammars — a compiler reads your code to make sure it conforms to specific rules and informs you of any errors. A context-free grammar, however, isn’t robust enough to describe the complexities of natural language. After all, they have no context! Natural languages can be described using Context-sensitive grammars, a concept introduced by Noam Chomsky in the 1950s”.
A great way to get started experimenting with Context-Free Grammar text generation is to use a library. As suggested in Daniel Shiffman’s course, Simon used Tracery, a JavaScript library by Kate Compton. With Tracery, all you need to do is setup your grammar as a JSON object. Simon followed the lesson to generate stories and had great fun:
Every time he hit a key, the values of the variables in his story changed:




The following day Simon programmed another grammar to generate haiku’s:

