The task is to produce a working program to accept a set of instructions and to execute them on a stack and to output the result of the expression. The set of instrtuctions is to be held in an array that ideally should be loaded from a file. Validation of the set of input instructions is not required as we assume the set of intsructions have been produced by a translater.
note: Any postfix expression will consist of literal values and the four operators + - * and /.
Example:
For the infix expression: 2.4+6.37*4.9 the translater will generate:
load 2.4
load 6.37
load 4.9
apply *
apply +
This code will be evaluated on a stack computer as follows:
Instruction Stack
load 2.4 2.4
load 6.37 2.4 6.37
load 4.9 4.9
apply * 2.4 31.213
apply + 33.613
stop (This will cause 33.613 to be output)
Does anyone have any ideas for the coding?
Any help much appreciated