-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexp.rkt
22 lines (16 loc) · 801 Bytes
/
exp.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#lang typed/racket
(provide (all-defined-out))
(struct: Prog ([defs : (Listof FDef)] [body : Expr]) #:transparent)
(define-type FDef (Pair Symbol Func))
(struct: Func ([args : (Listof Symbol)] [body : Expr]) #:transparent)
(define-type Val (U Integer Boolean))
(define-predicate Val? Val)
(define-type Expr (U Const Var Apply Prim If))
(define-predicate Expr? Expr)
(struct: Const ([val : Val]) #:transparent)
(struct: Var ([var : Symbol]) #:transparent)
(struct: Apply ([op : Symbol] [args : (Listof Expr)]) #:transparent)
(struct: Prim ([op : Op] [args : (Listof Expr)]) #:transparent)
(struct: If ([test : Expr] [then : Expr] [else : Expr]) #:transparent)
(define-type Op (U '= '+ '- '*))
(define-predicate Op? Op)