for arith in (arith1, arith2):
    print(arith.parseString('A+B+C+D+E')[0])
print(arith.parseString('A+B+C*D+E')[0])
print(arith.parseString('12AX+34BY+C*5DZ+E')[0])
Recursive expressions with pyparsing