codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#! /usr/bin/scheme –script (define (next) (cond ((eof-object? (peek-char)) (exit)) ((char=? (peek-char) #\space) (read-char) (next)) ((char=? (peek-char) #\newline) (read-char) ‘nl) (else (read)))) (define (op token) (case token ((+) +) ((-) -) ((*) *) ((/) /))) (let rpn ((token (next)) (stack ‘())) (cond ((eq? ‘nl token) (display (car stack)) (newline) (rpn (next) (cdr stack))) ((number? token) (rpn (next) (cons token stack))) (else (rpn (next) (cons ((op token) (cadr stack) (car stack)) (cddr stack))))))
Private
[
?
]
Run code
Submit