Adapt your calculator to read input line by line from a file instead of from the user. Work as usual: push any numbers, pop twice and apply an operator, pushing the result. Write the state of the stack at the end (once you've read everything from the file) into a separate file. Work in any type (Rational, double, etc) that you like.