|
|
@ -1,29 +1,28 @@
|
|
|
|
#lang br
|
|
|
|
#lang br
|
|
|
|
(provide (all-defined-out))
|
|
|
|
(provide b-expr b-sum b-product b-neg b-expt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (b-expr expr)
|
|
|
|
|
|
|
|
(if (integer? expr) (inexact->exact expr) expr))
|
|
|
|
|
|
|
|
|
|
|
|
;; b-sum : b-product (("+" | "-") b-product)*
|
|
|
|
|
|
|
|
(define-macro-cases b-sum
|
|
|
|
(define-macro-cases b-sum
|
|
|
|
[(_ PROD) #'PROD]
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
[(_ LEFT-PROD "+" RIGHT-PROD) #'(+ LEFT-PROD RIGHT-PROD)]
|
|
|
|
[(_ LEFT "+" RIGHT) #'(+ LEFT RIGHT)]
|
|
|
|
[(_ LEFT-PROD "-" RIGHT-PROD) #'(- LEFT-PROD RIGHT-PROD)])
|
|
|
|
[(_ LEFT "-" RIGHT) #'(- LEFT RIGHT)])
|
|
|
|
|
|
|
|
|
|
|
|
;; b-product : [b-product ("*"|"/"|"%"|"^")] b-value
|
|
|
|
|
|
|
|
(define-macro-cases b-product
|
|
|
|
(define-macro-cases b-product
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
[(_ LEFT "*" RIGHT) #'(* LEFT RIGHT)]
|
|
|
|
[(_ LEFT "*" RIGHT) #'(* LEFT RIGHT)]
|
|
|
|
[(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT 1.0)]
|
|
|
|
[(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT 1.0)]
|
|
|
|
[(_ LEFT "mod" RIGHT) #'(modulo LEFT RIGHT)])
|
|
|
|
[(_ LEFT "mod" RIGHT) #'(modulo LEFT RIGHT)])
|
|
|
|
|
|
|
|
|
|
|
|
;; b-expt : [b-expt "^"] b-value
|
|
|
|
(define-macro-cases b-neg
|
|
|
|
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
|
|
|
|
[(_ "-" VAL) #'(- VAL)])
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro-cases b-expt
|
|
|
|
(define-macro-cases b-expt
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
[(_ LEFT "^" RIGHT) #'(expt LEFT RIGHT)])
|
|
|
|
[(_ LEFT "^" RIGHT) #'(expt LEFT RIGHT)])
|
|
|
|
|
|
|
|
|
|
|
|
(define (b-expr expr)
|
|
|
|
|
|
|
|
(if (integer? expr) (inexact->exact expr) expr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (b-negative num) (- num))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (b-not expr) (if (zero? expr) 1 0))
|
|
|
|
(define (b-not expr) (if (zero? expr) 1 0))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (b-def ID VAR EXPR)
|
|
|
|
(define-macro (b-def ID VAR EXPR)
|
|
|
|