(define reduce?
(lambda (expr-stack next-token)
(let ((stack-top (top-minus expr-stack 0)))
(cond ((number? stack-top)
(let ((stack-second (top-minus expr-stack 1)))
(cond ((equal? next-token '$)
(operator? stack-second))
((operator? next-token)
(and (operator? stack-second)
(not (lower-precedence?
stack-second
next-token))))
((equal? next-token 'rparen)
(operator? stack-second))
(else #f))))
((equal? stack-top 'rparen)
(or (equal? next-token '$)
(operator? next-token)
(equal? next-token 'rparen)))
(else #f)))))
|