$ G = \{\Sigma, V, R, S \} $
S - Starting symbol
V - Set of terminals and non-terminals
R - production rules ($ R \subseteq (V \setminus \Sigma) \times V^n $)
Property: Chomsky Normal Form (CNF) - A grammar in CNF is context-free.
S is the starting symbol.
Write CF grammar for the following languages. For each grammar, make sure it is not ambiguous. (Start with any CF grammar that accepts L. Then write another non-ambiguous grammar for the same language).
9.1.1. $ L = \{\: w \in \{a,b\}^* \ | \:w \text{ is a palindrome}\} $.
9.1.2. $ L = \{ a^{m} b^{m+n} c^{n} \ | \: n, m \geq 0 \} $
9.1.3. $ L = \{w \in \{a, b\}^* | \#_a(w) = \#_b(w) \} $
9.1.4. $ L = \{w \in \{a, b\}^* | \#_a(w) \neq \#_b(w) \} $
9.1.5. $ L = \{a^ib^jc^k | i = j \lor j = k \} $
Which of the following grammars are ambiguous? Justify each answer. Modify the grammar to remove ambiguity, wherever the case.
9.2.1.
$ S \leftarrow aA\ |\ A $
$ A \leftarrow aA\ |\ B $
$ B \leftarrow bB\ |\ \epsilon $
9.2.2.
$ S \leftarrow AS\ |\ \epsilon $
$ A \leftarrow 0A1\ |\ 01\ |\ B $
$ B \leftarrow B1\ |\ \epsilon $
9.2.3.
$ S \leftarrow ASB\ |\ BSA\ |\ \epsilon $
$ A \leftarrow aA\ |\ \epsilon $
$ B \leftarrow bB\ |\ \epsilon $
9.2.4. Write an ambiguous grammar for $ L(a^*) $.
Definition: A regular grammar is a CF grammar where the production rules follow one of these 2 patterns:
9.3.1. (warmup) Find a DFA or an NFA that accepts the language generated by the following regular grammar:
$ X \leftarrow 0X\ |\ 1Y $
$ Y \leftarrow 1Y\ |\ 0\ |\ \epsilon $
9.4.1. Prove that the languages accepted by regular grammars are exactly the regular languages