def tree_assign(iterator): left = tree_conditional(iterator) if peek(iterator) == "=": oper = next(iterator) right = tree_assign(iterator) left = Oper(left, oper, right) return left
def tree_product(iterator): a = tree_factor(iterator) while peek(iterator) == '*' or peek(iterator) == '/' or peek(iterator) == '%': operation = next(iterator) b = tree_factor(iterator) a = Oper(a, operation, b) return a
def tree_sum(iterator): a = tree_product(iterator) while peek(iterator) == '+' or peek(iterator) == '-': operation = next(iterator) b = tree_product(iterator) a = Oper(a, operation, b) return a
def tree_sum(iterator): left = tree_product(iterator) while (peek(iterator) == "+" or peek(iterator) == "-"): oper = next(iterator) right = tree_product(iterator) left = Oper(left, oper, right) return left
def postfix_assign(iterator): left_child = postfix_conditional(iterator) if peek(iterator) == "=": next(iterator) right_child = postfix_assign(iterator) left_child = Oper(left_child, "=", right_child) return left_child
def tree_assign(iterator): a = tree_condition(iterator) if peek(iterator) == '=': operation = next(iterator) b = tree_assign(iterator) return Oper(a, operation, b) else: return a
def tree_relation(iterator): a = tree_sum(iterator) if peek(iterator) == "<" or peek(iterator) == ">" or peek(iterator) == "<=" or peek(iterator) == ">=" or peek(iterator) == "==" or peek(iterator) == "!=": operation = next(iterator) b = tree_sum(iterator) return Oper(a, operation, b) else: return a
def postfix_sum(iterator): left_child = postfix_product(iterator) while (peek(iterator) == "+" or peek(iterator) == "-"): join = peek(iterator) next(iterator) right_child = postfix_product(iterator) left_child = Oper(left_child, join, right_child) return left_child
def tree_relational(iterator): temp = tree_sum(iterator) peeking = peek(iterator) if (peeking in relaOpers): next(iterator) temp = Oper(temp, peeking, tree_sum(iterator)) peeking = peek(iterator) return temp
def tree_assign( iter ): left = tree_cond( iter ) if peek(iter) == '=': next(iter) right = tree_assign( iter ) return Oper( left, '=', right ) else: return left
def tree_product(iterator): left = tree_factor(iterator) while (peek(iterator) == "*" or peek(iterator) == "/" or peek(iterator) == "%"): oper = next(iterator) right = tree_factor(iterator) left = Oper(left, oper, right) return left
def tree_assign(iterator): temp = tree_conditional(iterator) peeking = peek(iterator) if (peeking == '='): next(iterator) temp = Oper(temp, peeking, tree_assign(iterator)) peeking = peek(iterator) return temp
def tree_product( iter ): left = tree_factor( iter ) oper = peek(iter) while oper == '*' or oper == '/' or oper == '%': next(iter) right = tree_factor( iter ) left = Oper( left, oper, right ) oper = peek(iter) return left
def postfix_keyword(iterator): left_child = postfix_relation(iterator) while (peek(iterator) == "and" or peek(iterator) == "or" or peek(iterator) == "not"): join = peek(iterator) next(iterator) right_child = postfix_relation(iterator) left_child = Oper(left_child, join, right_child) return left_child
def postfix_product(iterator): left_child = postfix_factor(iterator) while (peek(iterator) == "*" or peek(iterator) == "/" or peek(iterator) == "%" or peek(iterator) == "//"): join = peek(iterator) next(iterator) right_child = postfix_factor(iterator) left_child = Oper(left_child, join, right_child) return left_child
def tree_relational(iterator): left = tree_sum(iterator) while (peek(iterator) == ">" or peek(iterator) == "<" or peek(iterator) == ">=" or peek(iterator) == "<=" or peek(iterator) == "==" or peek(iterator) == "!="): oper = next(iterator) right = tree_sum(iterator) left = Oper(left, oper, right) return left
def tree_sum( iter ): left = tree_product( iter ) oper = peek(iter) while oper == '+' or oper == '-': next(iter) right = tree_product( iter ) left = Oper( left, oper, right ) oper = peek(iter) return left
def tree_rel( iter ): left = tree_sum( iter ) oper = peek(iter) while oper in ['<','<=','>','>=','!=','==']: next(iter) right = tree_sum( iter ) left = Oper( left, oper, right ) oper = peek(iter) return left
def tree_sum(iter): """Handles addition""" left = tree_prod(iter) while peek(iter) == '+' or peek(iter) == '-': sign = next(iter) right = tree_prod(iter) left = Oper(left, sign, right) return left
def tree_prod(iter): """Handles multiplication and division""" left = tree_factor(iter) while peek(iter) in ['*', '/', '%']: sign = next(iter) right = tree_factor(iter) left = Oper(left, sign, right) return left
def tree_relate(iter): """Handles relational expressions""" left = tree_sum(iter) while peek(iter) in ["==", "!=", "<=", ">=", '>', '<']: sign = next(iter) right = tree_sum(iter) left = Oper(left, sign, right) return left
def tree_assign(iter): """Handles variable assignments""" left = tree_cond(iter) while peek(iter) == '=': sign = next(iter) right = tree_cond(iter) left = Oper(left, sign, right) return left
def tree_product(iterator): #call factor to evaluate order of operation temp = tree_factor(iterator) peeking = peek(iterator) #this while loop evaluates product and multiplication #yield data back up from factor then yield the sign like postfix while (peeking == '*' or peeking == '/' or peeking == '%' or peeking == '//'): next(iterator) temp = Oper(temp, peeking, tree_factor(iterator)) peeking = peek(iterator) return temp
def postfix_relation(iterator): left_child = postfix_sum(iterator) while (peek(iterator) == "+=" or peek(iterator) == "-=" or peek(iterator) == "*=" or peek(iterator) == "/=" or peek(iterator) == "==" or peek(iterator) == ">=" or peek(iterator) == "<=" or peek(iterator) == ">" or peek(iterator) == "<" or peek(iterator) == "!="): join = peek(iterator) next(iterator) right_child = postfix_sum(iterator) left_child = Oper(left_child, join, right_child) return left_child
def tree_sum(iterator): # evaluate the first term while checking for the next term for multiplication temp = tree_product(iterator) #store the operator #this while loop evaluates sum and subtraction. #yield data back up from product then yield the sign like postfix peeking = peek(iterator) while (peeking == '+' or peeking == '-'): next(iterator) temp = Oper(temp, peeking, tree_product(iterator)) peeking = peek(iterator) # skip the ')' and continue changing the expression #if(peeking == ')'): # next(iterator) return temp