danielperezunlpam

NFA

Nov 26th, 2020
643
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import xmltodict
  2. import pprint
  3.  
  4.  
  5. class NFA():
  6.     def __init__(self, file=None):
  7.         super(NFA, self).__init__()
  8.         self.af = None
  9.         self.q = None
  10.         self.f = []
  11.  
  12.  
  13.  
  14.         self.load_from_file(file)
  15.         print("FIN")
  16.  
  17.  
  18.     def load_from_file(self, filename):
  19.         with open(filename) as ifile:
  20.             self.af = xmltodict.parse(ifile.read())
  21.             for q in self.af["structure"]["automaton"]["state"]:
  22.                 print(q)
  23.                 if "initial" in q:
  24.                     self.q = q["@id"]
  25.             for t in self.af["structure"]["automaton"]["transition"]:
  26.                 print(t)
  27.  
  28.     def run(self, word):
  29.         return self.run_r(word, self.q)
  30.  
  31.     def run_r(self, word, q):
  32.         return True|False
  33.  
  34.  
  35. if __name__ == '__main__':
  36.     nfa = NFA("xml_folder/AFND_epsilon_even_0_or_1.jff")
RAW Paste Data