Skip to content

Commit 06b0ea4

Browse files
authored
Merge pull request #5 from kajigor/main
Better figures in GLR chapter.
2 parents a9ac33c + 4fa841c commit 06b0ea4

17 files changed

+727
-882
lines changed
-27.7 KB
Binary file not shown.

tex/FormalLanguageConstrainedReachabilityLectureNotes.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105

106106
\tikzstyle{r_state} = [shape=rectangle, draw, minimum size=0.2cm]
107107

108+
\tikzstyle{num_state} = [draw=none, fill=none, anchor=south west, red]
109+
108110
\tikzstyle{prod_node} = [shape=rectangle, draw, align=center]
109111

110112
\tikzset{
@@ -147,6 +149,8 @@
147149
\tableofcontents
148150
\newpage
149151
152+
% \input{GLR-based_CFPQ}
153+
150154
\input{List_of_contributors}
151155
\input{Introduction}
152156
%\input{LinearAlgebra}

tex/FormalLanguageTheoryIntro.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ \chapter{Общие сведения теории формальных язык
1313
\begin{itemize}
1414
\item Латинский алфавит $\Sigma = \{ a, b, c, \dots, z\}$
1515
\item Кириллический алфавит $\Sigma = \{ \text{а, б, в, \dots, я}\}$
16-
\item Алфавит чисел в шестнадцатеричной записи
16+
\item Алфавит чисел в шестнадцатеричной записи
1717
$$\Sigma = \{0, 1, 2, 3, 4, 5, 6, 7 ,8,9, A, B, C, D, E, F \}$$
1818
\end{itemize}
1919
\end{example}
@@ -56,11 +56,11 @@ \chapter{Общие сведения теории формальных язык
5656
\begin{itemize}
5757
\item Перечислить все элементы. Такой способ работает только для конечных языков. Перечислить бесконечное множество не получится.
5858
\item Задать генератор --- процедуру, которая возвращает очередное слово языка.
59-
\item Задать распознователь --- процедуру, которая по данному слову может определить, принадлежит оно заданному языку или нет.
59+
\item Задать распознаватель --- процедуру, которая по данному слову может определить, принадлежит оно заданному языку или нет.
6060
\end{itemize}
6161

6262

63-
%Теоретико-множественные задачи над языками и их применение.
63+
%Теоретико-множественные задачи над языками и их применение.
6464
%О том, что моногое --- про пересечение, проверку пустоты, вложенность.
6565

6666

@@ -69,6 +69,6 @@ \chapter{Общие сведения теории формальных язык
6969

7070
%\section{Вопросы и задачи}
7171
%\begin{enumerate}
72-
% \item !!!
72+
% \item !!!
7373
% \item !!!
7474
%\end{enumerate}

tex/GLR-based_CFPQ.tex

Lines changed: 214 additions & 677 deletions
Large diffs are not rendered by default.

tex/Introduction.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ \chapter*{Введение}
1414
Одна из классических задач, связанных с анализом графов --- это поиск путей в графе.
1515
Возможны различные формулировки этой задачи.
1616
В некоторых случаях необходимо выяснить, существует ли путь с определёнными свойствами между двумя выбранными вершинами.
17-
В других же ситуациях необходимо найти все пути в графе, удовлетворяющие некоторым свойствам или ограничениям.
17+
В других же ситуациях необходимо найти все пути в графе, удовлетворяющие некоторым свойствам или ограничениям.
1818
Например, в качестве ограничений можно указать, что искомый путь должен быть простым, кратчайшим, гамильтоновым и так далее.
1919

2020
Один из способов задавать ограничения на пути в графе основан на использовании формальных языков.

tex/figures/GLR/CLR_example.tex

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
\begin{tikzpicture}[> = stealth,node distance=3.25cm, on grid, scale=0.8, every node/.style={scale=0.8}]
2+
\node[draw=none, fill=none] at (-1.4, 1.2) {0};
3+
\node[draw=none, fill=none] at (3.1, 0.55) {3};
4+
\node[draw=none, fill=none] at (-1.4, -1.3) {1};
5+
\node[draw=none, fill=none] at (-1.4, -3.8) {2};
6+
\node[draw=none, fill=none] at (2.9, -1.95) {4};
7+
\node[draw=none, fill=none] at (2.9, -4.45) {5};
8+
\node[draw=none, fill=none] at (6.7, -1.3) {6};
9+
\node[draw=none, fill=none] at (6.7, -3.8) {7};
10+
\node[draw=none, fill=none] at (11, -1.95) {8};
11+
\node[draw=none, fill=none] at (11, -4.45) {9};
12+
\node[r_state] (s_0)
13+
{
14+
$
15+
\begin{aligned}
16+
S' &\to \cdot S, \{\$\} \\
17+
S &\to \cdot a S b S, \{\$\} \\
18+
S &\to \cdot, \{\$\}
19+
\end{aligned}
20+
$
21+
};
22+
\node[r_state] (s_1) [below=2cm of s_0]
23+
{
24+
$
25+
\begin{aligned}
26+
S &\to a \cdot S b S, \{\$\} \\
27+
S &\to \cdot a S b S, \{b\} \\
28+
S &\to \cdot, \{b\}
29+
\end{aligned}
30+
$
31+
};
32+
\node[r_state] (s_2) [below=2cm of s_1]
33+
{
34+
$
35+
\begin{aligned}
36+
S &\to a \cdot S b S, \{b\} \\
37+
S &\to \cdot a S b S, \{b\} \\
38+
S &\to \cdot, \{b\}
39+
\end{aligned}
40+
$
41+
};
42+
\node[r_state] (s_3) [right=of s_0]
43+
{
44+
$ S' \to S \cdot, \{\$\} $
45+
};
46+
\node[r_state] (s_4) [right=of s_1]
47+
{
48+
$ S \to a S \cdot b S, \{\$\} $
49+
};
50+
\node[r_state] (s_5) [right=of s_2]
51+
{
52+
$ S \to a S \cdot b S, \{b\} $
53+
};
54+
\node[r_state] (s_6) [right=of s_4]
55+
{
56+
$
57+
\begin{aligned}
58+
S &\to a S b \cdot S, \{\$\} \\
59+
S &\to \cdot a S b S, \{\$\} \\
60+
S &\to \cdot, \{\$\}
61+
\end{aligned}
62+
$
63+
};
64+
\node[r_state] (s_7) [right=of s_5]
65+
{
66+
$
67+
\begin{aligned}
68+
S &\to a S b \cdot S, \{b\} \\
69+
S &\to \cdot a S b S, \{b\} \\
70+
S &\to \cdot , \{b\}
71+
\end{aligned}
72+
$
73+
};
74+
\node[r_state] (s_8) [right=of s_6]
75+
{
76+
$ S \to a S b S \cdot, \{\$\} $
77+
};
78+
\node[r_state] (s_9) [right=of s_7]
79+
{
80+
$ S \to a S b S \cdot, \{b\} $
81+
};
82+
83+
\path[->]
84+
(s_0) edge [left] node {$a$} (s_1)
85+
edge [above] node {$S$} (s_3)
86+
(s_1) edge [left] node {$a$} (s_2)
87+
edge [above] node {$S$} (s_4)
88+
(s_2) edge [loop below] node {$a$} ()
89+
edge [above] node {$S$} (s_5)
90+
(s_4) edge [above] node {$b$} (s_6)
91+
(s_5) edge [above] node {$b$} (s_7)
92+
(s_6) edge [above] node {$S$} (s_8)
93+
edge [above, bend right=20] node {$a$} (s_1)
94+
(s_7) edge [above] node {$S$} (s_9)
95+
edge [below, bend left=20] node {$a$} (s_2)
96+
;
97+
\end{tikzpicture}

tex/figures/GLR/GLR_example.tex

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
\begin{tikzpicture}[> = stealth,node distance=1.25cm, on grid, scale=0.8, every node/.style={scale=0.8}]
2+
\node[r_state] (s_0)
3+
{
4+
$
5+
\begin{aligned}
6+
S' &\to \cdot S \$ \\
7+
S &\to \cdot a b C \\
8+
S &\to \cdot a B C
9+
\end{aligned}
10+
$
11+
};
12+
\node[r_state] (s_1) [below=2.5cm of s_0]
13+
{
14+
$ S' \to S \cdot \$ $
15+
};
16+
\node[r_state] (s_acc) [below=2cm of s_1]
17+
{
18+
$ S' \to S \$ \cdot $
19+
};
20+
\node[r_state] (s_2) [right=3cm of s_0]
21+
{
22+
$
23+
\begin{aligned}
24+
S &\to a \cdot B C \\
25+
S &\to a \cdot b C \\
26+
B &\to \cdot b
27+
\end{aligned}
28+
$
29+
};
30+
31+
\node[r_state] (s_3) [right=3cm of s_2]
32+
{
33+
$
34+
\begin{aligned}
35+
S &\to a b \cdot C \\
36+
B &\to b \cdot \\
37+
C &\to \cdot c
38+
\end{aligned}
39+
$
40+
};
41+
42+
\node[r_state] (s_5) [right=3cm of s_3]
43+
{
44+
$
45+
\begin{aligned}
46+
S &\to a b C \cdot
47+
\end{aligned}
48+
$
49+
};
50+
51+
\node[r_state] (s_4) [below=2.5cm of s_2]
52+
{
53+
$
54+
\begin{aligned}
55+
S &\to a B \cdot C \\
56+
C &\to \cdot c
57+
\end{aligned}
58+
$
59+
};
60+
61+
\node[r_state] (s_6) [right=3cm of s_4]
62+
{
63+
$
64+
\begin{aligned}
65+
C &\to c \cdot
66+
\end{aligned}
67+
$
68+
};
69+
70+
\node[r_state] (s_7) [below=2cm of s_4]
71+
{
72+
$
73+
\begin{aligned}
74+
S &\to a B C \cdot
75+
\end{aligned}
76+
$
77+
};
78+
79+
\node[num_state] at (s_0.north west) {0};
80+
\node[num_state] at (s_1.north west) {1};
81+
\node[num_state] at (s_2.north west) {2};
82+
\node[num_state] at (s_3.north west) {3};
83+
\node[num_state] at (s_4.north west) {4};
84+
\node[num_state] at (s_5.north west) {5};
85+
\node[num_state] at (s_6.north west) {6};
86+
\node[num_state] at (s_7.north west) {7};
87+
\node[num_state] at (s_acc.north west) {acc};
88+
89+
90+
\path[->]
91+
(s_0) edge [above] node {$a$} (s_2)
92+
edge [right] node {$S$} (s_1)
93+
(s_1) edge [right] node {$\$$} (s_acc)
94+
(s_2) edge [above] node {$b$} (s_3)
95+
edge [right] node {$B$} (s_4)
96+
(s_3) edge [above] node {$C$} (s_5)
97+
edge [right] node {$c$} (s_6)
98+
(s_4) edge [above] node {$c$} (s_6)
99+
edge [right] node {$C$} (s_7)
100+
;
101+
\end{tikzpicture}

tex/figures/GLR/LL_LR.tex

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
\begin{tikzpicture}
2+
\node at (0,0) (ll0) {LL(0)};
3+
\node at (0,3.5) (ll1) {LL(1)};
4+
\node at (0,4.5) (llk) {LL(k)};
5+
\node at (3,0) (lr0) {LR(0)};
6+
\node at (3,1.5) (slr) {SLR(1)};
7+
\node at (3,2.5) (lalr) {LALR(1)};
8+
\node at (3,3.5) (clr) {CLR(1)};
9+
\node at (3,4.5) (lrk) {LR(k)};
10+
11+
\node[r_state,violet,fit=(ll0)] (a) {};
12+
\node[draw=none,fit=(a)] (a1) {};
13+
\node[draw=none,fit=(a1)] (a2) {};
14+
\node[r_state,violet,fit=(ll0) (ll1) (a)] (b) {};
15+
\node[r_state,violet,fit=(ll0) (llk) (b)] (c) {};
16+
\node[r_state,fit=(a2) (lr0)] (d) {};
17+
\node[r_state,fit=(slr) (d)] (e) {};
18+
\node[r_state,fit=(lalr) (e)] (f) {};
19+
\node[r_state,fit=(lalr) (clr) (f) (b)] (g) {};
20+
\node[r_state,fit=(g) (lalr) (lrk) (c)] (h) {};
21+
\end{tikzpicture}

tex/figures/GLR/LR0/complete.tex

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
\begin{tikzpicture}[> = stealth,node distance=3.25cm, on grid, scale=0.8, every node/.style={scale=0.8}]
2+
\node[r_state] (s_0)
3+
{
4+
$
5+
\begin{aligned}
6+
S' &\to \cdot S \$ \\
7+
S &\to \cdot a S b S \\
8+
S &\to \cdot
9+
\end{aligned}
10+
$
11+
};
12+
\node[r_state] (s_1) [right=of s_0]
13+
{
14+
$ S' \to S \cdot \$ $
15+
};
16+
\node[r_state] (s_2) [right=of s_1]
17+
{
18+
$ S' \to S \$ \cdot $
19+
};
20+
\node[r_state] (s_3) [below=2.5cm of s_0]
21+
{
22+
$
23+
\begin{aligned}
24+
S &\to a \cdot S b S \\
25+
S &\to \cdot a S b S \\
26+
S &\to \cdot
27+
\end{aligned}
28+
$
29+
};
30+
\node[r_state] (s_4) [right=of s_3]
31+
{
32+
$ S \to a S \cdot b S$
33+
};
34+
\node[r_state] (s_5) [right=of s_4]
35+
{
36+
$
37+
\begin{aligned}
38+
S &\to a S b \cdot S \\
39+
S &\to \cdot a S b S \\
40+
S &\to \cdot
41+
\end{aligned}
42+
$
43+
};
44+
\node[r_state] (s_6) [right=of s_5]
45+
{
46+
$ S \to a S b S \cdot$
47+
};
48+
49+
\node[num_state] at (s_0.north west) {0};
50+
\node[num_state] at (s_1.north west) {1};
51+
\node[num_state] at (s_2.north west) {2};
52+
\node[num_state] at (s_3.north west) {3};
53+
\node[num_state] at (s_4.north west) {4};
54+
\node[num_state] at (s_5.north west) {5};
55+
\node[num_state] at (s_6.north west) {6};
56+
57+
\path[->]
58+
(s_0) edge [left] node {$a$} (s_3)
59+
edge [above] node {$S$} (s_1)
60+
(s_1) edge [above] node {$\$$} (s_2)
61+
(s_3) edge [above] node {$S$} (s_4)
62+
edge [loop below] node {$a$} ()
63+
(s_4) edge [above] node {$b$} (s_5)
64+
(s_5) edge [above] node {$S$} (s_6)
65+
edge [above, bend right=20] node {$a$} (s_3)
66+
;
67+
\end{tikzpicture}

tex/figures/GLR/LR0/state0.tex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
\begin{tikzpicture}[> = stealth,node distance=3.25cm, on grid, scale=0.8, every node/.style={scale=0.8}]
2+
\node[r_state] (s_0)
3+
{
4+
$
5+
\begin{aligned}
6+
S' &\to \cdot S \$ \\
7+
S &\to \cdot a S b S \\
8+
S &\to \cdot
9+
\end{aligned}
10+
$
11+
};
12+
13+
\node[num_state] at (s_0.north west) {0};
14+
\end{tikzpicture}

0 commit comments

Comments
 (0)