-
Notifications
You must be signed in to change notification settings - Fork 2
/
CFG1
108 lines (86 loc) · 1.71 KB
/
CFG1
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
// an bn am bm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
// char[] a = {'a', 'a', 'b', 'b', '$'};
CFG c = new CFG("aabbaabb$".ToCharArray());
c.validate();
}
}
class CFG
{
public static int index = 0;
char[] ch;
bool Checker = true;
bool Checkerr = false;
public CFG(char[] ch)
{
this.ch = ch;
}
public bool s()
{
if (ch[index] == 'a')
{
index++;
if (s() == true)
{
if (Checker == true)
{
Checkerr = Y();
Checker = false;
}
if (Checkerr == true)
{
if (ch[index] == 'b')
{
index++;
return true;
}
}
}
}
else
{
return true;
}
return false;
}
public bool Y()
{
if (ch[index] == 'b')
{
index++;
if (Y() == true)
{
if (ch[index] == 'a')
{
index++;
return true;
}
}
}
else
{
return true;
}
return false;
}
public bool validate()
{
if (s() == true)
{
if (ch[index] == '$')
{
Console.Write("TRUE\n");
return true;
}
}
Console.Write("FALSE\n");
return false;
}
}