-
Notifications
You must be signed in to change notification settings - Fork 0
/
lec13.tex
85 lines (75 loc) · 2.26 KB
/
lec13.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
\[
G = \lst{\Sigma, V, S, R}
\]
where
\begin{compactitem}
\item
$\Sigma, V$ are finite sets for input alphabet and variable symbols,
\item
$S \in V$ is the start variable,
\item
$R \subseteq V \times (V \cup \Sigma)^*$ is a finites set of rules.
\end{compactitem}
\begin{example}[A simple grammar]
\label{exa:a_simple_grammer}
A grammar
\[
G = \lst{\Sigma, V, S, R}
\]
\begin{align*}
\Sigma = \set{0,1,+,*,(,)} \\
V = \set{E,T,F} \\
S = E \\
\abs R = 7
\end{align*}
with rules
\begin{align*}
E &\mapsto E + T \mid T \\
T &\mapsto T * F \mid F \\
F &\mapsto 0 \mid 1 \mid (E)
\end{align*}
\end{example}
\begin{example}[Is $(0+1)*0$ in $L(G)$?]
With the grammar defined in \autoref{exa:a_simple_grammer},
consider the expression $(0+1)*0 \in L(G)$?
\[
E \mapsto T \mapsto T*F \mapsto F*F \mapsto (E)*F \mapsto (E+T)*F
\mapsto (T+F)*F \mapsto (F+F)*F \mapsto (0+1)*0 \in \Sigma^*
\]
\end{example}
\begin{definition}[Leftmost Derivatioonn]
leftmost derivation
is a sequence
$w_1, w_2, \cdots, w_n \in (V \cup \Sigma)^*$
such that
\begin{compactitem}
\item $w_1 = S$
\item $w_n \in S^*$
\item $\forall i = 1, \cdots, n-1$:
\begin{compactitem}
\item
$w_i = \alpha X \beta \quad \text{ where }
\alpha \in \Sigma^*, X \in V, \beta \in (\Sigma \cup V)^*,$
\item
$w_{i+1} = \alpha \gamma \beta \quad \text{ where }
(X, \gamma) \in R.$
\end{compactitem}
\end{compactitem}
\end{definition}
\begin{definition}[Language of a Grammar]
\begin{align*}
L(G) &= \set{ w \in \Sigma^* \mid S \mapsto_G^* w } \\
&= \set{ w \mid \text{ there is a leftmost derivation of $w$ in $G$} }
\end{align*}
\end{definition}
\begin{example}[Palindromes]
Write a grammar for the following language,
\[
P = \set{ w \in {0,1} \mid w^R = w }.
\]
\[
E \mapsto 0E0 \mid 1E1 \mid 0 \mid 1 \mid \varepsilon
\]
\end{example}
push what has been read onto the stack and check for reversion instantly.
Push a special symbol in the very first for the ``beginning of string.''