1+ #include <stdio.h>
2+
3+ /**
4+ * \brief MAX_STATES maximum no of states
5+ */
6+ #define MAX_STATES 10
7+ #define TRAP_STATE (-999)
8+ #define NOT_DEFINED (-1)
9+ #define FINAL_STATE 999
10+ #define SYMBOLS 3
11+
12+ typedef struct nfa
13+ {
14+ int a [10 ];
15+ int b [10 ];
16+ int epsilon [10 ];
17+ }nfa ;
18+
19+ int main (void )
20+ {
21+ int i , j , k ;
22+
23+ int no_of_states , no_of_final_state ;
24+ const int no_of_relations = 0 ;
25+ int final_states [MAX_STATES ];
26+
27+ // First, we are taking all the states as trap, to start our process
28+ // It also helps to remove garbage values
29+
30+ for (i = 0 ; i < MAX_STATES ; i ++ )
31+ final_states [i ] = TRAP_STATE ;
32+
33+ // Taking all the user inputs
34+
35+ printf ("Enter no of states: " );
36+ scanf_s ("%d" , & no_of_states );
37+
38+ printf ("Enter no of final states: " );
39+ scanf_s ("%d" , & no_of_final_state );
40+
41+ printf ("Enter index(State no) of final states: " );
42+ for (i = 0 ; i < no_of_final_state ; i ++ )
43+ {
44+ int index ;
45+ scanf_s ("%d" , & index );
46+ final_states [index ] = FINAL_STATE ;
47+ }
48+
49+ // Assuming that the first dimension indicating the states
50+ // second dimension indicating the symbols or edges
51+ // third dimension indicates the max no of relations defined for that state
52+ int matrix [MAX_STATES ][SYMBOLS ][MAX_STATES ];
53+
54+ printf ("We are assuming that the symbols of this NFA are \'a\' and \'b\' and \'E\'\n" );
55+ printf ("Here \'E\' is for epsilon (lambda NFA)\n" );
56+
57+ // Again Garbage Collection and TRAP STATES
58+ for (i = 0 ; i < MAX_STATES ; i ++ )
59+ for (j = 0 ; j < SYMBOLS ; j ++ )
60+ for (k = 0 ; k < MAX_STATES ; k ++ )
61+ matrix [i ][j ][k ] = NOT_DEFINED ;
62+
63+ // taking an array of symbols to get different edges for different symbols
64+ // We are assuming that edges are all of integer types
65+ int array_of_symbols [SYMBOLS ];
66+
67+ // this part is not user input able right now as we are omitting user input in case of symbols
68+ // We are hard coding this part right now
69+ for (i = 0 ; i < SYMBOLS ; i ++ )
70+ {
71+ // Assume 2 for epsilon
72+ array_of_symbols [i ] = i ;
73+ }
74+
75+ // Now taking the user input for creating the table
76+ for (i = 0 ; i < no_of_states ; i ++ )
77+ {
78+
79+
80+ for (j = 0 ; j < SYMBOLS ; j ++ )
81+ {
82+ printf ("Enter no of relations from the state %d for the symbol %d (Enter -1 for no relations): " , i , array_of_symbols [j ]);
83+ scanf_s ("%d" , no_of_relations );
84+
85+ if (no_of_relations != -1 )
86+ {
87+ for (k = 0 ; k < no_of_relations ; k ++ )
88+ {
89+ printf ("Enter relation from the state %d for the symbol %d: " , i , array_of_symbols [j ]);
90+ scanf_s ("%d" , matrix [i ][j ][k ]);
91+ }
92+ }
93+ }
94+ }
95+ }
0 commit comments