Construction and identification of experimental three-finite automata

Source: Internet
Author: User

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

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.