Construction and identification of finite automata

Source: Internet
Author: User

1 #include <string.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 int Main ()
5 {
6 Char p[30][30];
7 Char q[30][30];
8 int line=0;
9 int n;
ten int i,j;
int count=0;
k,t=0 int;
int flag=0;
l,m=0 int;
vn[30]={' + '};
+ Char vt[30]={' "};
printf ("Please enter the number of rules");
scanf ("%d", &n);
Line=n;
for (i=0;i<30;i++)
for (j=0;j<30;j++)
22 {
p[i][j]= ' + ';
q[i][j]= ' + ';
25}
-printf ("Please enter grammar: \ n");
for (i=0;i<line;i++)
28 {
scanf ("%s", P[i]);
30}
l=0;
m=0;
(i=0;i<line;i++)
34 {
For (j=0;j<30&& (p[i][j]!= '); j + +)
36 {
PNS if (p[i][j]<= ' z ' &&p[i][j]>= ' a ' | | (p[i][j]<= ' 9 ' &&p[i][j]>= ' 0 '))
38 {
flag=0;
for (t=0; vn[t]!= ' + '; t++)
41 {
if (Vn[t]==p[i][j])
43 {
flag=1;
a break;
46}
47}
if (flag==0)
49 {
[Vn[l]=p[i][j];
Wuyi l++;
52}
53}
if (p[i][j]<= ' Z ' &&p[i][j]>= ' A ')
55 {
flag=0;
t=0;t<30&& (vt[t]!= '); t++)
58 {
if (Vt[t]==p[i][j])
60 {
flag=1;
a break;
63}
64}
if (flag==0)
66 {
VT[M]=P[I][J];
m++;
69}
70}
71}
72}
count=0;
k=0;
(i=0;i<line;i++)
76 {
j=4;j<30&& (p[i][j]!= '), J + +)
78 {
(p[i][j]<= ' z ' &&p[i][j]>= ' a ') | | (p[i][j]<= ' Z ' &&p[i][j]>= ' A ') | | (p[i][j]<= ' 9 ' &&p[i][j]>= ' 0 '))
80 {
Bayi Q[count][k]=p[i][j];
k++;
83}
+ Else
85 {
count++;
k=0;
88}
89}
count++;
k=0;
92}
flag=0;
94 for (i=0;i<count;i++)
95 {
(j=i+1;j<count;j++)
97 {
98 if (strcmp (Q[i],q[j]) ==0)
99 {
flag=1;
101 break;
102}
103}
104}
if (flag==1)
106 {
107 printf ("Non-deterministic with a poor state automaton, ie nfa\n\n");
108 printf ("Constructed with a poor state automaton: \ n");
109 printf ("NFA n= (k,e (meaning of sum), m,{s},{z}) \ n");
110}
111 Else
112 {
113 printf ("is determined to have a poor state automaton, ie dfa\n\n\n");
printf ("Constructed with a poor state automaton: \ n");
n= printf ("DFA (k,e (meaning of sum), m,{s},{z}) \ n");
116}
117 printf ("wherein, \nk={s");
118 for (i=0;i<30&& (vt!= '); i++)
119 {
-printf (",%c", Vt[i]);
121}
122 printf ("}\n");
123 printf ("e={");
124 for (i=0;i<30&& (vn[i]!= '); i++)
125 {
126 printf ("%c", Vn[i]);
127}
printf ("}\n");
129//Separation Grammar
k=0;
131 count=0;
for (i=0;i<line;i++)
133 {
134 j=4;
135 while (p[i][j]!= ')
136 {
137 if (k<4)
138 {
139 Q[count][k]=p[i][k];
k++;
141}
142 Else
143 {
144 if ((p[i][j]<= ' z ' &&p[i][j]>= ' a ') | | (p[i][j]<= ' Z ' &&p[i][j]>= ' A ') | | (p[i][j]<= ' 9 ' &&p[i][j]>= ' 0 '))
145 {
146 Q[count][k]=p[i][j];
147 k++;
148 J + +;
149}
if (p[i][j]== ' l ')
151 {
count++;
153 k=0;
154 J + +;
155}
156}
157}
158 count++;
159 k=0;
160}
161 printf ("\ n");
162//Print
163 printf ("m:\n");
164 l=0;
165 while (vn[l]!= ')
166 {
167 printf ("M (s,%c) ={", Vn[l]);
168 for (i=0;i<30;i++)
169 {
(j=4;j<30&& (q[i][j]!= '); j + +)
171 {
172 if (vn[l]==q[i][j]&& (q[i][j+1]== ') && (q[i][j-1]== ' = '))
173 printf ("%c", q[i][0]);
174}
175}
176 printf ("}\t");
177 l++;
178}
179 printf ("\ n");
l=0;
181 k=0;
182 while (vt[k]!= ')
183 {
184 l=0;
185 while (vn[l]!= ')
186 {
187 printf ("M (%c,%c) ={", Vt[k],vn[l]);
188 for (i=0;i<30;i++)
189 {
j=4;j<30&& (q[i][j]!= '), J + +)
191 {
192 if (vt[k]==q[i][j]&&vn[l]==q[i][j+1])
193 printf ("%c", q[i][0]);
194}
195}
196 printf ("}\t");
197 l++;
198}
199 k++;
+ printf ("\ n");
201}
202 System ("pause");
203}
204

Construction and identification of finite automata

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.