Describing indefinitely nested language generated by Context-Free Grammar

32 Views Asked by At

Grammar:

$G=\{\{A, B, C\}, \{d_0, d_1\}, P, d_0\}$

Productions:

$ 1) d_0 \rightarrow Ad_1 \\ 2) d_1 \rightarrow Ad_1B \\ 3) d_1 \rightarrow Bd_1A \\ 4) d_1 \rightarrow C \\ 5) d_1 \rightarrow Cd_1 $

How can I describe language generated by this language? I know how to describe simple languages like: $L(G) = \{ (10)^n0^m | n \geq 0, m \geq 2 \}$ but this grammar generates language that can be indefinitely nested - we need to start from $A$ but then we can have $A$ then $B$ then again $A$ or $C$ then $B$ etc.. What's the proper way to show that?

1

There are 1 best solutions below

0
On BEST ANSWER

This is indeed a language that is a bit hard to describe. So to start with let us only look at rules 1-4. 1) generates one $A$ on the left in the beginning, 4) generates one $C$ and terminates the derivation.

The rules 2) and 3) generate palindromes $ww^R$ where $w^R$ is the reverse of $w$. So the resulting language is: $$\{AwCw^R: w\in \{A,B\}^* \}.$$

What rule 5) does is insertion of an arbitrary number of $C$ at any point in $w$ and also immediately preceding or following it but not in $w^R$. There is no common notation denoting this. A slightly complicated way could be: $$\{AC^*x_1C^*x_2C^*\cdots C^*x_n C^+ x_n\cdots x_2x_1: x\in \{A,B\}, n\in\{0,1,2,\dots\} \}.$$