From 427d769aa6d0df0c504c07adeef4bf6127cbc6f3 Mon Sep 17 00:00:00 2001 From: emile Date: Thu, 30 May 2019 20:36:52 +0200 Subject: [PATCH] =?UTF-8?q?dodanie=20kilku=20edge=20case=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- program.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/program.py b/program.py index 21423c7..44ea4e8 100644 --- a/program.py +++ b/program.py @@ -19,7 +19,7 @@ class SimpleInterpreter(AbstractInterpreter): logic_signs = ['=', '>', '&', '|', '!', '(', ')'] return char in logic_signs def isParentice(char): - return char in ('(', ')') + return char in ['(', ')'] def isVariable(char): return not isSign(char) def isNegation(char): @@ -31,13 +31,21 @@ class SimpleInterpreter(AbstractInterpreter): prev = formula.s[i-1] if i>0 else None #None, gdy jesteśmy na pierwszym znaku if (char=='(' and isVariable(prev) and prev is not None): #a(b|c) return False + if (prev is None): + if not (isVariable(char) or isParentice(char) or isNegation(char)): + return False if isSign(char): + if (not isNegation(char)): if isSign(prev) and not isNegation(prev): # tylko negacje mogą się powtarzać po innym znaku return False - else: - if isVariable(prev) and prev is not None: # obrona przed a!>b - return False + if isNegation(prev): + + if not (isNegation(char) or isParentice(char)): + print("xd") + return False + if isVariable(prev): #a! + return False else: #if current char is a variable if isVariable(prev) and prev is not None: #Obrona abc>d @@ -113,6 +121,7 @@ class ProperInterpreter(AbstractInterpreter): if len(formula)==0: # print("Empty subformula") return None + if (formula=='!'): raise Exception("Negacja źle postawiona") x=[0 for u in formula] current_depth=0 for i,char in enumerate(formula): @@ -131,7 +140,7 @@ class ProperInterpreter(AbstractInterpreter): if current_depth!=0: raise Exception("Nawiasy źle umieszczone w podformule: {0}".format(formula)) - #print(formula) + print(formula) min_depth = min(x) @@ -148,7 +157,7 @@ class ProperInterpreter(AbstractInterpreter): slice_point = i break if is_simple: - # print(formula, " is simple") + #print(formula, " is simple") if not self.check_simple_formula(formula): raise Exception("Błąd na poziomie formuły bez zagnieżdzeń: {0}".format(formula)) return False @@ -177,7 +186,7 @@ class Formula: def isValid(self, interpreter=None)->bool: i = self.__i if interpreter is None else interpreter return i.isValid(self) - +sim = SimpleInterpreter() if len(sys.argv) > 1 : i = ProperInterpreter() if '-g' in sys.argv: @@ -192,7 +201,9 @@ if len(sys.argv) > 1 : for l in u: print(Formula(l,i).isValid()) else: - print(Formula( sys.argv[1] if sys.argv[1] != '-g' else sys.argv[2],i).isValid()) + print( + Formula(sys.argv[1] if sys.argv[1] != '-g' else sys.argv[2],i).isValid() + ) else: print("help?")