Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- : evaluate (s -- i) ( Parse and evaluate string as RPN command )
- { swap " " explode } array_make
- foreach
- swap pop
- dup "+" strcmp not if pop + else
- dup "-" strcmp not if pop - else
- dup "*" strcmp not if pop * else
- dup "/" strcmp not if pop / else
- atoi then
- repeat
- ;
- : main
- begin
- me @ "Type a term in reverse polish notation: (x=exit)" notify
- read
- dup "x" strcmp
- dup if
- swap evaluate
- me @ swap intostr notify
- else
- swap pop
- then
- while
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement