include iostream include vector include string using namespace std boo

 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool analys(char lex[], int n)
{
int STATE = 1;
cout << "История команд:" << endl;
for (int i = 0; i < n; i++)
{
switch (STATE)
{
case 1:
cout << 1 << endl;
if (lex[i] == '0')
STATE = 2;
else
return false;
break;
case 2:
cout << 2 << endl;
if (lex[i] == '1')
break;
if (lex[i] == '0')
STATE = 1;
else
return false;
break;
}
}
}
int main()
{
setlocale(LC_ALL, "Russian");
char lex1[] = {'1', '0', '0', '0', '1', '0', '0', '1', '0'};
char lex2[] = {'0', '1', '1', '1', '1', '1', '1', '1', '0'};
char lex3[] = {'0', '0', '0', '0', '0', '0', '0', '0', '0'};
char lex4[] = {'0', '0', '0', '0', '0', '0', '0', '0', '1'};
string result = analys(lex2, 9) ? "Цепочка принадлежит грамматике" : "Цепочка не принадлежит грамматике";
cout << "Результат: " << endl;
cout << result << endl;
}