def tree_factor(iterator):
    peeking = peek(iterator)
    #check negative
    if (peeking == '-'):
        next(iterator)
        temp = tree_factor(iterator)
        return Value(int('-' + temp.__str__()))
    #check open parathesis
    if (peeking == '('):
        next(iterator)
        temp = tree_assign(iterator)
        next(iterator)
        return temp
    else:
        temp = next(iterator)
        if (temp[0].isalpha() and peek(iterator) == '('):
            parms = []
            next(iterator)
            while (peek(iterator) not in operators):
                if (peek(iterator) != ','):
                    parms.append(tree_assign(iterator))
                else:
                    next(iterator)
            next(iterator)
            return Func(temp, parms)
        elif (temp[0].isalpha()):
            return Var(temp)
        else:
            return Value(temp)
Beispiel #2
0
def tree_factor(iter):
    """Handles parentheses"""

    next = str(next(iter))
    if next == '(':
        next(iter)
        ans = tree_assign(
            iter
        )  #recursively makes a new expr subtree for the contents of the parens
        next(iter)  #passes over )
        return ans

    elif next.isdigit():
        return Value(next(iter))

    elif peek(iter) == '(':
        args = []
        while peek(iter) != ')':
            next(iter)
            args.append(tree_assign(iter))
        next(iter)
        return Funct(nxt, args)

    elif next.isalpha():
        return Var(next(iter))
def postfix_factor(iterator):
    if peek(iterator) == "(":
        next(iterator)
        dub = postfix_assign(iterator)
        next(iterator)
        return dub
    else:
        if (peek(iterator).isdigit()):
            join = peek(iterator)
            next(iterator)
            return Value(join)
        elif (peek(iterator).isalpha()):
            join = peek(iterator)
            next(iterator)
            return Var(join)
Beispiel #4
0
def tree_factor(iter):
    """Handles parentheses"""

    if peek(iter) == '(':
        next(
            iter
        )  #passes over the ( The exprtree inherently includes the functionality of parens
        ans = tree_assign(
            iter
        )  #recursively makes a new expr subtree for the contents of the parens
        next(iter)  #passes over )

    elif str(peek(iter)).isdigit():
        return Value(next(iter))

    elif str(peek(iter)).isalpha():
        return Var(next(iter))
def tree_factor( iter ):
    item = next(iter)
    if item == '(':
        res = tree_assign( iter )
        next(iter)
        return res
    elif item.isdigit():
        return Value(item)
    elif peek(iter) == '(':
        args = []
        while peek(iter) != ')':
            next(iter)
            temp = tree_assign(iter)
            args.append(temp)
        next(iter)
        return Func(item, args)
    else:
        return Var(item)
def tree_factor(iterator):
    if peek(iterator).isalpha():
        name = next(iterator)
        if peek(iterator) == "(":
            next(iterator)
            args = []
            arg = tree_assign(iterator)
            args.append(arg)
            while peek(iterator) == ",":
                arg = tree_assign(iterator)
                args.append(arg)
            next(iterator)
            return Func(name, args)
        return Var(name)
    elif peek(iterator).isdigit():
        return Value(next(iterator))
    elif peek(iterator) == '(':
        next(iterator)
        ans = tree_assign(iterator)
        next(iterator)
        return ans
def tree_factor(iterator):
   if peek(iterator) == '(':
      next(iterator)
      a = tree_assign(iterator)
      next(iterator)
      return a
   else:
      if peek(iterator)[0].isdigit():
         return Value(next(iterator))
      else:
         b = next(iterator)
         if peek(iterator) == "(":
            next(iterator)
            c = []
            while peek(iterator) != ")":
               a = tree_assign(iterator)
               c.append(a)
               if peek(iterator) == ",":
                  next(iterator)
            next(iterator)
            return Functioncall(b, c)
         else:
            return Var(b)