#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{
Char p[30][30];
Char q[30][30];
int line=0;
int n;
int i,j;
int count=0;
int k,t=0;
int flag=0;
int l,m=0;
Char 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++)
{
p[i][j]= ' + ';
q[i][j]= ' + ';
}
printf ("Please enter grammar: \ n");
for (i=0;i<line;i++)
{
scanf ("%s", P[i]);
}
l=0;
m=0;
for (i=0;i<line;i++)
{
For (j=0;j<30&& (p[i][j]!= '); j + +)
{
if (p[i][j]<= ' z ' &&p[i][j]>= ' a ' | | (p[i][j]<= ' 9 ' &&p[i][j]>= ' 0 '))
{
flag=0;
for (t=0; vn[t]!= ' + '; t++)
{
if (Vn[t]==p[i][j])
{
Flag=1;break;
}
}
if (flag==0)
{
VN[L]=P[I][J];
l++;
}
}
if (p[i][j]<= ' Z ' &&p[i][j]>= ' A ')
{
flag=0;
For (t=0;t<30&& (vt[t]!= '); t++)
{
if (Vt[t]==p[i][j])
{
flag=1;
Break
}
}
if (flag==0)
{
VT[M]=P[I][J];
m++;
}
}
}
}
count=0;
k=0;
for (i=0;i<line;i++)
{
For (j=4;j<30&& (p[i][j]!= '); j + +)
{
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 '))
{
Q[COUNT][K]=P[I][J];
k++;
}
Else
{
count++;
k=0;
}
}
count++;
k=0;
}
flag=0;
for (i=0;i<count;i++)
{
for (j=i+1;j<count;j++)
{
if (strcmp (Q[i],q[j]) ==0)
{
flag=1;
Break
}
}
}
if (flag==1)
{
printf ("Non-deterministic with a poor state automaton, ie nfa\n\n");
printf ("Constructed with a poor state automaton: \ n");
printf ("NFA n= (k,e (meaning of sum), m,{s},{z}) \ n");
}
Else
{
printf ("is determined to have a poor state automaton, ie dfa\n\n\n");
printf ("Constructed with a poor state automaton: \ n");
printf ("DFA n= (k,e (meaning of sum), m,{s},{z}) \ n");
}
printf ("Wherein, \nk={s");
For (i=0;i<30&& (vt!= '); i++)
{
printf (",%c", Vt[i]);
}
printf ("}\n");
printf ("e={");
For (i=0;i<30&& (vn[i]!= '); i++)
{
printf ("%c", Vn[i]);
}
printf ("}\n");
Separation grammar
k=0;
count=0;
for (i=0;i<line;i++)
{
j=4;
while (p[i][j]!= ')
{
if (k<4)
{
Q[COUNT][K]=P[I][K];
k++;
}
Else
{
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 '))
{
Q[COUNT][K]=P[I][J];
k++;
j + +;
}
if (p[i][j]== ' l ')
{
count++;
k=0;
j + +;
}
}
}
count++;
k=0;
}
printf ("\ n");
Print
printf ("m:\n");
l=0;
while (vn[l]!= ')
{
printf ("M (s,%c) ={", Vn[l]);
for (i=0;i<30;i++)
{
For (j=4;j<30&& (q[i][j]!= '); j + +)
{
if (vn[l]==q[i][j]&& (q[i][j+1]== ') && (q[i][j-1]== ' = '))
printf ("%c", q[i][0]);
}
}
printf ("}\t");
l++;
}
printf ("\ n");
l=0;k=0;
while (vt[k]!= ')
{
l=0;
while (vn[l]!= ')
{
printf ("M (%c,%c) ={", Vt[k],vn[l]);
for (i=0;i<30;i++)
{
For (j=4;j<30&& (q[i][j]!= '); j + +)
{
if (vt[k]==q[i][j]&&vn[l]==q[i][j+1])
printf ("%c", q[i][0]);
}
}
printf ("}\t");
l++;
}
k++;
printf ("\ n");
}
System ("pause");
}
1211 Limited automatic mechanism making and recognition