Is there a Context-free grammar
for the following language:
$L=\{ x\#1^m|x \in \{0,1\}^* \text{ and the $m^{\text{th}}$ char in $x$ is 1} \}$
If so what is it? Because i couldn't find any. I also tried to prove there isn't (by the Pumping lemma for context-free languages), but it's given that a Context-free grammar
does exist and I found an error in my "proof".
So what would be the grammar?
Here's the big picture of my proof:
Let's choose $m=n_0$ and take the word $w=0^{n_0}1\#1^{n_0+1}$ (so that $x$ is what's on the left side of $\#$) .
According to the lemma, $w$ can be written as $uvxyz$ and some conditions hold...
$|vxy| \leq n_0$
therefor, $vxy$ include only zeros ($0$'s).
Now let's choose k=2
and pump it up:
we get: $w_2=uv^2xy^2z$
which means, the number of $0$'s is now:
$n_0 + |v| + |y| \geq n_0 + 1$
(since $|vy| \geq 1$) .
Hence, the $m$th number (the $n_0$th in our case) is not $1$. It's actually $0$.
Hence, $w_2$ doesn't belong to $L$. Contradiction.
Hence, $L$ isn't Context-free
.
I think i know where's my mistake in the proof:
$vxy$ isn't necessarily only $0$'s. It could have the last $n_0-1$ zero's and a $1$.