How might I split a string (with postfix) into one with parentheses? What I mean is, if the user inputs 3 (3 6 *) * I want the interpreter to be able to multiply 3 18 * and understand the parentheses in the text. Is this possible? Like a str.split() but with a start and end delimiter?
Am I not being realistic? I found the shlex module similar, but it only does quotes AFAIK.
I don’t think using
reis such a bad idea. You could just go through replacing the nested parenthesis one at a time with the result of their operation. Seems pretty straight forward to me:And use like so: