Create grammar to manipulate query monoids