-
Notifications
You must be signed in to change notification settings - Fork 7
/
chap2_CNF1.tex
123 lines (114 loc) · 3.06 KB
/
chap2_CNF1.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
\input{header}
\AtBeginSubsection[]
{
\begin{frame}<beamer>
\frametitle{Outline}
\tableofcontents[current,currentsubsection]
\end{frame}
}
\begin{document}
\begin{frame}[allowframebreaks] \frametitle{Chomsky normal form (CNF)}
\begin{itemize}
\item Purpose: a simplified form of grammars
\item Every rule must be either
\begin{equation*}
A \rightarrow BC
\end{equation*}
or
\begin{equation*}
A \rightarrow a
\end{equation*}
\item $B,C$ are not start variables
\item $a \in\Sigma $ so
\begin{equation*}
A \rightarrow \epsilon
\end{equation*}
is not allowed.
\item However,
\begin{equation*}
S \rightarrow \epsilon
\end{equation*}
is allowed, where $S$ is the start
variable
\item This form is useful later (but not in this chapter)
\item To convert a CFG to a CNF, let's show an example first
\end{itemize}\end{frame}
\begin{frame}[allowframebreaks] \frametitle{Example to convert CFG to CNF}
\begin{itemize}
\item The original CFG
\begin{eqnarray*}
&& S \rightarrow ASA\mid aB\\
&& A \rightarrow B\mid S\\
&& B \rightarrow b \mid \epsilon\\
\end{eqnarray*}
\item Add
\begin{equation*}
S_0 \rightarrow S
\end{equation*}
because the start variable cannot be on the right
\begin{eqnarray*}
&& S_0 \rightarrow S\\
&& S \rightarrow ASA\mid aB\\
&& A \rightarrow B\mid S\\
&& B \rightarrow b \mid \epsilon\\
\end{eqnarray*}
\item Remove
\begin{equation*}
B \rightarrow \epsilon
\end{equation*}
because $\epsilon$ cannot be on the right
\begin{eqnarray*}
&& S_0 \rightarrow S\\
&& S \rightarrow ASA\mid aB|\alert{a}\\
&& A \rightarrow B\mid \alert{\epsilon} \mid S\\
&& B \rightarrow b\\
\end{eqnarray*}
\item Remove $A\rightarrow \epsilon$
\begin{eqnarray*}
&& S_0 \rightarrow S\\
&& S \rightarrow ASA\mid aB\mid a \mid \alert{AS\mid SA \mid S}\\
&& A \rightarrow B\mid S\\
&& B \rightarrow b
\end{eqnarray*}
\item What if
\begin{equation*}
B \rightarrow \epsilon
\end{equation*}
appears again? An infinite loop? We will discuss this issue later
\item Remove $S\rightarrow S$ because the right-hand side
cannot be a single variable
\begin{eqnarray*}
&& S_0 \rightarrow S\\
&& S \rightarrow ASA\mid aB\mid a \mid AS\mid SA\\
&& A \rightarrow B\mid S\\
&& B \rightarrow b
\end{eqnarray*}
\item Remove $S_0 \rightarrow S$
\begin{eqnarray*}
&& S_0 \rightarrow \alert{ASA\mid aB\mid a \mid AS\mid SA}\\
&& S \rightarrow ASA\mid aB\mid a \mid AS \mid SA\\
&& A \rightarrow B\mid S\\
&& B \rightarrow b
\end{eqnarray*}
\item Remove $A\rightarrow B, A\rightarrow S$
\begin{eqnarray*}
&& S_0 \rightarrow ASA\mid aB\mid a \mid AS\mid SA\\
&& S \rightarrow ASA\mid aB\mid a \mid AS \mid SA\\
&& A \rightarrow \alert{b \mid ASA \mid aB\mid a \mid AS \mid SA}\\
&& B \rightarrow b
\end{eqnarray*}
\item Finally
\begin{eqnarray*}
&& S_0 \rightarrow AA_1\mid UB\mid a \mid AS\mid SA\\
&& S \rightarrow AA_1 \mid UB\mid a \mid AS \mid SA\\
&& A \rightarrow b \mid AA_1 \mid UB\mid a \mid AS \mid SA\\
&& A_1 \rightarrow SA\\
&& U \rightarrow a\\
&& B \rightarrow b\\
\end{eqnarray*}
\end{itemize}\end{frame}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: