# Explain the relationship between grammar and language in TOC

In order to understand the relationship between the grammar and language in the theory of computation (TOC), let us understand what is language generated by grammar in TOC.

## Language generated by grammar

The grammar is S-> aSb| E.

In this grammar, by using S-> E, we can generate E.

Therefore, E is part of L(G).

Similarly, by using S=>aSb=>ab, ab is generated.

Similarly, aabb can also be generated.

Therefore, the result is as follows −

L(G) = {anbn, n>0}

In language L(G) which is discussed above, the condition n =0 is taken to accept the epsilon.

Consider the grammar given below

S -> aSa | bSb | a |b

Now, let us find out what language is generated by the above grammar over the alphabet {a,b}.

## Explanation

Using S->a and S->b,

a and b can be generated.

Similarly by using S->aSa

->aba

aba can be generated.

Other strings which can be generated from grammar are as follows −

a,b,aba,bab,aaa,bbb,ababa,.....

Therefore, the language generated for the given grammar over the alphabet {a,b} is the set of all odd length palindromes.