Читайте также:
|
|
3.1. Сгенерировать цепочку символов по заданному языку L.
00101010+111
3.2. По заданному языку построить НДКА. Представить в виде диаграмм.
KA = {Q, ∑, δ, q0, F}
Q = { A, B, C, S0, qf } – состояния автомата. Q = V
∑ = {1, 0, +} – алфавит. ∑ = T
δ – правила перехода. δ = P
q0 – начальное состояние. q0 = S0
F – множество заключительных состояний. F = {qf}
НДКА с ε-переходами.
δ(S0, 0) = {1}
δ(1, 0) = {2}
δ(2, ε) = {3}
δ(3, ε) = {4}
δ(3, ε) = {6}
δ(4, 1) = {5}
δ(6, 0) = {7}
δ(5, ε) = {8}
δ(7, ε) = {8}
δ(8, ε) = {9}
δ(9, +) = {10}
δ(10, ε) = {11}
δ(11, 1) = {12}
δ(12, 1) = {11}
δ(11, ε) = {qf}
δ(12, ε) = { qf }
Диаграмма переходов.
ε
ε
ε ε
0 0 ε ε
0 ε
ε +
ε 1 ε
1
3.3. Реализовать преобразование НДКА в ДКА.
Шаг 1.
ε-closure(0) = {0} = A
ε-closure(move(A, 1)) = Ø
Dtran[A, 1] = Ø
ε-closure(move(A, +)) = Ø
Dtran[A, +] = Ø
ε-closure(move(A, 0)) = ε-closure({1}) = {1} = B
Dtran[A, 0] = B
ε-closure(move(B, 1)) = Ø
Dtran[B, 1] = Ø
ε-closure(move(B, 0)) = ε-closure({2}) = {2, 3, 4, 6, 9} = C
Dtran[B, 0] = C
ε-closure(move(B, +)) = Ø
Dtran[B, +] = Ø
ε-closure(move(C, 1)) = ε-closure({5}) = {3, 4, 5, 6, 8, 9} = D
Dtran[C, 1] = D
ε-closure(move(C, 0)) = ε-closure({7}) = {3, 4, 6, 7, 8, 9} = E
Dtran[C, 0] = E
ε-closure(move(C, +)) = ε-closure({10}) = {11} = F
Dtran[C, +] = F
ε-closure(move(D, 1)) = Ø
Dtran[D, 1] = Ø
ε-closure(move(D, 0)) = ε-closure({7}) = {3, 4, 6, 7, 8, 9} = E
Dtran[D, 0] = E
ε-closure(move(D, +)) = ε-closure({10}) = {11} = F
Dtran[D, +] = F
ε-closure(move(E, 0)) = Ø
Dtran[E, 0] = Ø
ε-closure(move(E, 1)) = ε-closure({5}) = {3, 4, 5, 6, 8, 9} = D
Dtran[E, 1] = D
ε-closure(move(E, +)) = ε-closure({10}) = {11} = F
Dtran[E, +] = F
ε-closure(move(F, 0)) = Ø
Dtran[F, 0] = Ø
ε-closure(move(F, 1)) = ε-closure({11, 12}) = {qf} = K
Dtran[F, 1] = K
ε-closure(move(F, +)) = Ø
Dtran[F, +] = Ø
Шаг 2. Построение таблицы переходов Dtran.
Состояние | Входной символ | ||
+ | |||
A | Ø | B | Ø |
B | Ø | C | Ø |
C | D | E | F |
D | Ø | E | F |
E | D | Ø | F |
F | K | Ø | Ø |
Диаграмма переходов ДКА.
Текст программы.
myAutomate ka = new myAutomate(new ArrayList() { "S0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "qf" },
new ArrayList() { "0", "1", "+", ""}, new ArrayList() { "qf" },"S0");
ka.AddRule("S0", "0", "A");
ka.AddRule("A", "0", "B");
ka.AddRule("B", "1", "C");
ka.AddRule("B", "0", "C");
ka.AddRule("C", "+", "D");
ka.AddRule("D", "1", "qf");
ka.Execute(Console.ReadLine()); // lab 1-3 KA
myAutomate ndka = new myAutomate(new ArrayList() {"S0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "qf"}, new ArrayList() { "1", "0","+", "-"}, new ArrayList() { "qf" }, "S0");
ndka.AddRule("S0", "0", "1");
ndka.AddRule("1", "0", "2");
ndka.AddRule("2", "", "3");
ndka.AddRule("3", "", "4");
ndka.AddRule("3", "", "6");
ndka.AddRule("4", "1", "5");
ndka.AddRule("6", "0", "7");
ndka.AddRule("5", "", "8");
ndka.AddRule("7", "", "8");
ndka.AddRule("8", "", "9");
ndka.AddRule("9", "+", "10");
ndka.AddRule("10", "", "11");
ndka.AddRule("11", "1", "12");
ndka.AddRule("12", "1", "11");
ndka.AddRule("11", "", "qf");
ndka.AddRule("12", "", "qf");
myAutomate dka = new myAutomate();
dka.BuildDeltaDKAutomate(ndka);
dka.DebugAuto();
dka.Execute(Console.ReadLine());
Дата добавления: 2015-10-31; просмотров: 117 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
Спроектировать конечный автомат, составить диаграмму переходов КА и реализовать. | | | Реализовать МП автомат для приведенной КС-грамматики |