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
| private void button6_Click(object sender, EventArgs e)
{
try
{
ready = false;
gram.Clear();
start = richTextBox1.Lines[0];
string tempRead;
tempRead = richTextBox1.Lines[1];
alfavit = tempRead.Split(new char[] { ' ' }, StringSplitOptions.None);
tempRead = richTextBox1.Lines[0];
alfavitnt = tempRead.Split(new char[] { ' ' }, StringSplitOptions.None);
Array.Sort(alfavit, myComparer);
Array.Sort(alfavitnt, myComparer);
for (int i = 0; i < alfavitnt.Length; i++) gram.Add(alfavitnt[i], new List<MySymbol>());
string[] line;
int c = 3;
bool flagT = false;
bool flagNT = false;
int qwe;
int PosInAlfNt = -1;
string temp;
while (richTextBox1.Lines[c]!="*")
{
tempRead = richTextBox1.Lines[c];
c++;
line = tempRead.Split(new char[] { ' ' }, StringSplitOptions.None);
if (line.Length < 2) throw new IOException("Некорректные входные данные");
for (int i = 0; i < alfavitnt.Length; i++)
{
if (alfavitnt[i] == line[0]) { PosInAlfNt = i; break; }
}
if (PosInAlfNt < 0) throw new IOException("Некорректные входные данные в левой части правила");
for (int i = 1; i < line.Length; i++)
{
temp = line[i];
int kolvo = 0;
int kolvoT = 0;
int t = alfavit.Length - 1, nt = alfavitnt.Length - 1;
for (int j = 0; j < alfavit.Length + alfavitnt.Length; j++)
{
flagT = false;
flagNT = false;
do
{
qwe = -1;
if ((t >= 0) && (nt >= 0))
{
if (alfavit[t].Length < alfavitnt[nt].Length)
{
flagT = true;
qwe = temp.IndexOf(alfavit[t]);
if (qwe >= 0) { kolvo++; kolvoT++; temp = temp.Remove(qwe, alfavit[t].Length); }
}
else
{
flagNT = true;
qwe = temp.IndexOf(alfavitnt[nt]);
if (qwe >= 0) { kolvo++; temp = temp.Remove(qwe, alfavitnt[nt].Length); }
}
}
else
{
if (nt < 0)
{
flagT = true;
qwe = temp.IndexOf(alfavit[t]);
if (qwe >= 0) { kolvo++; kolvoT++; temp = temp.Remove(qwe, alfavit[t].Length); }
}
else
{
flagNT = true;
qwe = temp.IndexOf(alfavitnt[nt]);
if (qwe >= 0) { kolvo++; temp = temp.Remove(qwe, alfavitnt[nt].Length); }
}
}
}
while (qwe >= 0);
if (flagNT) nt--;
if (flagT) t--;
}
if (temp != " ") throw new IOException("Некорректные данные правой части");
kolvo = kolvoT * Razdel + kolvo;
gram[alfavitnt[PosInAlfNt]].Add(new MySymbol(line[i], kolvo));
}
}
ready = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Критическая ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} |