OK, So I am working on a calculator that takes in LaTeX code and spits out step by step instructions on how to solve the problem. Right now I am working on the sigma series, but I am having some difficulty trying to get the value of a String in terms of integers.

For example a hypothetical input would be "\sum^{5}_{i=0}i"
I need to take it apart, the create a "for"-loop that runs while i<=5 and the solution is "0+1+2+3+4+5". However, the problem is taking the "^{5}" and making it into an integer value.

Same goes for the "_{i=0}" clause. And I guess the same goes for the summation term.

How would I do this?