Question: nfa.py class FA: def _ _ init _ _ ( self , alphabet, states, transition, accepting _ states ) : self.alphabet = alphabet self.states =
nfa.py
class FA:
def initself alphabet, states, transition, acceptingstates:
self.alphabet alphabet
self.states states
self.transition transition
self.acceptingstates acceptingstates
def DFAinputstring, dfa:
# set currentstate to initial state
currentstate dfa.states
# run through the input string
for symbol in inputstring:
i dfa.states.indexcurrentstate
j dfa.alphabet.indexsymbol
currentstate dfa.transitionij
return currentstate
def NFAinputstring, nfa:
# set currentstate to initial state
currentstates #
# run through the input string
for symbol in inputstring:
x set
for state in currentstates:
i nfa.states.indexstate
j nfa.alphabet.indexsymbol
x #
currentstates x
return currentstates
def main:
# Read in the inputstring
inputstring input
# Define a DFA
dfa FAqrrqqrq
# Define the NFA given in Figure for n
nfa #
# Run the DFA on the input string
# finalstate DFAinputstring, dfa
# if finalstate in dfaacceptingstates:
# printAccept
# else:
# printReject
# Run the NFA on the input string
finalstates NFAinputstring, nfa
if setfinalstates & setnfaacceptingstates:
printAccept
else:
printReject
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
