Construction and identification of 1210 finite automata

Source: Internet
Author: User

#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 ("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 poor state automaton, i.e. 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 deterministic with a poor state automaton, i.e. 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 ("Where, \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");

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");

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");
}

Construction and identification of 1210 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.