Search code examples
context-free-grammarcomputation-theorycontext-free-language

What is the result of this CFG?


I have this example of free context grammar a(x^i) a(y^i). I wonder, if my accepted chains of letters would be something like axxx ayyy or would it be something like axaxayay.

Also for this grammar:

a(x^i)(y^i)(z^i), what kind of grammar would it accept? axxxyyyzzz or axyzaxyzaxyz?


Solution

  • I wonder, if my accepted chains of letters would be something like axxx ayyy or would it be something like axaxayay.

    It would be like axxxayyy, not axaxayay. The "^i" bit as shown applies only to x and y, not a, so you'd expect the a's to appear just once each. To get axaxayay you'd need (ax)^i (ay)^I. Note: the language corresponding to a(x^i) a(y^i) is context-free.

    Also for this grammar: a(x^i)(y^i)(z^i), what kind of grammar would it accept? axxxyyyzzz or axyzaxyzaxyz?

    Again, the "^i" bit applies only to x, y and z; so you'd expect strings of the form axxxyyyzzz but not axyzaxyzaxyz. To get axyzaxyzaxyz you'd need (axyz)^I. Note: the language corresponding to a(x^i)(y^i)(z^i) is not context-free.