So, you asked about the stack problem, which of course you need for evaluation. I would do something like this:
import re #1
stack = [] #2 FIX: NOT NECESSARY (since fourth line returns a list anyway)
inputstr = "A=B=C+26-(23*_2 )-D" #3
stack = re.findall(r'(?:[A-Z])|(?:[0-9]+)|(?:[/*+_=\(\)-])', inputstr) #4
while len(stack): #5
print stack.pop() #6
First three lines are some init stuff only. After that, I would make a stack with regex in the fourth line. (?:[A-Z])
matches variable, (?:[0-9]+)
matches number (which may have more than one digit) and (?:[/*+_=\(\)-])
matches all the operators. Braces are escaped, and -
is on the end, so you don't have to escape it.
Fifth and sixth line prints the stack.
I used (?: ...)
because I don't want to match either group. Hard to explain - just try to run it without ?:
and you will see the effect.