Question: Can someone help me fix my code. The instructions are: Complete the function NFA ( input _ string, nfa ) that runs an NFA. In
Can someone help me fix my code. The instructions are:
Complete the function NFAinputstring, nfa that runs an NFA.
In particuar, modify the code on the following lines:
line : initialize currentstates note the plural!
line : define x
line : define the NFA given in Figure ; use, as an example, the definition of dfa given in line
n is so the th symbol from the end should be it should reject
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 nfastates
# run through the input string
for symbol in inputstring:
x set
for state in currentstates:
i nfa.states.indexstate
j nfa.alphabet.indexsymbol
x setnfatransitionij
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 FAqrstuqqrssttuuu
# Run the DFA on the input stri
# 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
