How to handle functions call in RPN
<p>I'm having a lot of trouble converting infix notation to postfix.</p>

<p>For instance, I want to convert this</p>

<pre><code>test(a(b+c), d()) - 3
</code></pre>

<p>into this</p>

<pre><code>b c + a , d test 3 -
</code></pre>

<p>I tried this solution,</p>

<pre><code>def composition(s):
    i = 0
    rpnstack = []
    stack = []
    ret = []
    count = 0
    while i &lt; len(s) :
        if i + 1 &lt; len(s) and s[i + 1] == "(":
            stack.append([count, rpnstack, s[i]])
            i += 2
            count = 1
            rpnstack = []
        elif s[i] == "(":
            count += 1
            rpnstack.append(s[i])
            i += 1
        elif s[i] == ")":
            count -= 1
            if count == 0:
                for a in rpn(rpnstack):
                    ret.append(a)
                a = stack.pop()
                count = a[0]
                rpnstack = a[1]
                ret.append(a[2])
            else:
                rpnstack.append(s[i])
            i += 1
        else:
            rpnstack.append(s[i])
            i += 1
    for a in rpn(rpnstack):
        ret.append(a)
    return ret
</code></pre>

<p>where RPN is the standard algorithm for the reverse polish notation and is is the infix string splitted with this regex </p>

<pre><code>(\+|\-|\*|\/|\&gt;|\&lt;|\(|\)|\,)
</code></pre>

<p>But it only works sometimes.</p>

<p>This is the full implementation of the rpn function</p>

<pre><code>operator = -10
operand = -20
leftparentheses = -30
rightparentheses = -40
empty = -50

operands = ["+", "-", "*", "/", "&gt;", "&lt;", "=", ","]


def precedence(s):
    if s is '(':
        return 0
    elif s is '+' or '-':
        return 1
    elif s is '*' or '/' or '%':
        return 2
    else:
        return 99

def typeof(s):
    if s is '(':
        return leftparentheses
    elif s is ')':
        return rightparentheses
    elif s in operands:
        return operator
    elif s is ' ':
        return empty    
    else :
        return operand                          


def rpn(infix):
    postfix = []
    temp = []
    for i in infix :
        type = typeof(i)
        if type is leftparentheses :
            temp.append(i)
        elif type is rightparentheses :
            next = temp.pop()
            while next is not '(' or skip &gt; 0:
                postfix.append(next)
                next = temp.pop()
        elif type is operand:
            postfix.append(i)
        elif type is operator:
            p = precedence(i)
            while len(temp) is not 0 and p &lt;= precedence(temp[-1]) :
                postfix.append(temp.pop())
            temp.append(i)
        elif type is empty:
            continue

    while len(temp) &gt; 0 :
        postfix.append(temp.pop())

    return postfix
</code></pre>

<p>if i try to use the code against this infix expression:</p>

<pre><code>i &lt; test.func()
</code></pre>

<p>i get:</p>

<pre><code>[' test.func', 'i ', '&lt;']
</code></pre>

<p>and against this</p>

<pre><code>i &lt; 10
</code></pre>

<p>i get:</p>

<pre><code>['i ', ' 10', '&lt;']
</code></pre>

<p>How can I fix this?</p>