Answer:
see the explanation
Step-by-step explanation:
/* C Program to construct Deterministic Finite Automaton */
#include <stdio.h>
#include <DFA.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
struct node{
struct node *initialStateID0;
struct node *presentStateID1;
};
printf("Please enter the total number of states:");
scanf("%d",&count);
//To create the Deterministic Finite Automata
DFA* create_dfa DFA(){
q=(struct node *)malloc(sizeof(struct node)*count);
dfa->initialStateID = -1;
dfa->presentStateID = -1;
dfa->totalNumOfStates = 0;
return dfa;
}
//To make the next transition
void NextTransition(DFA* dfa, char c)
{
int tID;
for (tID = 0; tID < pPresentState->numOfTransitions; tID++){
if (pPresentState->transitions[tID].condition(c))
{
dfa->presentStateID = pPresentState->transitions[tID].toStateID;
return;
}
}
dfa->presentStateID = pPresentState->defaultToStateID;
}
//To Add the state to DFA by using number of states
void State_add (DFA* pDFA, DFAState* newState)
{
newState->ID = pDFA->numOfStates;
pDFA->states[pDFA->numOfStates] = newState;
pDFA->numOfStates++;
}
void transition_Add (DFA* dfa, int fromStateID, int(*condition)(char), int toStateID)
{
DFAState* state = dfa->states[fromStateID];
state->transitions[state->numOfTransitions].toStateID = toStateID;
state->numOfTransitions++;
}
void reset(DFA* dfa)
{
dfa->presentStateID = dfa->initialStateID;
}