Sandbox tool

CFG Interpreter


An interpreter for context-free grammars, which are essentially basic procedural text generation rules.

How the grammar works

  • *X instantiates new symbol X if used at start of line, but references existing symbol X if used mid-line.
  • All possibilities for X come after the -.
  • X will choose with uniform randomness between its possibilities, divided by |, when it's written.
  • A possibility can reference another symbol directly, or it can be a terminal: a fully defined string.
  • Terminals can contain further symbol references inside angle brackets. If a terminal does this, it writes those symbols at the point where said symbol was referenced.
  • Symbol references can be modified by adding a period and modifier after the reference inside the angle brackets.
  • Current modifiers: .a prepends a/an, .cap capitalizes the first letter, .s pluralizes nouns, .ff gives the symbol a fifty-fifty chance of being included, and .uncap uncapitalizes the first letter.
  • Modifiers can be chained together and will operate as expected: X.a.cap writes symbol X with a/an prepended and capitalized.
  • Don't create infinite loops of symbols. You can. Don't do it.
  • There must be a symbol with the name S. This is the start symbol for processing.
  • All used characters (|"-*<) are forbidden from symbol names, though only " is forbidden from terminals.
  • Starting a line with a forward slash (/) makes that line a comment. Such lines still have to end with a semicolon, and semicolons are unfortunately banned for comments.

Output