@@ -6,13 +6,13 @@ struct node
66 struct node * link ;
77};
88
9- void findclosure (int , int );
10- void insert_trantbl (int , char , int );
11- int findalpha (char );
12- void findfinalstate (void );
13- void unionclosure (int );
14- void print_e_closure (int );
15- static int set [20 ], nostate , noalpha , s , notransition , nofinal , start , finalstate [20 ], c , r , buffer [20 ];
9+ void fc (int , int );
10+ void it (int , char , int );
11+ int fa (char );
12+ void ffs (void );
13+ void uc (int );
14+ void pec (int );
15+ static int set [20 ], ns , na , s , nt , nf , start , fs [20 ], c , r , b [20 ];
1616char alphabet [20 ];
1717static int e_closure [20 ][20 ] = {0 };
1818struct node * transition [20 ][20 ] = {NULL };
@@ -22,72 +22,72 @@ void main()
2222
2323 struct node * temp ;
2424 printf ("enter the number of alphabets?\n" );
25- scanf ("%d" , & noalpha );
25+ scanf ("%d" , & na );
2626 getchar ();
2727 printf ("NOTE:- [ use letter e as epsilon]\n" );
2828
2929 printf ("NOTE:- [e must be last character ,if it is present]\n" );
3030
3131 printf ("\nEnter alphabets?\n" );
32- for (i = 0 ; i < noalpha ; i ++ )
32+ for (i = 0 ; i < na ; i ++ )
3333 {
3434
3535 alphabet [i ] = getchar ();
3636 getchar ();
3737 }
3838 printf ("Enter the number of states?\n" );
39- scanf ("%d" , & nostate );
39+ scanf ("%d" , & ns );
4040 printf ("Enter the start state?\n" );
4141 scanf ("%d" , & start );
4242 printf ("Enter the number of final states?\n" );
43- scanf ("%d" , & nofinal );
43+ scanf ("%d" , & nf );
4444 printf ("Enter the final states?\n" );
45- for (i = 0 ; i < nofinal ; i ++ )
46- scanf ("%d" , & finalstate [i ]);
45+ for (i = 0 ; i < nf ; i ++ )
46+ scanf ("%d" , & fs [i ]);
4747 printf ("Enter no of transition?\n" );
48- scanf ("%d" , & notransition );
49- printf ("NOTE:- [Transition is in the form--> qno alphabet qno]\n" , notransition );
48+ scanf ("%d" , & nt );
49+ printf ("NOTE:- [Transition is in the form--> qno alphabet qno]\n" , nt );
5050 printf ("NOTE:- [States number must be greater than zero]\n" );
5151 printf ("\nEnter transition?\n" );
52- for (i = 0 ; i < notransition ; i ++ )
52+ for (i = 0 ; i < nt ; i ++ )
5353 {
5454
5555 scanf ("%d %c%d" , & r , & c , & s );
56- insert_trantbl (r , c , s );
56+ it (r , c , s );
5757 }
5858
5959 printf ("\n" );
6060
61- for (i = 1 ; i <= nostate ; i ++ )
61+ for (i = 1 ; i <= ns ; i ++ )
6262 {
6363 c = 0 ;
6464 for (j = 0 ; j < 20 ; j ++ )
6565
6666 {
67- buffer [j ] = 0 ;
67+ b [j ] = 0 ;
6868 e_closure [i ][j ] = 0 ;
6969 }
70- findclosure (i , i );
70+ fc (i , i );
7171 }
7272 printf ("Equivalent NFA without epsilon\n" );
7373 printf ("-----------------------------------\n" );
7474 printf ("start state:" );
75- print_e_closure (start );
75+ pec (start );
7676 printf ("\nAlphabets:" );
77- for (i = 0 ; i < noalpha ; i ++ )
77+ for (i = 0 ; i < na ; i ++ )
7878 printf ("%c " , alphabet [i ]);
7979 printf ("\n States :" );
80- for (i = 1 ; i <= nostate ; i ++ )
81- print_e_closure (i );
80+ for (i = 1 ; i <= ns ; i ++ )
81+ pec (i );
8282
8383 printf ("\nTnransitions are...:\n" );
8484
85- for (i = 1 ; i <= nostate ; i ++ )
85+ for (i = 1 ; i <= ns ; i ++ )
8686 {
8787
88- for (j = 0 ; j < noalpha - 1 ; j ++ )
88+ for (j = 0 ; j < na - 1 ; j ++ )
8989 {
90- for (m = 1 ; m <= nostate ; m ++ )
90+ for (m = 1 ; m <= ns ; m ++ )
9191 set [m ] = 0 ;
9292 for (k = 0 ; e_closure [i ][k ] != 0 ; k ++ )
9393 {
@@ -97,15 +97,15 @@ void main()
9797 while (temp != NULL )
9898 {
9999
100- unionclosure (temp -> st );
100+ uc (temp -> st );
101101 temp = temp -> link ;
102102 }
103103 }
104104 printf ("\n" );
105- print_e_closure (i );
105+ pec (i );
106106 printf ("%c\t" , alphabet [j ]);
107107 printf ("{" );
108- for (n = 1 ; n <= nostate ; n ++ )
108+ for (n = 1 ; n <= ns ; n ++ )
109109 {
110110 if (set [n ] != 0 )
111111 printf ("q%d," , n );
@@ -114,33 +114,33 @@ void main()
114114 }
115115 }
116116 printf ("\n Final states:" );
117- findfinalstate ();
117+ ffs ();
118118}
119119
120- void findclosure (int x , int sta )
120+ void fc (int x , int sta )
121121{
122122 struct node * temp ;
123123 int i ;
124- if (buffer [x ])
124+ if (b [x ])
125125 return ;
126126 e_closure [sta ][c ++ ] = x ;
127- buffer [x ] = 1 ;
128- if (alphabet [noalpha - 1 ] == 'e' && transition [x ][noalpha - 1 ] != NULL )
127+ b [x ] = 1 ;
128+ if (alphabet [na - 1 ] == 'e' && transition [x ][na - 1 ] != NULL )
129129 {
130- temp = transition [x ][noalpha - 1 ];
130+ temp = transition [x ][na - 1 ];
131131 while (temp != NULL )
132132 {
133- findclosure (temp -> st , sta );
133+ fc (temp -> st , sta );
134134 temp = temp -> link ;
135135 }
136136 }
137137}
138138
139- void insert_trantbl (int r , char c , int s )
139+ void it (int r , char c , int s )
140140{
141141 int j ;
142142 struct node * temp ;
143- j = findalpha (c );
143+ j = fa (c );
144144 if (j == 999 )
145145 {
146146 printf ("error\n" );
@@ -152,17 +152,17 @@ void insert_trantbl(int r, char c, int s)
152152 transition [r ][j ] = temp ;
153153}
154154
155- int findalpha (char c )
155+ int fa (char c )
156156{
157157 int i ;
158- for (i = 0 ; i < noalpha ; i ++ )
158+ for (i = 0 ; i < na ; i ++ )
159159 if (alphabet [i ] == c )
160160 return i ;
161161
162162 return (999 );
163163}
164164
165- void unionclosure (int i )
165+ void uc (int i )
166166{
167167 int j = 0 , k ;
168168 while (e_closure [i ][j ] != 0 )
@@ -172,26 +172,26 @@ void unionclosure(int i)
172172 j ++ ;
173173 }
174174}
175- void findfinalstate ()
175+ void ffs ()
176176{
177177 int i , j , k , t ;
178- for (i = 0 ; i < nofinal ; i ++ )
178+ for (i = 0 ; i < nf ; i ++ )
179179 {
180- for (j = 1 ; j <= nostate ; j ++ )
180+ for (j = 1 ; j <= ns ; j ++ )
181181 {
182182 for (k = 0 ; e_closure [j ][k ] != 0 ; k ++ )
183183 {
184- if (e_closure [j ][k ] == finalstate [i ])
184+ if (e_closure [j ][k ] == fs [i ])
185185 {
186186
187- print_e_closure (j );
187+ pec (j );
188188 }
189189 }
190190 }
191191 }
192192}
193193
194- void print_e_closure (int i )
194+ void pec (int i )
195195{
196196 int j ;
197197 printf ("{" );
0 commit comments