There is a poor automatic mechanism to build

Source: Internet
Author: User

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{
Char p[30][30];//store Grammar
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]={'};//' store non-terminating symbols
Char vt[30]={'};//' store the finalization symbol
printf ("Please enter the number of rules");
scanf ("%d", &n);
Line=n;
for (i=0;i<30;i++)//string array p,q all assigned to '
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]);
}
Divide characters into Terminator and non-terminator
l=0;
m=0;
for (i=0;i<line;i++)
{
For (j=0;j<30&& (p[i][j]!= '); j + +)
{
Non-terminator into the array vn
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++;
}
}
Terminator placed in the array VT
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++;
}
}
}
}
Separate the right part of the rule into the array q
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;
}
The judgment is deterministic or indeterminate with a poor state automaton, and the first half is printed
Judging by: Is the string of each row in the Q array the same
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 m rear section
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");
}

There is a poor automatic mechanism to build

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.