def proc_stack(input, vardict):
    '''process IDENTs, binary operators in input list using vardict namespace'''
    stack=[]
    for item in input:
        # anything left to process?
        if item[0]=='IDENT':
            # push object referred to by IDENT onto stack
            stack.append(vardict[item[1]])
        elif item[0]=='NUMBER':
            stack.append(float(item[1]))
        else:
            # we must have a binary operator
            # and assuming well formed input two operands on stack
            operand=item[0]
            y=stack.pop()
            x=stack.pop()
            # XXX the following hack should be fixed some time just
            # because it is really ugly!
            if operand=='__truediv__' and type(y)!=type(1.0) and \
                    type(x)==type(1.0) and x==1 :
                # special case of empty numerator and Q denom
                x=vardict['']
                # this is coordinated with hack in UNITS_LIST in dimensions.py
            stack.append(x.__getattribute__(operand)(y))
    return stack[0]
process IDENTs, binary operators in input list using vardict namespace
recipes/Python/577333_Numerical_type_units/recipe-577333.py