Construction and identification of experimental three-finite automata
First, the experimental target
1, master the concept of a poor state automata;
2. Master the storage and presentation method of the automatic machine with poor state;
3. Master the relationship between the self-motive of the poor state and the regular one.
Second, the experimental requirements
1, input regular type;
2, constructs the regular type has the poor state self-motive;
3. Output in five-tuple form.
#include <stdio.h>#include<string.h>#defineOK 1#defineError 0#defineN 50intIcurrentstate=0;//initial state starting with 1intIprestate=0;intIforkstate=0;intIlastforkstate=0;intImaxstate=0;CharX[n];//Normal string of inputCharCcharset[n];//Character SetintIstatematrix[n][n];//State Transition MatrixintVstring ()//to read a string into a buffer{scanf ("%s", x); returnOK;}intVprocessstring ()//preprocessing of strings, eliminating the effect of parsing in strings{ intI=0; while(x[i]!=' /') { if(x[i]=='*') { intj=i+1; while(x[j-1]!=' /') {x[j-1]=x[j++]; }} I++; } returnOK;}voidConstructmatrix (CharCChar,intIstate)//constructing a State transformation matrix{ inti; for(i=0; ccharset[i]!=' /'; i++) if(cchar==Ccharset[i]) Break; Ccharset[i]=CChar; Istatematrix[iprestate][i]=istate;}voidVaanalystring ()//left-to-right parsing and processing of strings{ intI=0; for(i=0; x[i]!=0; i++) { if(x[i]=='(')//The NFA begins to diverge { intIthefirstl=0; intIcharnumbeforl=0; Iforkstate=icurrentstate; while(x[i]!=')') {i++; if(Isalpha (X[i])) {if(x[i+1]==')') Icurrentstate=ilastforkstate; Elseicurrentstate++; Icharnumbeforl++; Constructmatrix (x[i],icurrentstate); Iprestate=icurrentstate; if(icurrentstate>imaxstate) Imaxstate=icurrentstate; } if(x[i]=='|') {iprestate=iforkstate; if(ithefirstl==0) {ilastforkstate=icurrentstate; Ithefirstl++; } if(icharnumbeforl==1&&x[i+2]=='|') Icurrentstate=iforkstate; Icharnumbeforl=0; } if(x[i]==')') {iprestate=iforkstate=ilastforkstate; Icurrentstate=imaxstate; } } } Else { if(Isalpha (X[i])) {icurrentstate++; Constructmatrix (x[i],icurrentstate); Iprestate=icurrentstate; if(icurrentstate>imaxstate) Imaxstate=icurrentstate; } } }}voidVPRINTFF ()//output F function{ intIccharsetpointer; intIprestatepointer; for(iprestatepointer=0; iprestatepointer<n;iprestatepointer++) for(iccharsetpointer=0; iccharsetpointer<n;iccharsetpointer++) if(istatematrix[iprestatepointer][iccharsetpointer]>0) printf ("f (%d,%c) =%d\n", Iprestatepointer,ccharset[iccharsetpointer],istatematrix[iprestatepointer][iccharsetpointer]);}voidVPRINTFNFA ()//Output NFA{ intistatenumble; intI=0; printf ("\nnfa in the form of: (k,$,f,s,z) \ nthe following is the specific set of NFA content: \ n"); printf ("\ n The initial set S is: {0}\n\n"); printf ("End state Set Z is: {%d}\n", imaxstate); printf ("\ n The character set F is: {"); while(ccharset[i]!=0) if(ccharset[i+1]==0) printf ("%c", ccharset[i++]); Elseprintf ("%c,", ccharset[i++]); printf ("}\n"); printf ("\ n The state set K is: {"); for(i=0; i<=imaxstate;i++) { if(i==imaxstate) printf ("%d", i); Elseprintf ("%d,", i); } printf ("}\n\n"); VPRINTFF ();}voidMain () {printf ("Please enter normal type:"); Vstring (); Vprocessstring (); Vaanalystring (); Vprintfnfa (); printf ("\ n");}
Run:
Construction and identification of experimental three-finite automata