-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfg_string1.m
45 lines (38 loc) · 1.15 KB
/
cfg_string1.m
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
% Matlab code for Context free grammar
%‐---------------------------------------------------------------------------------
% G= (V, T, P, S)
% G describes the grammar
% T describes a finite set of terminal symbols.
% V describes a finite set of non-terminal symbols
% P describes a set of production rules
% S is the start symbol.
%--------------------------------------------------------------------------
% Input the production :
disp('Note: The input string only contains a b');
prompt='Enter the string to check the production rule:';
s=input(prompt,'s');
%--------------------------------------------------------------------------
n=size(s);
n=n(2);
t=1;
if ((s(1)=='b'||'a') && n==1)
disp('1');
else if(s(1)=='a')
for j=2:n
if(s(j)=='b')
for l=j:n
if(s(l)=='a')
t=2;
end
end
end
end
else
t=2;
end
end
if(t==1)
disp('Output : 1');
else
disp('Output : 0');
end