Last active
August 29, 2015 14:01
-
-
Save NobukazuHanada/875d2ed089d6b0c89d2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (expr x) | |
(define (calc op oprnd ans) | |
(if (null? op) | |
ans | |
(calc (cdr op) (cdr oprnd) ((car op) ans (car oprnd))))) | |
(define (expr-sub x op-stack oprnd-stack) | |
(cond [(number? x) | |
(lambda (y) (expr-sub y op-stack (cons x oprnd-stack)))] | |
[(member x '("+" "*" "-" "/")) | |
(lambda (y) (expr-sub y (cons (eval (string->symbol x)) op-stack) oprnd-stack))] | |
[else | |
(let ((r-op-stack (reverse op-stack)) | |
(r-oprnd-stack (reverse oprnd-stack))) | |
(calc (cdr r-op-stack) | |
(cddr r-oprnd-stack ) | |
((car r-op-stack) (car r-oprnd-stack) (cadr r-oprnd-stack))))])) | |
(expr-sub x '() '())) | |
((((((((expr 4) "+") 3) "*") 2) "-") 1) "=") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment