def nfa(): if request.method == 'GET': return render_template('nfa.html') nfa_recv = request.json nfa = NFA(nfa_recv['model']) accepted = nfa.checkInput(nfa_recv['input']) dfaOutput = {"output": accepted} return jsonify(dfaOutput)
def conversion(self, save=0): file = open(self.file_path, 'r') self.lines = file.readlines() file.close() self.nfa = NFA(self.lines) self.dfa = DFA() self.dfa.convert_from_nfa(self.nfa) if not save: self.dfa.print() else: try: with open(f"{self.file_path}_output.txt", 'w') as file: file.write(f'{str(len(self.dfa.q))}\n') file.write(f'{"".join(self.dfa.symbols)}\n') file.write(f'{str(self.dfa.num_final_states)} {" ".join(str(final_state) for final_state in self.dfa.final_states)}\n') file.write(f'{str(self.dfa.start_state)}\n') for transition in sorted(self.dfa.transition_functions): file.write(f"{' '.join(str(value) for value in transition)}\n") except Exception as e: print(e, "You need to select a file first, if you did, check the error output.")
import sys from finite_automata import NFA, DFA if sys.version_info >= (3, 0): filename = input('Enter the name of the NFA file: ') elif sys.version_info >= (2, 0): filename = raw_input('Enter the name of the NFA file: ') else: print("Please update python to version 2.0 or newer") quit() file = open(filename, 'r') lines = file.readlines() file.close() nfa = NFA() dfa = DFA() nfa.construct_nfa_from_file(lines) dfa.convert_from_nfa(nfa) dfa.print_dfa()
from finite_automata import NFA, DFA filename = input('Enter the name of the NFA file\nFor example "./tests/test2.txt".\nYou might need to format your input,\ndepending on the location of your file.\n\nFilename:') try: file = open(filename, 'r') lines = file.readlines() file.close() dfa = DFA() dfa.convert_from_nfa(NFA(lines)) dfa.print() except Exception as e: print(e)