Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lfa:lab10-cfl-closures [2020/12/07 09:14]
lfa
lfa:lab10-cfl-closures [2020/12/08 09:12] (current)
lfa
Line 3: Line 3:
 === Context-Free Grammar to Pushdown Automata === === Context-Free Grammar to Pushdown Automata ===
  
-**1.** Consider the following CFG:+** 1.** Consider the following CFG:
  
 $ S \leftarrow X\ |\ Y $ \\ $ S \leftarrow X\ |\ Y $ \\
Line 9: Line 9:
 $ Y \leftarrow YY\ |\ 1\ |\ \epsilon $ $ Y \leftarrow YY\ |\ 1\ |\ \epsilon $
  
-**1.1** Write a PDA which accepts L(G)+//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.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 ... \alpha_n $? +//1.3// In our PDA, $ (p, 111100, XZ0) \mapsto^* ​ (p, e, Z0) $. Write-down the steps. How is $ \alpha $ split into $ \alpha_1 ... \alpha_n $? \\ \\
  
  
Line 19: Line 19:
  
 **2.** Which of the following languages are Context-Free?​ Argue for your answer. **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.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\ ofBs\} $ \\
  
-**2.2.** $ L = \{w \in \{ab\}^*\ |\ eachsequenceofconsecutiveAsis\ followed\ bythe\ same\ number\ ofBs\} $ \\+//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.3.** $ L = \{a^{n}b^{2n}c^{m}\ |\ n, m \geq 0 \\cap \{a^{n}b^{m}c^{2m}|n\geq 0 \} $ \\+//2.4.// $ L = \{w \in \{ab\}^*\ |\ aandbcanbematched\ insequences,\ in\ any\ order \} $. Example : $ aabbbbaaaabb \in L $ \\
  
-**2.4.** $ L = \{w \in \{a, b\}^*\ |\ \#_a(w\eq \#_b(w\} $ \\+//2.5.// $ L = \{w \in \{a, b\}^*\ |\ w=a^nb^n ​and|w|\ \%\ 3\ =\ 0 \} $ \\
  
-**2.5.** $ L = \{w \in \{a, b\}^*\ |\ w=a^nb^n ​\|w\|\%3\leq0 $ \\+//2.6.// $ L = \{w \in \{a, b\}^*\ |\ \#_{a}(w)=\#_{b}(wandnob\ should\ be\ followed\ by\ two\ a \} $ \\
  
 +//2.7.// Give an example of two context-free languages whose intersection is context-free.
  
  
-**2.1.** +**3.** ​Show that the following ​are closed under CF languages:
- +
-$ 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?+
  
 +//3.1// Reversal \\
  
 +//3.2// $ init(L) = \{w\ \in\ \Sigma^*\ |\ \exists x\ such\ that\ wx\ \in\ L\}. $ //Hint//: Write a CNF grammar for init L, starting from a grammar for L.