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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
| namespace Unit1
{
public partial class TForm1 : Form//<------------------------------------[bcc32c Error]
{
public TForm1()
{
InitializeComponent();
}
public Label Label1 = new Label();
public Label Label3 = new Label();
public Label Label4 = new Label();
public Label Label7 = new Label();
public Label Label5 = new Label();
public Label Label2 = new Label();
public Label Label6 = new Label();
public TextBox Edit2 = null;
public TextBox Edit1 = null;
public TextBox Edit3 = null;
public ListBox ListBox1 = null;
public TextBox Edit4 = null;
public TextBox Edit5 = null;
public TextBox Edit6 = null;
public TUpDown UpDown1 = new TUpDown();
public TUpDown UpDown2 = new TUpDown();
public RichTextBox Memo1 = null;
public GroupBox RadioGroup1 = new GroupBox();
public Label Label8 = new Label();
public Label Label9 = new Label();
public TMainMenu MainMenu1 = new TMainMenu();
public MenuItem N1 = null;
public MenuItem N2 = null;
public MenuItem N3 = null;
public MenuItem N5 = null;
public OpenFileDialog OpenDialog1;
public void RadioGroup1Select(object Sender, EventArgs e)
{
string R = string.Empty;
string S = string.Empty;
int I = 0;
int J = 0;
int K = 0;
int N = 0;
if (Edit1.Text == string.Empty)
{
Application.MessageBox("Отсутствуют нетерминальные символы", "Ошибка входных данных");
return;
}
if (Edit2.Text == string.Empty)
{
Application.MessageBox("Отсутствует алгаритм символы", "Ошибка входных данных");
return;
}
if (Edit3.Text == string.Empty)
{
Application.MessageBox("Отсутствует целевой символ", "Ошибка входных данных");
return;
}
if (Edit4.Text == string.Empty)
{
Application.MessageBox("Отсутствует символ пустой цепочки", "Ошибка входных данных");
return;
}
if (Edit4.Text == "|")
{
Application.MessageBox("Использовать \"|\" в качестве символа пустой цепочки", "Ошибка входных данных");
return;
}
if ((Edit1.Text.IndexOf("|") + 1) > 0)
{
Application.MessageBox("Использовать \"|\" в качестве нетерминального символа", "Ошибка входных данных");
return;
}
if ((Edit2.Text.IndexOf("|") + 1) > 0)
{
Application.MessageBox("Использовать \"|\" в качестве алфавитного символа", "Ошибка входных данных");
return;
}
for (I = 1; I <= Edit1.Text.Length - 1; I ++)
{
for (J = I + 1; J <= Edit1.Text.Length; J ++)
{
if (Edit1.Text[I] == Edit1.Text[J])
{
Application.MessageBox("Дублирование нетерминального символа", "Ошибка входных данных");
return;
}
}
}
for (I = 1; I <= Edit2.Text.Length - 1; I ++)
{
for (J = I + 1; J <= Edit2.Text.Length; J ++)
{
if (Edit2.Text[I] == Edit2.Text[J])
{
Application.MessageBox("Дублирование алфавитного символа", "Ошибка входных данных");
return;
}
}
}
for (I = 1; I <= Edit2.Text.Length; I ++)
{
if ((Edit1.Text.IndexOf(Edit2.Text[I]) + 1) > 0)
{
Application.MessageBox("Пересечение нетерминального и алфавитного символов", "Ошибка входных данных");
return;
}
}
if ((Edit1.Text.IndexOf(Edit3.Text[1]) + 1) == 0)
{
Application.MessageBox("Целевой символ отсутствует среди нетерминальных символов", "Ошибка входных данных");
return;
}
if ((Edit1.Text.IndexOf(Edit4.Text[1]) + 1) > 0)
{
Application.MessageBox("Пересечение нетерминального символа и символа пустой цепочки", "Ошибка входных данных");
return;
}
if ((Edit2.Text.IndexOf(Edit4.Text[1]) + 1) > 0)
{
Application.MessageBox("Пересечение алфавитного символа и символа пустой цепочки", "Ошибка входных данных");
return;
}
for (I = 1; I <= Unit1Unit.P.GetUpperBound(0); I ++)
{
for (J = 1; J <= Unit1Unit.P[1].GetUpperBound(0); J ++)
{
Unit1Unit.P[I, J] = string.Empty;
}
}
for (I = 0; I <= Memo1.Lines.Count - 1; I ++)
{
S = Memo1.Lines[I];
if (S == string.Empty)
{
break;
}
N = (Edit1.Text.IndexOf(S[0]) + 1);
if (N == 0)
{
Application.MessageBox("Посторонний символ в левой части правила", "Ошибка входных данных");
return;
}
if ((S.IndexOf("->") + 1) != 2)
{
Application.MessageBox("Отсутствует разделитель левой и правой части правила \"->\"", "Ошибка входных данных");
return;
}
K = 1;
while (Unit1Unit.P[N, K] != string.Empty)
{
K ++;
}
S = S.SafeSubstring(3, S.Length);
while ((S.IndexOf("|") + 1) > 0)
{
R = S.SafeSubstring(0, (S.IndexOf("|") + 1) - 1);
S = S.Remove(0, (S.IndexOf("|") + 1));
if (R == string.Empty)
{
Application.MessageBox("Отсутствует левая часть правила", "Ошибка входных данных");
return;
}
for (J = 1; J <= R.Length; J ++)
{
if (R[J - 1] == Edit4.Text[1])
{
if (R.Length > 1)
{
Application.MessageBox("В левой части пустого правила более одного символа", "Ошибка входных данных");
return;
}
}
else if (((Edit1.Text.IndexOf(R[J - 1]) + 1) == 0) && ((Edit2.Text.IndexOf(R[J - 1]) + 1) == 0))
{
Application.MessageBox("Посторонний символ в левой части правила", "Ошибка входных данных");
return;
}
}
Unit1Unit.P[N, K] = R;
K = K + 1;
}
if (S == string.Empty)
{
Application.MessageBox("Отсутствует левой часть правила", "Ошибка входных данных");
return;
}
for (J = 1; J <= S.Length; J ++)
{
if (S[J - 1] == Edit4.Text[1])
{
if (S.Length > 1)
{
Application.MessageBox("В правой части пустого правила более одного символа", "Ошибка входных данных");
return;
}
}
else if (((Edit1.Text.IndexOf(S[J - 1]) + 1) == 0) && ((Edit2.Text.IndexOf(S[J - 1]) + 1) == 0))
{
Application.MessageBox("Посторонний символ в правой части правила", "Ошибка входных данных");
return;
}
}
Unit1Unit.P[N, K] = S;
}
ListBox1.Items.Clear();
Unit1Unit.Quit = false;
Recurse(Edit3.Text, 15);
}
public void N4Click(object Sender, EventArgs e)
{
string s = string.Empty;
s = DateTime.Now.ToString("yyyy-mm-dd hh-nn-ss") + ".txt";
ListBox1.Items.SaveToFile(s);
MessageBox.Show("Добавленно в" + "\xD\xA" + s);
}
public void N5Click(object Sender, EventArgs e)
{
if (OpenDialog1.Execute)
{
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
}
}
/* Private declarations */
private void Recurse(string S, int Depth)
{
string L = string.Empty;
string R = string.Empty;
int DJ = 0;
int I = 0;
int J = 0;
int K = 0;
int N = 0;
if ((Unit1Unit.Quit) || (Depth < 0))
{
return;
}
K = S.Length;
N = 0;
for (I = 1; I <= K; I ++)
{
if ((Edit1.Text.IndexOf(S[I - 1]) + 1) > 0)
{
N = N + 1;
}
}
if (K - N > UpDown2.Position)
{
return;
}
if (RadioGroup1.SelectedIndex == 1)
{
J = K;
DJ = -1;
}
else
{
J = 1;
DJ = 1;
}
while ((J >= 1) && (J <= K))
{
N = (Edit1.Text.IndexOf(S[J - 1]) + 1);
if (N > 0)
{
Depth = Depth - 1;
L = S.SafeSubstring(0, J - 1);
R = S.SafeSubstring(J + 1 - 1, K - J);
I = 1;
while (Unit1Unit.P[N, I] != string.Empty)
{
if (Unit1Unit.P[N, I] == Edit4.Text)
{
Recurse(L + R, Depth);
}
else
{
Recurse(L + Unit1Unit.P[N, I] + R, Depth);
}
I = I + 1;
}
return;
}
J = J + DJ;
}
if ((K < UpDown1.Position) || (K > UpDown2.Position))
{
return;
}
if (S == string.Empty)
{
S = Edit4.Text;
}
if (ListBox1.Items.IndexOf(S) >= 0)
{
return;
}
ListBox1.Items.Add(S);
if (ListBox1.Items.Count % 5000 == 0)
{
L = Convert.ToString(ListBox1.Items.Count);
if (MessageBox.Show("Сгенерировано цепочек " + L + ". Продолжить?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes)
{
Unit1Unit.Quit = true;
return;
}
}
}
}
public partial class Unit1Unit//<------------------------------------[bcc32c Error]
{
public static TForm1 Form1
{
get;
set;
} = new TForm1();
public static string[,] P
{
get;
set;
} = new string[51, 51];
public static bool Quit
{
get;
set;
} = false;
}
} |