You did not indicate which Smalltalk dialect you are using. In Squeak, you can use the findTokens: method:
'336 8 4 2 1 + - * /' findTokens: ' ' ==> an OrderedCollection('336' '8' '4' '2' '1' '+' '-' '*' '/')
Use isDigit to check if the token is a number:
'336' first isDigit ==> true '+' first isDigit ==> false
To convert from string to number, use asNumber :
'336' asNumber ==> 336
The entire RPN parser / evaluator can be easily implemented with less than 10 lines of code, but obviously this is your homework (hint: there is no need to implement a stack, there is already one).
source share