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):
""" """
+26 -22
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)
# handle lazy evaluation of and/or here. types = evaluator.eval_element(next(iterator))
if operator in ('and', 'or'): for operator in iterator:
left_bools = set([left.py__bool__() for left in left_objs]) right = next(iterator)
if left_bools == set([True]): if pr.is_node(operator, 'comp_op'): # not in / is not
if operator == 'and': operator = ' '.join(str(c.value) for c in operator.children)
return lazy_right()
else: # handle lazy evaluation of and/or here.
return left_objs if operator in ('and', 'or'):
elif left_bools == set([False]): left_bools = set([left.py__bool__() for left in types])
if operator == 'and': if left_bools == set([True]):
return left_objs if operator == 'and':
else: types = evaluator.eval_element(right)
return lazy_right() elif left_bools == set([False]):
# Otherwise continue, because of uncertainty. if operator != 'and':
return calculate(evaluator, left_objs, precedence.operator, types = evaluator.eval_element(right)
lazy_right()) # Otherwise continue, because of uncertainty.
types = calculate(evaluator, types, operator,
evaluator.eval_element(right))
return types
def calculate(evaluator, left_result, operator, right_result): def calculate(evaluator, left_result, operator, right_result):
@@ -273,7 +276,8 @@ 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)
yield typ else:
yield typ
def _is_number(obj): def _is_number(obj):