Changed normal precedence calculation.

This commit is contained in:
Dave Halter
2014-11-06 03:47:42 +01:00
parent fae798adfe
commit d58046f38f
2 changed files with 27 additions and 30 deletions
+1 -8
View File
@@ -203,14 +203,7 @@ class Evaluator(object):
types = list(precedence.factor_calculate(self, types, operator)) types = list(precedence.factor_calculate(self, types, operator))
return types return types
else: else:
if element.children[0] == 'not': return precedence.calculate_children(self, element.children)
left = []
operator, right = element.children
else:
left, operator, right = element.children
left = self.eval_element(left)
return precedence.calculate(self, left, operator,
self.eval_element(right))
def _eval_atom(self, atom): def _eval_atom(self, atom):
""" """
+19 -15
View File
@@ -218,27 +218,30 @@ def _literals_to_types(evaluator, result):
return list(set(result)) return list(set(result))
def process_children(evaluator, children): def calculate_children(evaluator, children):
#first = children[0] """
#if isinstance(first, Calculate a list of children with operators.
operator = precedence.operator """
lazy_right = lambda: process_precedence_element(evaluator, precedence.right) iterator = iter(children)
types = evaluator.eval_element(next(iterator))
for operator in iterator:
right = next(iterator)
if pr.is_node(operator, 'comp_op'): # not in / is not
operator = ' '.join(str(c.value) for c in operator.children)
# handle lazy evaluation of and/or here. # handle lazy evaluation of and/or here.
if operator in ('and', 'or'): if operator in ('and', 'or'):
left_bools = set([left.py__bool__() for left in left_objs]) left_bools = set([left.py__bool__() for left in types])
if left_bools == set([True]): if left_bools == set([True]):
if operator == 'and': if operator == 'and':
return lazy_right() types = evaluator.eval_element(right)
else:
return left_objs
elif left_bools == set([False]): elif left_bools == set([False]):
if operator == 'and': if operator != 'and':
return left_objs types = evaluator.eval_element(right)
else:
return lazy_right()
# Otherwise continue, because of uncertainty. # Otherwise continue, because of uncertainty.
return calculate(evaluator, left_objs, precedence.operator, types = calculate(evaluator, types, operator,
lazy_right()) evaluator.eval_element(right))
return types
def calculate(evaluator, left_result, operator, right_result): def calculate(evaluator, left_result, operator, right_result):
@@ -273,6 +276,7 @@ def factor_calculate(evaluator, types, operator):
if value is None: # Uncertainty. if value is None: # Uncertainty.
return return
yield keyword_from_value(not value) yield keyword_from_value(not value)
else:
yield typ yield typ