Phase 2 - FSM execution algorithm done

This commit is contained in:
Hizenberg469
2025-01-21 23:24:33 +05:30
parent 971e5484e0
commit eb91c66a75
3 changed files with 574 additions and 69 deletions

View File

@@ -4,6 +4,9 @@
/***Constants***/
#define space " " // 4 ws
#define MAX_INP_BUFFER_LEN 128
#define MAX_TRANSITION_TABLE_SIZE 128
#define MAX_STATE_NAME_SIZE 32
@@ -11,6 +14,7 @@
#define MAX_TRANSITION_KEY_SIZE 64
#define MAX_ALP_BUFFER_SIZE 30
#define MAX_FINAL_STATE 128
#define MAX_NUM_OF_STATES 128
/***Data structures and custom datatypes***/
@@ -28,6 +32,13 @@ typedef enum{
}fsm_bool_t;
typedef enum{
FSM_NO_TRANSITION,
FSM_NO_ERROR
}fsm_error_t;
/*This data structure act similar
* to the behaviour of transition
@@ -73,12 +84,18 @@ struct fsm_{
/*Initial state of FSM to start with*/
state_t *initial_state;
/*Number of States*/
state_t *states[MAX_NUM_OF_STATES];
/*Number of states in FSM*/
unsigned int state_count;
/*Set of alphabet*/
char alphabet[MAX_ALP_BUFFER_SIZE];
/*Count of No. of alphabets*/
unsigned int alphabet_count;
/*Set of final/accept states*/
char final_states[MAX_FINAL_STATE];
@@ -101,7 +118,7 @@ struct fsm_{
/***Function Prototypes***/
fsm_t*
create_new_fsm(const char *fsm_name, const char *inp_alpha);
create_new_fsm(const char *fsm_name, const char *inp_alpha, unsigned int alpha_count);
state_t*
create_new_state(const char *state_name,
@@ -122,6 +139,16 @@ create_and_insert_new_tt_entry(tt_t *trans_table,
tt_entry_t*
get_next_empty_tt_entry(tt_t *trans_table);
fsm_error_t
execute_fsm(fsm_t *fsm,
char *input_buffer,
unsigned int size,
fsm_bool_t *fsm_result);
void
print_fsm(fsm_t *fsm);
/**static(hidden) functions***/
static inline fsm_bool_t
is_tt_entry_empty(tt_entry_t *tt_entry){