'Convert infix to postfix which make use of user defined functions

What would be a good algorithm to convert infix to postfix of an expression which uses user-defined functions: For example:

def get_random_integer(a, b, c):
   import random

   return random.choice([a,b,c])

# Expression to be parsed
expression_string = '1 + 2 - (2 * 4) + get_random_integer(2,1,3) + 7 + 9'
   

What's the best way to convert this to a postfix expression The user-defined function could have any name and number of parameters

I followed https://github.com/KaylenTPillay/SSBOMAS-Calculator for the normal expression conversion.

Any help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source