This is an old revision of the document!
Context Free Languages
Context-Free Grammar to Pushdown Automata
1. Consider the following CFG:
$ S \leftarrow X\ |\ Y $
$ X \leftarrow YXY\ |\ 0X\ |\ 0 $
$ Y \leftarrow YY\ |\ 1\ |\ \epsilon $
1.1 Write a PDA which accepts L(G)
1.2 Write a sequence of derivations which yeilds $ S\ \Rightarrow\ 110X1Y $ . What is it's corresponding sequence of transitions in the PDA?
1.3 In our PDA, $ (p, 111100, XZ0) \mapsto^* (p, e, Z0) $. Write-down the steps. How is $ \alpha $ split into $ \alpha_1 \ldots \alpha_n $?
Closure Properties of Context-Free Languages
2. Which of the following languages are Context-Free? Argue for your answer.
2.1. $ L = \{a^{n}b^{2n}c^{2m}d^{m}\ |\ n, m \geq 0 \} $
2.2. $ L = \{w \in \{a, b\}^*\ |\ each\ sequence\ of\ consecutive\ As\ is\ followed\ by\ the\ same\ number\ of\ Bs\} $
2.3. $ L = \{a^{n}b^{2n}c^{m}\ |\ n, m \geq 0 \} \cap \{a^{n}b^{m}c^{2m}\ |\ n, m \geq 0 \} $
2.4. $ L = \{w \in \{a, b\}^*\ |\ \#_a(w) \eq \#_b(w) \} $
2.5. $ L = \{w \in \{a, b\}^*\ |\ w=a^nb^n \|w\|\%3\leq0 $
2.1.
$ S \leftarrow aA | A $
$ A \leftarrow aA | B $
$ B \leftarrow bB | \epsilon $
2.2.
$ S \leftarrow AS | \epsilon $
$ A \leftarrow 0A1 | 01 | B $
$ B \leftarrow B1 | \epsilon $
2.3.
$ S \leftarrow ASB | BSA | \epsilon $
$ A \leftarrow aA | \epsilon $
$ B \leftarrow bB | \epsilon $
3. Write an ambiguous grammar for $ L(a^*) $.
Regular Grammars
4. Is the language described by the following grammar regular? If so, write a regular expression for it.
$ S \leftarrow aA $
$ A \leftarrow aA | B $
$ B \leftarrow Bb | \epsilon $
5. Write a regular expression for the language described by:
$ S \leftarrow aX $
$ X \leftarrow bY | S $
$ Y \leftarrow aX | bS | \epsilon $
6. Write a regular grammar for $ L((0 \cup 1^*)^*01^*) $.
Chomsky Normal Form
7. Remove “$ \epsilon \text{-rules} $” from the following grammar:
$ A \leftarrow \epsilon | B $
$ B \leftarrow b $
$ B \leftarrow ABC | BAC $
$ C \leftarrow AC | c$
8. Remove the “unit rules” from the previous grammar, after “$ \epsilon \text{-rules} $” have been removed.
9. Apply the CNF conversion rules to the solution for 1.1. Does the accepted language stay the same?