From 9c168fbd987ae509e23faf7a108c91b4963c390e Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 13 Jul 2019 22:17:10 -0600 Subject: [PATCH] fix negativity --- beautiful-racket-demo/precalc-demo/grammar.rkt | 3 ++- beautiful-racket-demo/precalc-demo/main.rkt | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/beautiful-racket-demo/precalc-demo/grammar.rkt b/beautiful-racket-demo/precalc-demo/grammar.rkt index 22861cc..03877ef 100644 --- a/beautiful-racket-demo/precalc-demo/grammar.rkt +++ b/beautiful-racket-demo/precalc-demo/grammar.rkt @@ -6,6 +6,7 @@ fun : /"fun" var /"(" argvars /")" /"=" expr @expr : add-or-sub add-or-sub : [add-or-sub ("+" | "-")] mult-or-div mult-or-div : [mult-or-div ("*" | "/")] value -@value : var | INT | app | /"(" expr /")" +@value : var | int | app | /"(" expr /")" +int : ["-"] INT app : var /"(" [expr (/"," expr)*] /")" @var : ID \ No newline at end of file diff --git a/beautiful-racket-demo/precalc-demo/main.rkt b/beautiful-racket-demo/precalc-demo/main.rkt index caeb866..70d43df 100644 --- a/beautiful-racket-demo/precalc-demo/main.rkt +++ b/beautiful-racket-demo/precalc-demo/main.rkt @@ -1,6 +1,6 @@ #lang br/quicklang (require brag/support "grammar.rkt") -(provide top fun app add-or-sub mult-or-div) +(provide top fun app add-or-sub mult-or-div int) (module+ reader (provide read-syntax)) @@ -34,6 +34,10 @@ [(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT)] [(_ OTHER) #'OTHER]) +(define-macro-cases int + [(_ VAL) #'VAL] + [(_ "-" VAL) #'(- VAL)]) + (define-macro app #'#%app) (define (read-syntax src ip)