def tree_conditional(iterator): cond = tree_relational(iterator) if peek(iterator) == "?": next(iterator) true = tree_assign(iterator) next(iterator) false = tree_assign(iterator) cond = Cond(cond, true, false) return cond
def postfix_conditional(iterator): t = postfix_keyword(iterator) if (peek(iterator) == "?"): next(iterator) true = postfix_keyword(iterator) if (peek(iterator) == ":"): next(iterator) false = postfix_keyword(iterator) t = Cond(t, true, false) return t
def tree_cond( iter ): left = tree_rel( iter ) if peek(iter) == '?': next(iter) true_case = tree_cond( iter ) next(iter) # : expected false_case = tree_cond( iter ) return Cond( left, true_case, false_case ) else: return left
def tree_condition(iterator): a = tree_relation(iterator) if peek(iterator) == "?": next(iterator) b = tree_assign(iterator) next(iterator) c = tree_assign(iterator) return Cond(a, b, c) else: return a
def tree_conditional(iterator): temp = tree_relational(iterator) peeking = peek(iterator) if (peeking == '?'): next(iterator) case1 = tree_relational(iterator) next(iterator) case2 = tree_relational(iterator) temp = Cond(temp, case1, case2) return temp
def tree_cond(iter): """Handles conditional statements""" left = tree_relate(iter) #the test condition subtree while peek(iter) == '?': next(iter) #passes over the ? t = tree_cond(iter) #the true expression subtree next(iter) #passses over the : f = tree_cond(iter) #the false expression subtree left = Cond(left, t, f) return left