Grammar Construction from Given Language!

611 Views Asked by At

Just a fast question!

I have this language L(G) = { z^n * x^2n with n>=1 }

What is the grammar ? 

I think it should rather be:

Non Terminals {S}
Terminals {z, x}

and

P= {S-> zSxxx , S->zxxx} .

Could anyone verify my answer ? I am not sure! cheers.

1

There are 1 best solutions below

0
On

Your grammar is generating $3$ $x$’s for each $z$, so you’re getting the language

$$\left\{z^nx^{3n}:n\ge 1\right\}$$

instead of

$$\left\{z^nx^{2n}:n\ge 1\right\}\;.$$

If $2n$ was a typo for $3n$, your grammar is fine; if you really did want $2n$, your productions should be $S\to zSxx\mid zxx$.