How to write a production rule for the power set of a given set
I am writing a small command language. The language开发者_StackOverflow has a few simple commands, which can be composed to make complex ones. For example, if we have commands fry an egg
, make a sandwich
, make coffee
, we can create a new command :
make a breakfast := fry an egg, make a sandwich, make coffee
.
However sometimes, I want only coffee for breakfast, sometimes both coffee and sandwich, etc. That is, make a breakfast
can be any subset of commands set: {fry an egg, make a sandwich, make coffee}
Thus I need a rule to define a power set of a given set of simple commands. Does it make sense ? Can I do that ?
It looks like you use (E)BNF grammar notation. If your question is about how to capture powerset in a grammar rule. AFAIK (E)BNF allows only to describe context-free grammars, however the powerset can be modeled as a language {a^2^n} in alphabet {a}, which is context sensitive. This means, you cannot use (E)BNF to describe any powerset. However what you can do, is to enumerate the specific powerset. For example: S := (a,{b, {c}}|(b, {c})|c|epsilon); This language is powerset of the {a,b,c} alphabet.
精彩评论