eignnx / affix-grammar

An affix-grammar format and sentence generator.
Mozilla Public License 2.0
0 stars 0 forks source link

increase expressive power #9

Open eignnx opened 4 years ago

eignnx commented 4 years ago

im feelin like rn this isnt powerful enough. you can specify a grammar in a relatively compact way, but it's hard to make something that is more than the sum of its parts. i think there needs to be more expressive power in order to keep the language interesting.

Idea

lets add mutable state back in and see what happens.

Example

from the old semantics:

start --> {character: animal} "There once was a" character "who told a story: '" + (start)[prev_character]
          "The end', said" character "with a" action + "."
          "Did you like that story about the" prev_character + "?"
          {prev_character: character}
        | {character: "potato"} "I ate a potato last week." {prev_character: "potato"}
        ;

animal --> "Penguin" {action: "waddle"}
         | "Chimp" {action: "climb"}
         | "Fish" {action: "blub"}
         | "Kangaroo" {action: "hop"}
         | "Lobster" {action: "snap"}
         ;

possible translation into new semantics/syntax:

rule start
  = {character: Animal} "There once was a" character "who told a story: '"
  + (start){prev_character} "The end', said" character "with a" action.character + "."
  "Did you like that story about the" prev_character + "?" {prev_character: character}
  | {character: "potato"} "I ate a potato last week." {prev_character: "potato"}

rule action.Animal =
  .penguin -> "waddle"
  .chimp -> "climb"
  .fish -> "blub"
  .kangaroo -> "hop"
  .lobster -> "snap"

data Animal
  = penguin ("Penguin")
  | chimp ("Chimp")
  | fish ("Fish")
  | kangaroo ("Kangaroo")
  | lobster ("Lobster")