In Ocaml, the following NFA, and assuming you have function shift nfa qs s Type: ('q, 's) nfa_t -> 'q list -> 's option -> 'q list write the function e_closure nfa qs of type Type: ('q, 's) nfa_t -> 'q list -> 'q list This function takes as input an NFA nfa and a set of initial states qs. It outputs a set of states that the NFA might be in after making zero or more epsilon transitions from any state in qs. You can assume the initial states are valid. type ('q, 's) transition = 'q * 's option * 'q type ('q, 's) nfa_t = { sigma : 's list; qs : 'q list; q0 : 'q; fs : 'q list; delta : ('q, 's) transition list; } If function works, it should give the following let nfa_ex = { sigma = ['b']; qs = [1; 2; 3]; q0 = 1; fs = [3]; delta = [(1, Some 'b', 2); (2, None, 3)] } e_closure nfa_ex [1] = [1] e_closure nfa_ex [1] = [2;3] e_closure nfa_ex [3] = [3] e_closure nfa_ex [1;2] = [1;2;3]
In Ocaml, the following NFA, and assuming you have function
shift nfa qs s
Type: ('q, 's) nfa_t -> 'q list -> 's option -> 'q list
write the function e_closure nfa qs of type Type: ('q, 's) nfa_t -> 'q list -> 'q list
This function takes as input an NFA nfa and a set of initial states qs. It outputs a set of states that the NFA might be in after making zero or more epsilon transitions from any state in qs. You can assume the initial states are valid.
type ('q, 's) transition = 'q * 's option * 'q type ('q, 's)
nfa_t = { sigma : 's list; qs : 'q list; q0 : 'q; fs : 'q list; delta : ('q, 's) transition list; }
If function works, it should give the following
let nfa_ex = { sigma = ['b']; qs = [1; 2; 3]; q0 = 1; fs = [3]; delta = [(1, Some 'b', 2); (2, None, 3)] }
e_closure nfa_ex [1] = [1] e_closure nfa_ex [1] = [2;3] e_closure nfa_ex [3] = [3] e_closure nfa_ex [1;2] = [1;2;3]
Step by step
Solved in 2 steps