I am trying to design a contextfree grammar for the language
Solution
A)
If we start the grammar with S -> 1S0, then no matter in what way the S in the middle is substituted, it will always end with 0. Similar if we start the grammar with S -> 0S1, then no matter in what way the S in the middle is substituted, it will always end with 1.
The language this grammar generates has equal number of 0’s and 1’s however it always starts and ends up with different symbols.
Hence, any string which starts and ends with the same symbol (and has equal number of 1\'s and 0\'s) can be given as an example of contradiction.
Examples are 1001, 0110, etc.
------------------------------------------------------------------------------------------------------------------
B)
To fix it add a grammar rule S -> SS to the grammar. This ensures that strings which start and end with same symbol and have equal number of 1’s and 0’s are also generated.
Complete grammar is the following:
S -> e
S -> SS
S -> 1S0
S -> 0S1
If you have any queries regarding any of the above, please ask in the comments and I will make sure to help you with it.
