|
|
|
@ -1,29 +1,28 @@
|
|
|
|
|
#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
|
|
|
|
|
[(_ PROD) #'PROD]
|
|
|
|
|
[(_ LEFT-PROD "+" RIGHT-PROD) #'(+ LEFT-PROD RIGHT-PROD)]
|
|
|
|
|
[(_ LEFT-PROD "-" RIGHT-PROD) #'(- LEFT-PROD RIGHT-PROD)])
|
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
|
[(_ LEFT "+" RIGHT) #'(+ LEFT RIGHT)]
|
|
|
|
|
[(_ LEFT "-" RIGHT) #'(- LEFT RIGHT)])
|
|
|
|
|
|
|
|
|
|
;; b-product : [b-product ("*"|"/"|"%"|"^")] b-value
|
|
|
|
|
(define-macro-cases b-product
|
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
|
[(_ LEFT "*" RIGHT) #'(* LEFT RIGHT)]
|
|
|
|
|
[(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT 1.0)]
|
|
|
|
|
[(_ 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
|
|
|
|
|
[(_ VAL) #'VAL]
|
|
|
|
|
[(_ 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-macro (b-def ID VAR EXPR)
|
|
|
|
|