Construct a grammar that generates the language $L = \{ a^x b^{x-y} c^y \mid x > y > 0 \text{ and } (x + y) \text{ is even }\}$

145 Views Asked by At

I have the following problem:

Construct a grammar that only generates the strings that belong to the language $L$ where: $$ L = \{ a^x b^{x-y} c^y \mid x > y > 0 \text{ and }(x + y) \text{ is even} \} $$

From which I deduced that:

  1. $x$ and $y$ have to both be either odd or even for their sum to be even.

But how to I proceed in generating the grammar. This language is a bit confusing to me.

1

There are 1 best solutions below

0
On BEST ANSWER

I think i found a context-free grammar that does this. Let $S$ be the start symbol.

  1. $S \to aQc$
  2. $Q \to aQc$
  3. $Q \to aaRbb$
  4. $R \to aaRbb$
  5. $R \to \epsilon$.

Some explanations: 1. is to ensure that $y>0$, there has to be at least one $c$. 2. Increase both $x$ and $y$ by $1$. 3. Increase $x$ by 2, ensuring that there is at least one $b$ (because $x>y$). 4. Increase $x$ by 2, if necessary. We cannot increase by one, because $x,y$ need to have the same parity.