Construction and identification of a poor automaton

Source: Internet
Author: User

#include <string.h> #include <stdio.h> #include <stdlib.h>int main () {char p[30][30];                        Storage 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 symbol char vt[30] = {'} '};           Store the finalization symbol printf ("Please enter the number of rules:");           scanf ("%d", &n);                line = n;                          for (i = 0; i < i++)//Assign the string array p, q all to ' \ n ' 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]);         }//The character is divided into the final symbol and non-terminating symbol l=0;          m=0; for (i = 0;i < line; i++) {for (j = 0;j < 30&& (p[i][j]! = ' + '); J + +) {//non-terminating symbol put in 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 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 < && (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;    }//judgment is deterministic or indeterminate with a poor state automaton and the first half of the print//judgment is based on: Q The string in the array is the same as 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,∑,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 d= (k,∑,m,{s},{z}) \ n");    } printf ("wherein, \nk = {S");    for (i = 0;i < && (vt[i]!= '); i++) {printf (",%c", Vt[i]);    } printf ("}\n");    printf ("∑={"); for (i = 0;i < && (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] = = ' | ')                    {count++;                    k = 0;                j + +;        }}} count++;    k=0;    } printf ("\ n");    Print M The latter half part of printf ("m:\n");    L = 0;        while (vn[l]! = ' + ') {printf ("M (s,%c) ={", Vn[l]); for (i = 0; i < 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 < 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 a poor automaton

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.