Explain formal definition of language with examples in TOC?

Data Structure AlgorithmsComputer ScienceComputers

The set of all strings (over terminal symbols) which can be derived from the start symbol is the language generated by the grammar G.

Example 1

Let grammar G be defined by the set of terminals T = {a, b}, the only non-terminal start symbol S and the set of production rules. Hence, the grammar G would be as follows −

S → ∧, S → aSb

Or in shorthand, it is as mentioned below −

S → ∧ | aSb

L(G) = {∧, ab, aabb, aaabbb, . . . }


If G is called as a grammar with start symbol S and set of terminals T, then the language generated by G is the following set −

S → ∧ | aSb

L(G) = {s | s ∈ T* and S ⇒+ s}.

That is, it’s the set of all strings containing only terminal symbols which can be derived from the start symbol using one or more steps.

Example 2

Let ∑ = {a, b, c} be the set of terminal symbols and {A, S} be the set of non-terminal symbols with the start symbol S. A language L over ∑ is defined by the following productions −

S → b | aA, A → c | bS

Examples of strings which belong to the language L are as follows −

Clearly, we can generate b. All longer strings begin with a. All strings will either end with b or ac.

We can make the strings − b, ac, abb, abac, ababb, ababac, abababb, . . .

Is the following characterisation correct?

‘Any string from L contains a, b (in any order) and ends with either b or ac’

. . . NO!,

For example, ba, abaabac ∈/ L

Example 3

Let ∑ = {a, b, c} be the set of terminal symbols, S be the only non-terminal symbol. Which language is described by the following four productions?

S → ∧

S → aS

S → bS

S → cS

Or in shorthand − S → ∧ | aS | bS | cS.

Try to realize that all strings from ∑* can be generated by these rules and verify it for the string aacb.

S ⇒ aS ⇒ aaS ⇒ aacS ⇒ aacbS ⇒ aacb∧ = aacb

Hence, S ⇒*aacb.

Updated on 15-Jun-2021 11:54:25