Commit 2a742b78 authored by Kateřina Sloupová's avatar Kateřina Sloupová
Browse files

grammar and regex conversion fix

parent fd809f8e
Pipeline #62459 passed with stage
in 1 minute and 3 seconds
......@@ -73,8 +73,9 @@ class WebChecker():
if self.task == "GRA":
return parser.reggrammar_to_str(automaton.nfa_to_reggrammar().eliminate_useless())
if self.task == "REG" and student_type != "REG":
return "Tohle není pěkný typ převodu. Nechcete si místo regulárního výrazu vybrat něco jiného?"
if self.task == "REG":
return self.student_string if student_type == "REG" else \
"Tohle není pěkný typ převodu. Nechcete si místo regulárního výrazu vybrat něco jiného?"
#return parser.regex_to_str(automaton.nfa_to_regex())
except ParsingError as ex:
......
......@@ -33,13 +33,13 @@ def nfa_transform(string: str, automaton_type: str) -> reg.NFA:
if automaton_type in {"EFA", "NFA"}:
automaton = parser.str_to_nfa(string)
elif automaton_type == "GRA":
automaton = parser.str_to_reggrammar(string).reggrammar_to_nfa()
automaton = parser.str_to_reggrammar(string).eliminate_useless().reggrammar_to_nfa()
elif automaton_type == "REG":
automaton = parser.str_to_regex(string).regex_to_efa().eliminate_epsilon()
elif automaton_type in {"DFA", "TOT", "MIN", "TOC", "MIC"}:
automaton = parser.str_to_dfa(string).dfa_to_nfa()
return automaton
return reg.NFA(automaton.states, automaton.characters, automaton.transition, automaton.init, automaton.final)
except ParsingError as ex:
raise ParsingError(ex.args)
......
......@@ -65,4 +65,6 @@ class NFA(NFA):
pass
class RegEx(RegEx):
pass
def regex_to_efa(self) -> NFA:
nfa = super().regex_to_efa() # TODO ask how to do this more efficiently
return NFA(nfa.states, nfa.characters, nfa.transition, nfa.init, nfa.final)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment