# Constructing a Context Free Grammar for checking non-equality of strings [duplicate]

I have been studying the book Introduction to Computation by Michael Sipser on my own, and I'm stuck on this exercise from the chapter on Pushdown Automato and Context-Free Languages. The exercise is to show that $$A=\{x\#y\,|\, x \neq y\}$$ is a context-free language.

I'm having a hard time proving this because of the second string not reversed. I've tried both making a context-free grammar and a pushdown automata, but in both cases I can't figure out how to make/check that the initial characters of both $x$ and $y$ are the same.

I would appreciate any hints that could help me get to the answer.

• Because you are looking for the non-equality of the two strings you only need to find one position (in both strings) that does not contain equal characters. Can you see how to use non-determinism to do this? – Sam Jones Aug 22 '13 at 13:24
• Oh, I see! Yes, I got it from here, thank you very much! – Milind Aug 22 '13 at 14:07