Advertisement
prasun54

NFA

Aug 27th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | Source Code | 0 0
  1. final = {'C'}
  2. current = {'A'}
  3.  
  4. delta = {('A','a'):{'A', 'B'},
  5.          ('A','b'):{'A'},
  6.          ('B','b'):{'C'}
  7.          }
  8.  
  9. string = input("Enter input string: ")
  10. for char in string:
  11.     newcurrent = set()
  12.     for state in current:
  13.         newcurrent |= delta.get((state, char), set())
  14.     current = newcurrent
  15.  
  16. if any([state in final for state in current]):
  17.     print("string is accepted")
  18. else:
  19.     print("string is rejected")
Tags: python NFA toc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement